use of antlr.CharScanner in project groovy by apache.
the class LexerFrame method scanScript.
private void scanScript(final StringReader reader) throws Exception {
scriptPane.read(reader, null);
reader.reset();
// create lexer
final Constructor constructor = lexerClass.getConstructor(Reader.class);
final CharScanner lexer = (CharScanner) constructor.newInstance(reader);
tokenPane.setEditable(true);
tokenPane.setText("");
int line = 1;
final ButtonGroup bg = new ButtonGroup();
Token token;
while (true) {
token = lexer.nextToken();
JToggleButton tokenButton = new JToggleButton((String) tokens.get(Integer.valueOf(token.getType())));
bg.add(tokenButton);
tokenButton.addActionListener(this);
tokenButton.setToolTipText(token.getText());
tokenButton.putClientProperty("token", token);
tokenButton.setMargin(new Insets(0, 1, 0, 1));
tokenButton.setFocusPainted(false);
if (token.getLine() > line) {
tokenPane.getDocument().insertString(tokenPane.getDocument().getLength(), "\n", null);
line = token.getLine();
}
insertComponent(tokenButton);
if (token.getType() == Token.EOF_TYPE) {
break;
}
}
tokenPane.setEditable(false);
tokenPane.setCaretPosition(0);
reader.close();
}
Aggregations