Example usage for org.antlr.v4.runtime BufferedTokenStream consume

List of usage examples for org.antlr.v4.runtime BufferedTokenStream consume

Introduction

In this page you can find the example usage for org.antlr.v4.runtime BufferedTokenStream consume.

Prototype

@Override
    public void consume() 

Source Link

Usage

From source file:com.cisco.yangide.core.parser.YangParserUtil.java

License:Open Source License

public static String formatYangSource(YangFormattingPreferences preferences, char[] content,
        int indentationLevel, String lineSeparator) {
    ANTLRInputStream input = new ANTLRInputStream(content, content.length);
    final YangLexer lexer = new YangLexer(input) {
        @Override/*from www .  j  a  v a2s.  c o m*/
        public void skip() {
            // disable skipping of comment tokens
        }
    };
    LexerErrorListener errorListener = new LexerErrorListener();
    lexer.addErrorListener(errorListener);
    final BufferedTokenStream tokens = new BufferedTokenStream(lexer);
    final ITokenFormatter formatter = new YangTokenFormatter(preferences, indentationLevel, lineSeparator);
    while (tokens.LT(1).getType() != IntStream.EOF) {
        formatter.process(tokens.LT(1));
        tokens.consume();
    }
    if (errorListener.isErrorDetected()) {
        // Source that contains parsing errors should never be formatted
        return String.valueOf(content);
    }
    return formatter.getFormattedContent();
}