@Override
public SortedMap<Integer, String> parseString(String fieldString) {
CharStream is = CharStreams.fromString(fieldString);
DrawGrammarLexer lex = new DrawGrammarLexer(is);
CommonTokenStream tokens = new CommonTokenStream(lex);
DrawGrammarParser parser = new DrawGrammarParser(tokens);
palette = Palette.makeDefaultPalette("DarkSpectrum");
final SortedMap<Integer, String> resultMap;
try {
resultMap = parser.root().map;
} catch (RecognitionException | NullPointerException | StringIndexOutOfBoundsException | RasterFormatException re) {
//Something wrong with the parsing do not update.
return null;
}
return resultMap;
}
java类org.antlr.v4.runtime.RecognitionException的实例源码
PainterLogic.java 文件源码
项目:bitbox
阅读 25
收藏 0
点赞 0
评论 0
DescriptiveErrorListener.java 文件源码
项目:Squid
阅读 17
收藏 0
点赞 0
评论 0
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol,
int line, int charPositionInLine,
String msg, RecognitionException e) {
if (!reportSyntaxErrors) {
return;
}
// String sourceName = recognizer.getInputStream().getSourceName();
// if (!sourceName.isEmpty()) {
// sourceName = String.format("%s:%d:%d: ", sourceName, line, charPositionInLine);
// }
System.err.println("CUSTOM: " + "line " + line + ":" + charPositionInLine + " " + msg);
syntaxErrors = msg;
}
Walker.java 文件源码
项目:elasticsearch_my
阅读 22
收藏 0
点赞 0
评论 0
private void setupPicky(PainlessParser parser) {
// Diagnostic listener invokes syntaxError on other listeners for ambiguity issues,
parser.addErrorListener(new DiagnosticErrorListener(true));
// a second listener to fail the test when the above happens.
parser.addErrorListener(new BaseErrorListener() {
@Override
public void syntaxError(final Recognizer<?,?> recognizer, final Object offendingSymbol, final int line,
final int charPositionInLine, final String msg, final RecognitionException e) {
throw new AssertionError("line: " + line + ", offset: " + charPositionInLine +
", symbol:" + offendingSymbol + " " + msg);
}
});
// Enable exact ambiguity detection (costly). we enable exact since its the default for
// DiagnosticErrorListener, life is too short to think about what 'inexact ambiguity' might mean.
parser.getInterpreter().setPredictionMode(PredictionMode.LL_EXACT_AMBIG_DETECTION);
}
ParserErrorStrategy.java 文件源码
项目:elasticsearch_my
阅读 23
收藏 0
点赞 0
评论 0
@Override
public void recover(final Parser recognizer, final RecognitionException re) {
final Token token = re.getOffendingToken();
String message;
if (token == null) {
message = "no parse token found.";
} else if (re instanceof InputMismatchException) {
message = "unexpected token [" + getTokenErrorDisplay(token) + "]" +
" was expecting one of [" + re.getExpectedTokens().toString(recognizer.getVocabulary()) + "].";
} else if (re instanceof NoViableAltException) {
if (token.getType() == PainlessParser.EOF) {
message = "unexpected end of script.";
} else {
message = "invalid sequence of tokens near [" + getTokenErrorDisplay(token) + "].";
}
} else {
message = "unexpected token near [" + getTokenErrorDisplay(token) + "].";
}
Location location = new Location(sourceName, token == null ? -1 : token.getStartIndex());
throw location.createError(new IllegalArgumentException(message, re));
}
SelectScriptErrorListener.java 文件源码
项目:SelectScriptC
阅读 19
收藏 0
点赞 0
评论 0
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol,
int line, int charPositionInLine,
String msg, RecognitionException e)
{
if (!REPORT_SYNTAX_ERRORS) {
return;
}
String sourceName = recognizer.getInputStream().getSourceName();
if (!sourceName.isEmpty()) {
sourceName = String.format("%d:%d: ", line, charPositionInLine);
}
error_msg.add(sourceName+"line "+line+":"+charPositionInLine+" "+msg);
}
FWPolicyErrorStrategy.java 文件源码
项目:oscm-app
阅读 25
收藏 0
点赞 0
评论 0
/**
* Make sure we don't attempt to recover inline; if the parser successfully
* recovers, it won't throw an exception.
*/
@Override
public Token recoverInline(Parser recognizer) throws RecognitionException {
InputMismatchException e = new InputMismatchException(recognizer);
String policies = recognizer.getInputStream().getText();
StringTokenizer tk = new StringTokenizer(policies, ";");
String policy = "";
int idx = 0;
while (tk.hasMoreElements()) {
policy = (String) tk.nextElement();
idx += policy.length();
if (idx >= e.getOffendingToken().getStartIndex()) {
break;
}
}
String message = Messages.get(Messages.DEFAULT_LOCALE,
"error_invalid_firewallconfig", new Object[] {
e.getOffendingToken().getText(), policy });
throw new RuntimeException(message);
}
FWPolicyParser.java 文件源码
项目:oscm-app
阅读 27
收藏 0
点赞 0
评论 0
public final Source_zoneContext source_zone(FWPolicy p)
throws RecognitionException {
Source_zoneContext _localctx = new Source_zoneContext(_ctx, getState(),
p);
enterRule(_localctx, 4, RULE_source_zone);
try {
enterOuterAlt(_localctx, 1);
{
{
setState(51);
((Source_zoneContext) _localctx).ZONE = match(ZONE);
}
_localctx.p.setSrcZone(((Source_zoneContext) _localctx).ZONE
.getText());
}
} catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
} finally {
exitRule();
}
return _localctx;
}
FWPolicyParser.java 文件源码
项目:oscm-app
阅读 24
收藏 0
点赞 0
评论 0
public final Dest_zoneContext dest_zone(FWPolicy p)
throws RecognitionException {
Dest_zoneContext _localctx = new Dest_zoneContext(_ctx, getState(), p);
enterRule(_localctx, 10, RULE_dest_zone);
try {
enterOuterAlt(_localctx, 1);
{
{
setState(60);
((Dest_zoneContext) _localctx).ZONE = match(ZONE);
}
_localctx.p.setDstZone(((Dest_zoneContext) _localctx).ZONE
.getText());
}
} catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
} finally {
exitRule();
}
return _localctx;
}
OboParser.java 文件源码
项目:ontolib
阅读 25
收藏 0
点赞 0
评论 0
private void parseInputStream(CharStream inputStream, OboParseResultListener listener) {
final OboLexer l = new OboLexer(inputStream);
final Antlr4OboParser p = new Antlr4OboParser(new CommonTokenStream(l));
p.addErrorListener(new BaseErrorListener() {
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
int charPositionInLine, String msg, RecognitionException e) {
throw new IllegalStateException("Failed to parse at line " + line + " due to " + msg, e);
}
});
if (debug) {
p.addErrorListener(new DiagnosticErrorListener());
}
p.addParseListener(new OboParserListener(listener));
p.oboFile();
}
FWPolicyErrorStrategy.java 文件源码
项目:oscm
阅读 23
收藏 0
点赞 0
评论 0
/**
* Make sure we don't attempt to recover inline; if the parser successfully
* recovers, it won't throw an exception.
*/
@Override
public Token recoverInline(Parser recognizer) throws RecognitionException {
InputMismatchException e = new InputMismatchException(recognizer);
String policies = recognizer.getInputStream().getText();
StringTokenizer tk = new StringTokenizer(policies, ";");
String policy = "";
int idx = 0;
while (tk.hasMoreElements()) {
policy = (String) tk.nextElement();
idx += policy.length();
if (idx >= e.getOffendingToken().getStartIndex()) {
break;
}
}
String message = Messages.get(Messages.DEFAULT_LOCALE,
"error_invalid_firewallconfig", new Object[] {
e.getOffendingToken().getText(), policy });
throw new RuntimeException(message);
}
FWPolicyParser.java 文件源码
项目:oscm
阅读 22
收藏 0
点赞 0
评论 0
public final Source_zoneContext source_zone(FWPolicy p)
throws RecognitionException {
Source_zoneContext _localctx = new Source_zoneContext(_ctx, getState(),
p);
enterRule(_localctx, 4, RULE_source_zone);
try {
enterOuterAlt(_localctx, 1);
{
{
setState(51);
((Source_zoneContext) _localctx).ZONE = match(ZONE);
}
_localctx.p.setSrcZone(((Source_zoneContext) _localctx).ZONE
.getText());
}
} catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
} finally {
exitRule();
}
return _localctx;
}
FWPolicyParser.java 文件源码
项目:oscm
阅读 23
收藏 0
点赞 0
评论 0
public final Dest_zoneContext dest_zone(FWPolicy p)
throws RecognitionException {
Dest_zoneContext _localctx = new Dest_zoneContext(_ctx, getState(), p);
enterRule(_localctx, 10, RULE_dest_zone);
try {
enterOuterAlt(_localctx, 1);
{
{
setState(60);
((Dest_zoneContext) _localctx).ZONE = match(ZONE);
}
_localctx.p.setDstZone(((Dest_zoneContext) _localctx).ZONE
.getText());
}
} catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
} finally {
exitRule();
}
return _localctx;
}
ExprParser.java 文件源码
项目:Expr3
阅读 20
收藏 0
点赞 0
评论 0
public final AssignmentContext assignment() throws RecognitionException {
AssignmentContext _localctx = new AssignmentContext(_ctx, getState());
enterRule(_localctx, 4, RULE_assignment);
try {
enterOuterAlt(_localctx, 1);
{
setState(62);
match(NAME);
setState(63);
match(EQ);
setState(64);
expr(0);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
OboParser.java 文件源码
项目:boqa
阅读 22
收藏 0
点赞 0
评论 0
private void parseInputStream(CharStream inputStream, OboParseResultListener listener) {
final OboLexer l = new OboLexer(inputStream);
final Antlr4OboParser p = new Antlr4OboParser(new CommonTokenStream(l));
p.addErrorListener(new BaseErrorListener() {
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
int charPositionInLine, String msg, RecognitionException e) {
throw new IllegalStateException("Failed to parse at line " + line + " due to " + msg, e);
}
});
if (debug) {
p.addErrorListener(new DiagnosticErrorListener());
}
p.addParseListener(new OboParserListener(listener));
p.oboFile();
}
Verilog2001Parser.java 文件源码
项目:netlist-graph
阅读 25
收藏 0
点赞 0
评论 0
public final T0z_path_delay_expressionContext t0z_path_delay_expression() throws RecognitionException {
T0z_path_delay_expressionContext _localctx = new T0z_path_delay_expressionContext(_ctx, getState());
enterRule(_localctx, 380, RULE_t0z_path_delay_expression);
try {
enterOuterAlt(_localctx, 1);
{
setState(3159);
path_delay_expression();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
DescriptiveErrorListener.java 文件源码
项目:Compilador
阅读 21
收藏 0
点赞 0
评论 0
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol,
int line, int charPositionInLine,
String msg, RecognitionException e)
{
List<String> stack = ((Parser)recognizer).getRuleInvocationStack(); Collections.reverse(stack);
System.err.println("rule stack: "+stack);
System.err.println("linea "+line+":"+charPositionInLine+" at "+
offendingSymbol+": "+msg);
String rule = "rule stack: "+stack;
String mensaje = "linea "+line+":"+charPositionInLine+" at "+
offendingSymbol+": "+msg + "\n\r";
agregarLog("Un error inesperado ha ocurrido " +"\n" + mensaje, line, charPositionInLine,true);
}
Verilog2001Parser.java 文件源码
项目:netlist-graph
阅读 46
收藏 0
点赞 0
评论 0
public final Trise_path_delay_expressionContext trise_path_delay_expression() throws RecognitionException {
Trise_path_delay_expressionContext _localctx = new Trise_path_delay_expressionContext(_ctx, getState());
enterRule(_localctx, 370, RULE_trise_path_delay_expression);
try {
enterOuterAlt(_localctx, 1);
{
setState(3149);
path_delay_expression();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
Verilog2001Parser.java 文件源码
项目:netlist-graph
阅读 61
收藏 0
点赞 0
评论 0
public final T01_path_delay_expressionContext t01_path_delay_expression() throws RecognitionException {
T01_path_delay_expressionContext _localctx = new T01_path_delay_expressionContext(_ctx, getState());
enterRule(_localctx, 376, RULE_t01_path_delay_expression);
try {
enterOuterAlt(_localctx, 1);
{
setState(3155);
path_delay_expression();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
JSONSchemaDefinitionTreeParserTest.java 文件源码
项目:libraries
阅读 25
收藏 0
点赞 0
评论 0
@Test
public void testObjectArray() throws RecognitionException, JssdParserException, IOException {
final Iterable<JObject> objects = getObjects("[{\"text\": <String> \"one\"},{\"value\": <int> 2}]");
final Iterator<JObject> iterator = objects.iterator();
assertObject(iterator.next(),//
new String[]{},//
new String[]{ "text" },//
new String[]{ "String" },//
new Object[]{ "one" });
assertObject(iterator.next(),//
new String[]{},//
new String[]{ "value" },//
new String[]{ "int" },
new Object[]{ 2L }//
);
}
Verilog2001Parser.java 文件源码
项目:netlist-graph
阅读 22
收藏 0
点赞 0
评论 0
public final Inout_port_identifierContext inout_port_identifier() throws RecognitionException {
Inout_port_identifierContext _localctx = new Inout_port_identifierContext(_ctx, getState());
enterRule(_localctx, 566, RULE_inout_port_identifier);
try {
enterOuterAlt(_localctx, 1);
{
setState(3886);
identifier();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
AbstractJSONTest.java 文件源码
项目:libraries
阅读 20
收藏 0
点赞 0
评论 0
public Iterable<JObject> assertObjects(
final String source,
final long numberOfObjects,
final String[] annotations,
final String[] names,
final Object[] types,
final Object[] values) throws RecognitionException, JssdParserException, IOException {
assertNotNull(names);
assertNotNull(values);
assertThat(names.length, equalTo(values.length));
final Iterable<JObject> objects = getObjects(source);
assertNotNull(objects);
final Iterator<JObject> iterator = objects.iterator();
assertThat(iterator.hasNext(), equalTo(true));
final JObject object = iterator.next();
assertObject(object, annotations, names, types, values);
final Counter counter = new Counter(1);
while (iterator.hasNext()) {
assertNotNull(iterator.next());
counter.next();
}
assertThat(counter.value(), equalTo(numberOfObjects));
return objects;
}
Verilog2001Parser.java 文件源码
项目:netlist-graph
阅读 28
收藏 0
点赞 0
评论 0
public final Event_declarationContext event_declaration() throws RecognitionException {
Event_declarationContext _localctx = new Event_declarationContext(_ctx, getState());
enterRule(_localctx, 64, RULE_event_declaration);
try {
enterOuterAlt(_localctx, 1);
{
setState(1145);
match(T__35);
setState(1146);
list_of_event_identifiers();
setState(1147);
match(T__1);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
Verilog2001Parser.java 文件源码
项目:netlist-graph
阅读 20
收藏 0
点赞 0
评论 0
public final Unary_module_path_operatorContext unary_module_path_operator() throws RecognitionException {
Unary_module_path_operatorContext _localctx = new Unary_module_path_operatorContext(_ctx, getState());
enterRule(_localctx, 512, RULE_unary_module_path_operator);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(3799);
_la = _input.LA(1);
if ( !(((((_la - 141)) & ~0x3f) == 0 && ((1L << (_la - 141)) & ((1L << (T__140 - 141)) | (1L << (T__141 - 141)) | (1L << (T__142 - 141)) | (1L << (T__143 - 141)) | (1L << (T__144 - 141)) | (1L << (T__145 - 141)) | (1L << (T__146 - 141)) | (1L << (T__147 - 141)) | (1L << (T__148 - 141)))) != 0)) ) {
_errHandler.recoverInline(this);
} else {
consume();
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
Verilog2001Parser.java 文件源码
项目:netlist-graph
阅读 24
收藏 0
点赞 0
评论 0
public final Tx0_path_delay_expressionContext tx0_path_delay_expression() throws RecognitionException {
Tx0_path_delay_expressionContext _localctx = new Tx0_path_delay_expressionContext(_ctx, getState());
enterRule(_localctx, 394, RULE_tx0_path_delay_expression);
try {
enterOuterAlt(_localctx, 1);
{
setState(3173);
path_delay_expression();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
Verilog2001Parser.java 文件源码
项目:netlist-graph
阅读 28
收藏 0
点赞 0
评论 0
public final Genvar_function_identifierContext genvar_function_identifier() throws RecognitionException {
Genvar_function_identifierContext _localctx = new Genvar_function_identifierContext(_ctx, getState());
enterRule(_localctx, 546, RULE_genvar_function_identifier);
try {
enterOuterAlt(_localctx, 1);
{
setState(3864);
identifier();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
Verilog2001Parser.java 文件源码
项目:netlist-graph
阅读 19
收藏 0
点赞 0
评论 0
public final Genvar_identifierContext genvar_identifier() throws RecognitionException {
Genvar_identifierContext _localctx = new Genvar_identifierContext(_ctx, getState());
enterRule(_localctx, 548, RULE_genvar_identifier);
try {
enterOuterAlt(_localctx, 1);
{
setState(3866);
identifier();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
Verilog2001Parser.java 文件源码
项目:netlist-graph
阅读 22
收藏 0
点赞 0
评论 0
public final Always_constructContext always_construct() throws RecognitionException {
Always_constructContext _localctx = new Always_constructContext(_ctx, getState());
enterRule(_localctx, 268, RULE_always_construct);
try {
enterOuterAlt(_localctx, 1);
{
setState(2350);
match(T__107);
setState(2351);
statement();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
Verilog2001Parser.java 文件源码
项目:netlist-graph
阅读 24
收藏 0
点赞 0
评论 0
public final Memory_identifierContext memory_identifier() throws RecognitionException {
Memory_identifierContext _localctx = new Memory_identifierContext(_ctx, getState());
enterRule(_localctx, 574, RULE_memory_identifier);
try {
enterOuterAlt(_localctx, 1);
{
setState(3894);
identifier();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
Verilog2001Parser.java 文件源码
项目:netlist-graph
阅读 24
收藏 0
点赞 0
评论 0
public final Function_blocking_assignmentContext function_blocking_assignment() throws RecognitionException {
Function_blocking_assignmentContext _localctx = new Function_blocking_assignmentContext(_ctx, getState());
enterRule(_localctx, 276, RULE_function_blocking_assignment);
try {
enterOuterAlt(_localctx, 1);
{
setState(2381);
variable_lvalue();
setState(2382);
match(T__50);
setState(2383);
expression();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
Verilog2001Parser.java 文件源码
项目:netlist-graph
阅读 27
收藏 0
点赞 0
评论 0
public final IdentifierContext identifier() throws RecognitionException {
IdentifierContext _localctx = new IdentifierContext(_ctx, getState());
enterRule(_localctx, 564, RULE_identifier);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(3884);
_la = _input.LA(1);
if ( !(_la==Escaped_identifier || _la==Simple_identifier) ) {
_errHandler.recoverInline(this);
} else {
consume();
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}