Search in sources :

Example 1 with WHILE

use of org.apache.groovy.parser.antlr4.GroovyLexer.WHILE 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 GroovyLangLexer lexer = new GroovyLangLexer(reader);
    tokenPane.setEditable(true);
    tokenPane.setText("");
    int line = 1;
    final ButtonGroup bg = new ButtonGroup();
    Token token;
    int tokenCnt = 0;
    while (true) {
        token = lexer.nextToken();
        JToggleButton tokenButton = new JToggleButton(tokens.get(token.getType()));
        tokenButton.setFont(MONOSPACED_FONT);
        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);
        tokenCnt++;
        if (eof().equals(token.getType())) {
            break;
        }
    }
    tokenStreamLabel.setText(" Token Stream(" + tokenCnt + "):");
    tokenPane.setEditable(false);
    tokenPane.setCaretPosition(0);
    reader.close();
}
Also used : Insets(java.awt.Insets) JToggleButton(javax.swing.JToggleButton) ButtonGroup(javax.swing.ButtonGroup) GroovyLangLexer(org.apache.groovy.parser.antlr4.GroovyLangLexer) Token(org.antlr.v4.runtime.Token)

Aggregations

Insets (java.awt.Insets)1 ButtonGroup (javax.swing.ButtonGroup)1 JToggleButton (javax.swing.JToggleButton)1 Token (org.antlr.v4.runtime.Token)1 GroovyLangLexer (org.apache.groovy.parser.antlr4.GroovyLangLexer)1