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

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

Introduction

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

Prototype

public String[] getModeNames() 

Source Link

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);// w  w w  .  j a v a 2s .  co 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();
}