List of usage examples for org.antlr.v4.runtime BufferedTokenStream LT
@Override public Token LT(int k)
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 ww w . ja v a2 s.c om 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(); }