Updated spec_parser such that it runs with ANTLR v4
Change-Id: Ib0711ebc125f4fadb5a526c3538d5c3a35f11234 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97320 Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
This commit is contained in:
@@ -4,13 +4,52 @@
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import org.antlr.runtime.*;
|
||||
import org.antlr.v4.runtime.*;
|
||||
import org.antlr.v4.runtime.dfa.*;
|
||||
import org.antlr.v4.runtime.atn.*;
|
||||
|
||||
class ParsingResult {
|
||||
public int numberOfFileArguments;
|
||||
public int numberOfFailures;
|
||||
}
|
||||
|
||||
class DartErrorListener implements ANTLRErrorListener {
|
||||
public void reportAmbiguity(
|
||||
Parser recognizer,
|
||||
DFA dfa,
|
||||
int startIndex,
|
||||
int stopIndex,
|
||||
boolean exact,
|
||||
BitSet ambigAlts,
|
||||
ATNConfigSet configs) {}
|
||||
|
||||
public void reportAttemptingFullContext(
|
||||
Parser recognizer,
|
||||
DFA dfa,
|
||||
int startIndex,
|
||||
int stopIndex,
|
||||
BitSet conflictingAlts,
|
||||
ATNConfigSet configs) {}
|
||||
|
||||
public void reportContextSensitivity(
|
||||
Parser recognizer,
|
||||
DFA dfa,
|
||||
int startIndex,
|
||||
int stopIndex,
|
||||
int prediction,
|
||||
ATNConfigSet configs) {}
|
||||
|
||||
public void syntaxError(
|
||||
Recognizer<?,?> recognizer,
|
||||
Object offendingSymbol,
|
||||
int line,
|
||||
int charPositionInLine,
|
||||
String msg,
|
||||
RecognitionException e) {
|
||||
if (!DartParser.errorHasOccurred) DartParser.prepareForErrors();
|
||||
}
|
||||
}
|
||||
|
||||
/// Class for `main` which will parse files given as command line arguments.
|
||||
public class SpecParser {
|
||||
private static void normalExit() {
|
||||
@@ -83,8 +122,11 @@ public class SpecParser {
|
||||
continue;
|
||||
}
|
||||
if (verbose) System.err.println("Parsing file: " + filePath);
|
||||
DartParser parser = new DartParser(new CommonTokenStream(
|
||||
new DartLexer(new ANTLRFileStream(filePath))));
|
||||
DartLexer lexer = new DartLexer(new ANTLRFileStream(filePath));
|
||||
DartParser parser = new DartParser(new CommonTokenStream(lexer));
|
||||
ANTLRErrorListener errorListener = new DartErrorListener();
|
||||
lexer.addErrorListener(errorListener);
|
||||
parser.addErrorListener(errorListener);
|
||||
if (!parser.parseLibrary(filePath)) result.numberOfFailures++;
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user