@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; }
@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; }
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); }
@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)); }
@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); }
/** * 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); }
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; }
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; }
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(); }
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; }
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; }
@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); }
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; }
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; }
@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 }// ); }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
public final Output_variable_typeContext output_variable_type() throws RecognitionException { Output_variable_typeContext _localctx = new Output_variable_typeContext(_ctx, getState()); enterRule(_localctx, 82, RULE_output_variable_type); int _la; try { enterOuterAlt(_localctx, 1); { setState(1297); _la = _input.LA(1); if ( !(_la==T__25 || _la==T__28) ) { _errHandler.recoverInline(this); } else { consume(); } } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { exitRule(); } return _localctx; }
public final T0x_path_delay_expressionContext t0x_path_delay_expression() throws RecognitionException { T0x_path_delay_expressionContext _localctx = new T0x_path_delay_expressionContext(_ctx, getState()); enterRule(_localctx, 388, RULE_t0x_path_delay_expression); try { enterOuterAlt(_localctx, 1); { setState(3167); path_delay_expression(); } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { exitRule(); } return _localctx; }
public final Module_path_multiple_concatenationContext module_path_multiple_concatenation() throws RecognitionException { Module_path_multiple_concatenationContext _localctx = new Module_path_multiple_concatenationContext(_ctx, getState()); enterRule(_localctx, 446, RULE_module_path_multiple_concatenation); try { enterOuterAlt(_localctx, 1); { setState(3313); match(T__18); setState(3314); constant_expression(); setState(3315); module_path_concatenation(); setState(3316); match(T__19); } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { exitRule(); } return _localctx; }
public final Pass_en_switchtypeContext pass_en_switchtype() throws RecognitionException { Pass_en_switchtypeContext _localctx = new Pass_en_switchtypeContext(_ctx, getState()); enterRule(_localctx, 218, RULE_pass_en_switchtype); int _la; try { enterOuterAlt(_localctx, 1); { setState(2137); _la = _input.LA(1); if ( !(((((_la - 91)) & ~0x3f) == 0 && ((1L << (_la - 91)) & ((1L << (T__90 - 91)) | (1L << (T__91 - 91)) | (1L << (T__92 - 91)) | (1L << (T__93 - 91)))) != 0)) ) { _errHandler.recoverInline(this); } else { consume(); } } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { exitRule(); } return _localctx; }
public final Real_declarationContext real_declaration() throws RecognitionException { Real_declarationContext _localctx = new Real_declarationContext(_ctx, getState()); enterRule(_localctx, 72, RULE_real_declaration); try { enterOuterAlt(_localctx, 1); { setState(1161); match(T__26); setState(1162); list_of_real_identifiers(); setState(1163); match(T__1); } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { exitRule(); } return _localctx; }
public final Udp_identifierContext udp_identifier() throws RecognitionException { Udp_identifierContext _localctx = new Udp_identifierContext(_ctx, getState()); enterRule(_localctx, 608, RULE_udp_identifier); try { enterOuterAlt(_localctx, 1); { setState(3933); identifier(); } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { exitRule(); } return _localctx; }
public final Cell_identifierContext cell_identifier() throws RecognitionException { Cell_identifierContext _localctx = new Cell_identifierContext(_ctx, getState()); enterRule(_localctx, 530, RULE_cell_identifier); try { enterOuterAlt(_localctx, 1); { setState(3838); identifier(); } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { exitRule(); } return _localctx; }
public final T1z_path_delay_expressionContext t1z_path_delay_expression() throws RecognitionException { T1z_path_delay_expressionContext _localctx = new T1z_path_delay_expressionContext(_ctx, getState()); enterRule(_localctx, 384, RULE_t1z_path_delay_expression); try { enterOuterAlt(_localctx, 1); { setState(3163); path_delay_expression(); } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { exitRule(); } return _localctx; }
public final Parameter_identifierContext parameter_identifier() throws RecognitionException { Parameter_identifierContext _localctx = new Parameter_identifierContext(_ctx, getState()); enterRule(_localctx, 584, RULE_parameter_identifier); try { enterOuterAlt(_localctx, 1); { setState(3904); identifier(); } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { exitRule(); } return _localctx; }
@Test public void testExpensiveQueryParsing() { final String yqlQuery = "select * from sources * where " + "([{\"ranked\": false}](foo contains \"a\" " + "and ([{\"ranked\": true}](bar contains \"b\" " + "or ([{\"ranked\": false}](foo contains \"c\" " + "and foo contains ([{\"ranked\": true}]\"d\")))))));"; ProgramParser parser = new ProgramParser(); OperatorNode<?> ast; long start = System.currentTimeMillis(); try { ast = parser.parse("query", yqlQuery); } catch (IOException | RecognitionException e) { throw new IllegalArgumentException(e); } long elapsed = System.currentTimeMillis() - start; Assert.assertNotNull(ast); System.out.println("Parsing required " + elapsed + " ms"); }