use of org.antlr.v4.runtime.dfa.DFA in project antlr4 by antlr.
the class BaseBrowserTest method getTokenTypes.
public List<String> getTokenTypes(LexerGrammar lg, ATN atn, CharStream input) {
LexerATNSimulator interp = new LexerATNSimulator(atn, new DFA[] { new DFA(atn.modeToStartState.get(Lexer.DEFAULT_MODE)) }, null);
List<String> tokenTypes = new ArrayList<String>();
int ttype;
boolean hitEOF = false;
do {
if (hitEOF) {
tokenTypes.add("EOF");
break;
}
int t = input.LA(1);
ttype = interp.match(input, Lexer.DEFAULT_MODE);
if (ttype == Token.EOF) {
tokenTypes.add("EOF");
} else {
tokenTypes.add(lg.typeToTokenList.get(ttype));
}
if (t == IntStream.EOF) {
hitEOF = true;
}
} while (ttype != Token.EOF);
return tokenTypes;
}
use of org.antlr.v4.runtime.dfa.DFA in project antlr4 by antlr.
the class BaseNodeTest method getTokenTypes.
public List<String> getTokenTypes(LexerGrammar lg, ATN atn, CharStream input) {
LexerATNSimulator interp = new LexerATNSimulator(atn, new DFA[] { new DFA(atn.modeToStartState.get(Lexer.DEFAULT_MODE)) }, null);
List<String> tokenTypes = new ArrayList<String>();
int ttype;
boolean hitEOF = false;
do {
if (hitEOF) {
tokenTypes.add("EOF");
break;
}
int t = input.LA(1);
ttype = interp.match(input, Lexer.DEFAULT_MODE);
if (ttype == Token.EOF) {
tokenTypes.add("EOF");
} else {
tokenTypes.add(lg.typeToTokenList.get(ttype));
}
if (t == IntStream.EOF) {
hitEOF = true;
}
} while (ttype != Token.EOF);
return tokenTypes;
}
use of org.antlr.v4.runtime.dfa.DFA in project robozonky by RoboZonky.
the class SideEffectFreeParser method modifyInterpreter.
private static void modifyInterpreter(final NaturalLanguageStrategyParser p) {
final int originalSize = p.getInterpreter().decisionToDFA.length;
// give our own array so the static one isn't used
final DFA[] emptyDFA = new DFA[originalSize];
final ParserATNSimulator newInterpreter = new ParserATNSimulator(p, p.getATN(), emptyDFA, new PredictionContextCache());
// initialize our array so that the parser functions properly
newInterpreter.clearDFA();
// replace the interpreter to bypass all static caches
p.setInterpreter(newInterpreter);
}
use of org.antlr.v4.runtime.dfa.DFA in project robozonky by RoboZonky.
the class SideEffectFreeParser method modifyInterpreter.
private static void modifyInterpreter(final NaturalLanguageStrategyLexer l) {
final int originalSize = l.getInterpreter().decisionToDFA.length;
// give our own array so the static one isn't used
final DFA[] emptyDFA = new DFA[originalSize];
final LexerATNSimulator newInterpreter = new LexerATNSimulator(l, l.getATN(), emptyDFA, new PredictionContextCache());
// initialize our array so that the lexer functions properly
newInterpreter.clearDFA();
// replace the interpreter to bypass all static caches
l.setInterpreter(newInterpreter);
}
use of org.antlr.v4.runtime.dfa.DFA in project kripton by xcesco.
the class ContentUriChecker method prepareUri.
private Pair<ParserRuleContext, CommonTokenStream> prepareUri(final String input) {
UriLexer lexer = new UriLexer(CharStreams.fromString(input));
CommonTokenStream tokens = new CommonTokenStream(lexer);
UriParser parser = new UriParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(new ContentUriBaseErrorListener() {
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
AssertKripton.assertTrue(false, "unespected char at pos %s of URI '%s'", charPositionInLine, input);
}
@Override
public void reportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, boolean exact, BitSet ambigAlts, ATNConfigSet configs) {
AssertKripton.assertTrue(false, "ambiguity syntax at pos %s of URI '%s'", startIndex, input);
}
@Override
public void reportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex, int stopIndex, BitSet conflictingAlts, ATNConfigSet configs) {
AssertKripton.assertTrue(false, "error at pos %s of URI '%s'", startIndex, input);
}
@Override
public void reportContextSensitivity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, int prediction, ATNConfigSet configs) {
AssertKripton.assertTrue(false, "context eror at pos %s of URI '%s'", startIndex, input);
}
});
ParserRuleContext context = parser.uri();
return new Pair<>(context, tokens);
}
Aggregations