Example usage for org.antlr.v4.runtime Lexer nextToken

List of usage examples for org.antlr.v4.runtime Lexer nextToken

Introduction

In this page you can find the example usage for org.antlr.v4.runtime Lexer nextToken.

Prototype

@Override
public Token nextToken() 

Source Link

Document

Return a token from this source; i.e., match a token on the char stream.

Usage

From source file:nl.knaw.AntlrUtils.java

License:Apache License

public static String makeTokenTable(Lexer lexer) {
    AsciiTable table = new AsciiTable().setTextAlignment(TextAlignment.LEFT);
    CWC_LongestLine cwc = new CWC_LongestLine();
    table.getRenderer().setCWC(cwc);/*from www .j  a v  a2s  . c o m*/
    table.addRule();
    table.addRow("Pos", "Text", "Rule", "Next mode", "Token");
    table.addRule();

    Token token;
    do {
        token = lexer.nextToken();
        //      LOG.info(token.toString());
        if (token.getType() != Token.EOF) {
            String pos = token.getLine() + ":" + token.getCharPositionInLine();
            String text = "'" + token.getText() + "'";
            String rule = lexer.getRuleNames()[token.getType() - 1];
            String mode = lexer.getModeNames()[lexer._mode];
            table.addRow(pos, text, rule, mode, token);
        }
    } while (token.getType() != Token.EOF);
    table.addRule();
    table.getContext().setGrid(A7_Grids.minusBarPlusEquals());
    return table.render();
}