use of org.antlr.v4.runtime.misc.NotNull in project beetl2.0 by javamonkey.
the class BeetlAntlrErrorStrategy method reportUnwantedToken.
protected void reportUnwantedToken(@NotNull Parser recognizer) {
if (inErrorRecoveryMode(recognizer)) {
return;
}
beginErrorCondition(recognizer);
Token t = recognizer.getCurrentToken();
String tokenName = getTokenErrorDisplay(t);
IntervalSet expecting = getExpectedTokens(recognizer);
String msg = "多余输入 " + tokenName + " 期望 " + expecting.toString(recognizer.getTokenNames());
BeetlException exception = new BeetlParserException(BeetlException.PARSER_MISS_ERROR, msg);
// exception.token = this.getGrammarToken(t);
exception.pushToken(this.getGrammarToken(t));
throw exception;
}
use of org.antlr.v4.runtime.misc.NotNull in project beetl2.0 by javamonkey.
the class BeetlAntlrErrorStrategy method reportInputMismatch.
protected void reportInputMismatch(@NotNull Parser recognizer, @NotNull InputMismatchException e) {
Token t1 = recognizer.getInputStream().LT(-1);
String msg = "缺少输入在 " + getTokenErrorDisplay(t1) + " 后面, 期望 " + e.getExpectedTokens().toString(recognizer.getTokenNames());
BeetlException exception = new BeetlParserException(BeetlException.PARSER_MISS_ERROR, msg, e);
// exception.token = this.getGrammarToken(e.getOffendingToken());
exception.pushToken(this.getGrammarToken(t1));
throw exception;
}
use of org.antlr.v4.runtime.misc.NotNull in project beetl2.0 by javamonkey.
the class BeetlAntlrErrorStrategy method reportMissingToken.
protected void reportMissingToken(@NotNull Parser recognizer) {
if (inErrorRecoveryMode(recognizer)) {
return;
}
beginErrorCondition(recognizer);
// Token t = recognizer.getCurrentToken();
Token t = recognizer.getTokenStream().LT(-1);
IntervalSet expecting = getExpectedTokens(recognizer);
String expect = expecting.toString(recognizer.getTokenNames());
if (expects.containsKey(expect)) {
expect = expects.get(expect);
}
if (expect.equals("'>>'")) {
expect = "'模板的占位结束符号'";
}
String tokenStr = getTokenErrorDisplay(t);
String msg = "缺少输入 " + expect + " 在 " + tokenStr + " 后面";
BeetlException exception = new BeetlParserException(BeetlException.PARSER_MISS_ERROR, msg);
exception.pushToken(this.getGrammarToken(t));
throw exception;
}
use of org.antlr.v4.runtime.misc.NotNull in project antlr4 by tunnelvisionlabs.
the class TreeViewer method showInDialog.
@NotNull
protected static JDialog showInDialog(final TreeViewer viewer) {
final JDialog dialog = new JDialog();
dialog.setTitle("Parse Tree Inspector");
final Preferences prefs = Preferences.userNodeForPackage(TreeViewer.class);
// Make new content panes
final Container mainPane = new JPanel(new BorderLayout(5, 5));
final Container contentPane = new JPanel(new BorderLayout(0, 0));
contentPane.setBackground(Color.white);
// Wrap viewer in scroll pane
JScrollPane scrollPane = new JScrollPane(viewer);
// Make the scrollpane (containing the viewer) the center component
contentPane.add(scrollPane, BorderLayout.CENTER);
JPanel wrapper = new JPanel(new FlowLayout());
// Add button to bottom
JPanel bottomPanel = new JPanel(new BorderLayout(0, 0));
contentPane.add(bottomPanel, BorderLayout.SOUTH);
JButton ok = new JButton("OK");
ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
}
});
wrapper.add(ok);
// Add an export-to-png button right of the "OK" button
JButton png = new JButton("Export as PNG");
png.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
generatePNGFile(viewer, dialog);
}
});
wrapper.add(png);
// Add an export-to-png button right of the "OK" button
JButton svg = new JButton("Export as SVG");
svg.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
generateSVGFile(viewer, dialog);
}
});
wrapper.add(svg);
bottomPanel.add(wrapper, BorderLayout.SOUTH);
// Add scale slider
double lastKnownViewerScale = prefs.getDouble(DIALOG_VIEWER_SCALE_PREFS_KEY, viewer.getScale());
viewer.setScale(lastKnownViewerScale);
int sliderValue = (int) ((lastKnownViewerScale - 1.0) * 1000);
final JSlider scaleSlider = new JSlider(JSlider.HORIZONTAL, -999, 1000, sliderValue);
scaleSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
int v = scaleSlider.getValue();
viewer.setScale(v / 1000.0 + 1.0);
}
});
bottomPanel.add(scaleSlider, BorderLayout.CENTER);
// Add a JTree representing the parser tree of the input.
JPanel treePanel = new JPanel(new BorderLayout(5, 5));
// An "empty" icon that will be used for the JTree's nodes.
Icon empty = new EmptyIcon();
UIManager.put("Tree.closedIcon", empty);
UIManager.put("Tree.openIcon", empty);
UIManager.put("Tree.leafIcon", empty);
Tree parseTreeRoot = viewer.getTree().getRoot();
TreeNodeWrapper nodeRoot = new TreeNodeWrapper(parseTreeRoot, viewer);
fillTree(nodeRoot, parseTreeRoot, viewer);
final JTree tree = new JTree(nodeRoot);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
JTree selectedTree = (JTree) e.getSource();
TreePath path = selectedTree.getSelectionPath();
if (path != null) {
TreeNodeWrapper treeNode = (TreeNodeWrapper) path.getLastPathComponent();
// Set the clicked AST.
viewer.setTree((Tree) treeNode.getUserObject());
}
}
});
treePanel.add(new JScrollPane(tree));
// Create the pane for both the JTree and the AST
final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treePanel, contentPane);
mainPane.add(splitPane, BorderLayout.CENTER);
dialog.setContentPane(mainPane);
// make viz
WindowListener exitListener = new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
prefs.putInt(DIALOG_WIDTH_PREFS_KEY, (int) dialog.getSize().getWidth());
prefs.putInt(DIALOG_HEIGHT_PREFS_KEY, (int) dialog.getSize().getHeight());
prefs.putDouble(DIALOG_X_PREFS_KEY, dialog.getLocationOnScreen().getX());
prefs.putDouble(DIALOG_Y_PREFS_KEY, dialog.getLocationOnScreen().getY());
prefs.putInt(DIALOG_DIVIDER_LOC_PREFS_KEY, splitPane.getDividerLocation());
prefs.putDouble(DIALOG_VIEWER_SCALE_PREFS_KEY, viewer.getScale());
dialog.setVisible(false);
dialog.dispose();
}
};
dialog.addWindowListener(exitListener);
dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
int width = prefs.getInt(DIALOG_WIDTH_PREFS_KEY, 600);
int height = prefs.getInt(DIALOG_HEIGHT_PREFS_KEY, 500);
dialog.setPreferredSize(new Dimension(width, height));
dialog.pack();
// After pack(): set the divider at 1/3 (200/600) of the frame.
int dividerLocation = prefs.getInt(DIALOG_DIVIDER_LOC_PREFS_KEY, 200);
splitPane.setDividerLocation(dividerLocation);
if (prefs.getDouble(DIALOG_X_PREFS_KEY, -1) != -1) {
dialog.setLocation((int) prefs.getDouble(DIALOG_X_PREFS_KEY, 100), (int) prefs.getDouble(DIALOG_Y_PREFS_KEY, 100));
} else {
dialog.setLocationRelativeTo(null);
}
dialog.setVisible(true);
return dialog;
}
use of org.antlr.v4.runtime.misc.NotNull in project antlr4 by tunnelvisionlabs.
the class ATNVisitor method visit_.
public void visit_(@NotNull ATNState s, @NotNull Set<Integer> visited) {
if (!visited.add(s.stateNumber))
return;
visited.add(s.stateNumber);
visitState(s);
int n = s.getNumberOfTransitions();
for (int i = 0; i < n; i++) {
Transition t = s.transition(i);
visit_(t.target, visited);
}
}
Aggregations