org.antlr.v4.runtime.RecognitionException Java Examples

The following examples show how to use org.antlr.v4.runtime.RecognitionException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Tool.java    From bookish with MIT License 6 votes vote down vote up
public String translateString(Translator trans, String markdown, String startRule) throws Exception {
	CharStream input = CharStreams.fromString(markdown);
	BookishLexer lexer = new BookishLexer(input);
	CommonTokenStream tokens = new CommonTokenStream(lexer);
	BookishParser parser = new BookishParser(tokens,null, 0);
	parser.removeErrorListeners();
	parser.addErrorListener(new ConsoleErrorListener() {
		@Override
		public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
			msg = "Parsing author string: "+msg;
			super.syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e);
		}
	});
	Method startMethod = BookishParser.class.getMethod(startRule, (Class[])null);
	ParseTree doctree = (ParseTree)startMethod.invoke(parser, (Object[])null);

	OutputModelObject omo = trans.visit(doctree); // get single chapter

	ModelConverter converter = new ModelConverter(trans.templates);
	ST outputST = converter.walk(omo);
	return outputST.render();
}
 
Example #2
Source File: Utils.java    From Concurnas with MIT License 6 votes vote down vote up
public static FuncDef parseFuncDef(String text, String name, int startingLine) {
	//JPT: transition more code to use this style? - this is quite cool, massive time saver i think
	try{
		LexParseErrorCapturer errors = new LexParseErrorCapturer(name);
		ConcurnasParser op = miniParse(text, name, startingLine,  0, errors);
		FuncDef ret = (FuncDef)new ASTCreator(name, errors).visit(op.funcdef()); 
		//OwlParser.lineOffset.set(0);
		if(!errors.errors.isEmpty()){
			throw new RuntimeException("Internal compiler error: " + errors.errors);
		}
		return ret;
	}
	catch(RecognitionException re){
		throw new RuntimeException(re);
	}
}
 
Example #3
Source File: FWPolicyParser.java    From development with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: LogicalProgramTransformsTest.java    From yql-plus with Apache License 2.0 6 votes vote down vote up
@Test
public void requireSubqueryReplacement() throws IOException, RecognitionException {
    ProgramParser parser = new ProgramParser();
    OperatorNode<StatementOperator> program = parser.parse("program.yql",
            "SELECT * " +
                    "  FROM source1 WHERE id IN (SELECT id2 FROM source2);"
    );
    LogicalProgramTransforms transforms = new LogicalProgramTransforms();
    OperatorNode<StatementOperator> operator = transforms.apply(program, new ViewRegistry() {
        @Override
        public OperatorNode<SequenceOperator> getView(List<String> name) {
            return null;
        }
    });
    Assert.assertEquals(operator.toString(), "(PROGRAM L0:0 [(EXECUTE (EXTRACT {rowType=[source2]} (SCAN L53:1 {alias=source2, rowType=[source2]} [source2], []), (READ_FIELD L44:1 {rowType=[source2]} source2, id2)), subquery$0), (EXECUTE L0:1 (FILTER {rowType=[source1]} (SCAN L16:1 {alias=source1, rowType=[source1]} [source1], []), (IN (READ_FIELD L30:1 {rowType=[source1]} source1, id), (VARREF subquery$0))), result1), (OUTPUT L0:1 result1)])");
}
 
Example #5
Source File: EditorConfigParser.java    From editorconfig-netbeans with MIT License 6 votes vote down vote up
public final SectionHeaderContext sectionHeader() throws RecognitionException {
  SectionHeaderContext _localctx = new SectionHeaderContext(_ctx, getState());
  enterRule(_localctx, 4, RULE_sectionHeader);
  try {
    enterOuterAlt(_localctx, 1);
    {
      setState(34);
      match(SECTION_LDELIMITER);
      setState(35);
      match(SECTION_NAME);
      setState(36);
      match(SECTION_RDELIMITER);
    }
  } catch (RecognitionException re) {
    _localctx.exception = re;
    _errHandler.reportError(this, re);
    _errHandler.recover(this, re);
  } finally {
    exitRule();
  }
  return _localctx;
}
 
Example #6
Source File: CQLErrorListener.java    From PoseidonX with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine,
    String msg, RecognitionException e)
{
    if (parserException != null)
    {
        return;
    }
    
    String errorSymbol = getOffendingSymbol(recognizer, offendingSymbol, charPositionInLine);
    parserException =
        new ParseException(
            ErrorCode.SEMANTICANALYZE_PARSE_ERROR,
            "You have an error in your CQL syntax; check the manual that corresponds to your Streaming version for the right syntax to use near '"
                + errorSymbol + "' at line " + line + ":" + charPositionInLine);
    LOG.error(parserException.getMessage(), parserException);
}
 
Example #7
Source File: LogicalProgramTransformsTest.java    From yql-plus with Apache License 2.0 6 votes vote down vote up
@Test
public void requireSubSubqueryReplacement() throws IOException, RecognitionException {
    ProgramParser parser = new ProgramParser();
    OperatorNode<StatementOperator> program = parser.parse("program.yql",
            "SELECT * " +
                    "  FROM source1 WHERE id IN (SELECT id2 FROM source2 WHERE id2 IN (SELECT a + 1 FROM source3));"
    );
    LogicalProgramTransforms transforms = new LogicalProgramTransforms();
    OperatorNode<StatementOperator> operator = transforms.apply(program, new ViewRegistry() {
        @Override
        public OperatorNode<SequenceOperator> getView(List<String> name) {
            return null;
        }
    });
    Assert.assertEquals(operator.toString(), "(PROGRAM L0:0 [(EXECUTE (EXTRACT {rowType=[source3]} (SCAN L93:1 {alias=source3, rowType=[source3]} [source3], []), (ADD (READ_FIELD L82:1 {rowType=[source3]} source3, a), (LITERAL L86:1 1))), subquery$0), (EXECUTE (EXTRACT {rowType=[source2]} (FILTER {rowType=[source2]} (SCAN L53:1 {alias=source2, rowType=[source2]} [source2], []), (IN (READ_FIELD L67:1 {rowType=[source2]} source2, id2), (VARREF subquery$0))), (READ_FIELD L44:1 {rowType=[source2]} source2, id2)), subquery$1), (EXECUTE L0:1 (FILTER {rowType=[source1]} (SCAN L16:1 {alias=source1, rowType=[source1]} [source1], []), (IN (READ_FIELD L30:1 {rowType=[source1]} source1, id), (VARREF subquery$1))), result1), (OUTPUT L0:1 result1)])");
}
 
Example #8
Source File: DescriptiveErrorStrategy.java    From groovy with Apache License 2.0 6 votes vote down vote up
@Override
public void recover(Parser recognizer, RecognitionException e) {
    for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
        context.exception = e;
    }

    if (PredictionMode.LL.equals(recognizer.getInterpreter().getPredictionMode())) {
        if (e instanceof NoViableAltException) {
            this.reportNoViableAlternative(recognizer, (NoViableAltException) e);
        } else if (e instanceof InputMismatchException) {
            this.reportInputMismatch(recognizer, (InputMismatchException) e);
        } else if (e instanceof FailedPredicateException) {
            this.reportFailedPredicate(recognizer, (FailedPredicateException) e);
        }
    }

    throw new ParseCancellationException(e);
}
 
Example #9
Source File: EditorConfigParser.java    From editorconfig-netbeans with MIT License 6 votes vote down vote up
public final RootPropertyStatementContext rootPropertyStatement() throws RecognitionException {
  RootPropertyStatementContext _localctx = new RootPropertyStatementContext(_ctx, getState());
  enterRule(_localctx, 6, RULE_rootPropertyStatement);
  try {
    enterOuterAlt(_localctx, 1);
    {
      setState(38);
      match(PROPERTY_KEY_ROOT);
      setState(39);
      match(ASSIGNMENT);
      setState(40);
      propertyValue();
    }
  } catch (RecognitionException re) {
    _localctx.exception = re;
    _errHandler.reportError(this, re);
    _errHandler.recover(this, re);
  } finally {
    exitRule();
  }
  return _localctx;
}
 
Example #10
Source File: SoqlParser.java    From components with Apache License 2.0 5 votes vote down vote up
public final SubqueryListContext subqueryList() throws RecognitionException {
	SubqueryListContext _localctx = new SubqueryListContext(_ctx, getState());
	enterRule(_localctx, 10, RULE_subqueryList);
	int _la;
	try {
		enterOuterAlt(_localctx, 1);
		{
			setState(53);
			subquery();
			setState(58);
			_errHandler.sync(this);
			_la = _input.LA(1);
			while (_la == COMMA) {
				{
					{
						setState(54);
						match(COMMA);
						setState(55);
						subquery();
					}
				}
				setState(60);
				_errHandler.sync(this);
				_la = _input.LA(1);
			}
		}
	} catch (RecognitionException re) {
		_localctx.exception = re;
		_errHandler.reportError(this, re);
		_errHandler.recover(this, re);
	} finally {
		exitRule();
	}
	return _localctx;
}
 
Example #11
Source File: UserMatch.java    From onedev with MIT License 5 votes vote down vote up
public static UserMatch parse(@Nullable String userMatchString) {
	List<UserMatchCriteria> criterias = new ArrayList<>();
	List<UserMatchCriteria> exceptCriterias = new ArrayList<>();
	
	if (userMatchString != null) {
		CharStream is = CharStreams.fromString(userMatchString); 
		UserMatchLexer lexer = new UserMatchLexer(is);
		lexer.removeErrorListeners();
		lexer.addErrorListener(new BaseErrorListener() {

			@Override
			public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
					int charPositionInLine, String msg, RecognitionException e) {
				throw new RuntimeException("Malformed user match");
			}
			
		});
		CommonTokenStream tokens = new CommonTokenStream(lexer);
		UserMatchParser parser = new UserMatchParser(tokens);
		parser.removeErrorListeners();
		parser.setErrorHandler(new BailErrorStrategy());
		
		UserMatchContext userMatchContext = parser.userMatch();
		
		for (CriteriaContext criteriaContext: userMatchContext.criteria())
			criterias.add(getUserMatchCriteria(criteriaContext));
		
		for (ExceptCriteriaContext exceptCriteriaContext: userMatchContext.exceptCriteria()) {
			exceptCriterias.add(getUserMatchCriteria(exceptCriteriaContext.criteria()));
		}
	}
	
	return new UserMatch(criterias, exceptCriterias);
}
 
Example #12
Source File: BailSyntaxErrorStrategy.java    From gdl with Apache License 2.0 5 votes vote down vote up
/**
 *  Instead of recovering from exception {@code e}, re-throw it wrapped
 *  in a {@link ParseCancellationException} so it is not caught by the
 *  rule function catches.  Use {@link Exception#getCause()} to get the
 *  original {@link RecognitionException}. To print the syntax error the
 *  {@link DefaultErrorStrategy#recover(Parser, RecognitionException)} method
 *  gets executed.
 */
@Override
public void recover(Parser recognizer, RecognitionException e) {
  super.recover(recognizer, e);
  for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
    context.exception = e;
  }
  throw new ParseCancellationException(e);
}
 
Example #13
Source File: PatternSet.java    From onedev with MIT License 5 votes vote down vote up
public static PatternSet parse(@Nullable String patternSetString) {
	Set<String> includes = new HashSet<>();
	Set<String> excludes = new HashSet<>();
	
	if (patternSetString != null) {
		CharStream is = CharStreams.fromString(patternSetString); 
		PatternSetLexer lexer = new PatternSetLexer(is);
		lexer.removeErrorListeners();
		lexer.addErrorListener(new BaseErrorListener() {

			@Override
			public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
					int charPositionInLine, String msg, RecognitionException e) {
				throw new RuntimeException("Malformed pattern set");
			}
			
		});
		CommonTokenStream tokens = new CommonTokenStream(lexer);
		PatternSetParser parser = new PatternSetParser(tokens);
		parser.removeErrorListeners();
		parser.setErrorHandler(new BailErrorStrategy());
		
		PatternsContext patternsContext = parser.patterns();
		
		for (PatternContext pattern: patternsContext.pattern()) {
			String value;
			if (pattern.Quoted() != null) 
				value = FenceAware.unfence(pattern.Quoted().getText());
			else 
				value = pattern.NQuoted().getText();
			value = StringUtils.unescape(value);
			if (pattern.Excluded() != null)
				excludes.add(value);
			else 
				includes.add(value);
		}			
	}
	
	return new PatternSet(includes, excludes);
}
 
Example #14
Source File: NaturalLanguageStrategyService.java    From robozonky with Apache License 2.0 5 votes vote down vote up
@Override
public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol, final int line,
        final int charPositionInLine, final String msg, final RecognitionException e) {
    final String error = "Syntax error at " + line + ":" + charPositionInLine + ", offending symbol "
            + offendingSymbol + ", message: " + msg;
    throw new IllegalStateException(error, e);
}
 
Example #15
Source File: GyroErrorListener.java    From gyro with Apache License 2.0 5 votes vote down vote up
@Override
public void syntaxError(
    Recognizer<?, ?> recognizer,
    Object symbol,
    int line,
    int column,
    String message,
    RecognitionException error) {

    syntaxErrors.add(symbol instanceof Token
        ? new SyntaxError(stream, message, (Token) symbol)
        : new SyntaxError(stream, message, line - 1, column));
}
 
Example #16
Source File: XpathParser.java    From JsoupXpath with Apache License 2.0 5 votes vote down vote up
public final UnaryExprNoRootContext unaryExprNoRoot() throws RecognitionException {
	UnaryExprNoRootContext _localctx = new UnaryExprNoRootContext(_ctx, getState());
	enterRule(_localctx, 42, RULE_unaryExprNoRoot);
	int _la;
	try {
		enterOuterAlt(_localctx, 1);
		{
		setState(202);
		_errHandler.sync(this);
		_la = _input.LA(1);
		if (_la==MINUS) {
			{
			setState(201);
			((UnaryExprNoRootContext)_localctx).sign = match(MINUS);
			}
		}

		setState(204);
		unionExprNoRoot();
		}
	}
	catch (RecognitionException re) {
		_localctx.exception = re;
		_errHandler.reportError(this, re);
		_errHandler.recover(this, re);
	}
	finally {
		exitRule();
	}
	return _localctx;
}
 
Example #17
Source File: Python335FileAnalyzer.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Getter for the field <code>constructs</code>.</p>
 *
 * @param m a {@link java.io.InputStream} object.
 * @return a {@link java.util.Map} object.
 * @throws com.sap.psr.vulas.FileAnalysisException if any.
 * @throws java.io.IOException if any.
 * @throws org.antlr.v4.runtime.RecognitionException if any.
 */
public Map<ConstructId, Construct> getConstructs(InputStream m) throws FileAnalysisException, IOException, RecognitionException {
	final ANTLRInputStream input = new ANTLRInputStream(m);
	final Python335Lexer lexer = new Python335Lexer(input);
	final CommonTokenStream tokens = new CommonTokenStream(lexer);
	final Python335Parser parser = new Python335Parser(tokens);
	final ParseTree root = parser.file_input();
	final ParseTreeWalker walker = new ParseTreeWalker();
	
	try {
		walker.walk(this, root);
	}
	catch(IllegalStateException ise) {
		throw new FileAnalysisException("Parser error", ise);
	}

	// Update module body after the parsing of the entire file
	if(this.stmts!=null && this.stmts.size()>0) {
		final StringBuffer b = new StringBuffer();
		for(String stmt: this.stmts)
			if(!stmt.trim().equals(""))
				b.append(stmt);
		this.constructs.get(this.module).setContent(b.toString());
	}
	
	return this.constructs;
}
 
Example #18
Source File: JsonLexerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void syntaxError(
        Recognizer<?, ?> rcgnzr,
        Object o,
        int i,
        int i1,
        String string,
        RecognitionException re) {
    errors.offer(re);
}
 
Example #19
Source File: JsErrorManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void syntaxError(
        final Recognizer<?, ?> recognizer,
        final Object offendingSymbol,
        final int line,
        final int charPositionInLine,
        final String msg,
        final RecognitionException e) {
    if (recognizer instanceof Parser) {
        //Recognizer can be either Parser or Lexer
        List<String> stack = ((Parser) recognizer).getRuleInvocationStack();
        Collections.reverse(stack);
    }
    addParserError(new AntlrParserError(msg, line, charPositionInLine, offendingSymbol));
}
 
Example #20
Source File: ScriptDecisionTableErrorListener.java    From urule with Apache License 2.0 5 votes vote down vote up
@Override
public void syntaxError(Recognizer<?, ?> recognizer,Object offendingSymbol, 
		int line, int charPositionInLine,
		String msg, RecognitionException e) {
	if(sb==null){
		sb=new StringBuffer();
	}
	sb.append("["+offendingSymbol+"] is invalid:"+msg);
	sb.append("\r\n");
}
 
Example #21
Source File: TestParsing.java    From yql-plus with Apache License 2.0 5 votes vote down vote up
@Test(dataProvider = "programorexpression")
public void testConvertProgramOrExpression(Unit unit, String input, String expectedOutput) throws IOException, RecognitionException {
    String output;
    switch (unit) {
        case PROGRAM:
            output = new ProgramParser().parse("<string", input).toString();
            break;
        case EXPRESSION:
            output = new ProgramParser().parseExpression(input).toString();
            break;
        default:
            throw new IllegalArgumentException();
    }
    Assert.assertEquals(output, expectedOutput);
}
 
Example #22
Source File: QueryTest.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void insensitiveToCaseBuiltInCall() throws Exception {
    String queryString = "select * WHERE { ?s ?P ?o FILTeR (sameTeRm(?s, ?o))}";
    Sparql11Parser parser = Query.getParser(queryString);
    TokenStream tokens = parser.getTokenStream();
    parser.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);
        }
    });

    parser.query();
    assertEquals(queryString, tokens.getText());
}
 
Example #23
Source File: RegexLiterals.java    From onedev with MIT License 5 votes vote down vote up
@Override
public void syntaxError(Recognizer<?, ?> recognizer,
						Object offendingSymbol,
						int line,
						int charPositionInLine,
						String msg,
						RecognitionException e) {
	logger.error("line " + line + ":" + charPositionInLine + " " + msg);
}
 
Example #24
Source File: ParserErrorListener.java    From karate with MIT License 5 votes vote down vote up
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int position, String message, RecognitionException e) {
    logger.error("syntax error: {}", message);
    this.message = message;
    this.line = line;
    this.position = position;
    this.offendingSymbol = offendingSymbol;
}
 
Example #25
Source File: JavascriptParserErrorStrategy.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the ANTLR parser will throw an exception after the first error
 *
 * @param recognizer the parser being used
 * @return no actual return value
 * @throws RecognitionException not used as a ParseException wrapped in a RuntimeException is thrown instead
 */
@Override
public Token recoverInline(Parser recognizer) throws RecognitionException {
  Token token = recognizer.getCurrentToken();
  String message = "unexpected token " + getTokenErrorDisplay(token) +
      " on line (" + token.getLine() + ") position (" + token.getCharPositionInLine() + ")" +
      " was expecting one of " + recognizer.getExpectedTokens().toString(recognizer.getVocabulary());
  ParseException parseException = new ParseException(message, token.getStartIndex());
  throw new RuntimeException(parseException);
}
 
Example #26
Source File: SoqlParser.java    From components with Apache License 2.0 5 votes vote down vote up
public final AnythingClauseContext anythingClause() throws RecognitionException {
	AnythingClauseContext _localctx = new AnythingClauseContext(_ctx, getState());
	enterRule(_localctx, 6, RULE_anythingClause);
	int _la;
	try {
		enterOuterAlt(_localctx, 1);
		{
			setState(41);
			_errHandler.sync(this);
			_la = _input.LA(1);
			do {
				{
					{
						setState(40);
						anything();
					}
				}
				setState(43);
				_errHandler.sync(this);
				_la = _input.LA(1);
			} while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << COMMA) | (1L << DOT) | (1L << LPAR)
					| (1L << RPAR) | (1L << NAME) | (1L << ANYCHAR) | (1L << BY))) != 0));
		}
	} catch (RecognitionException re) {
		_localctx.exception = re;
		_errHandler.reportError(this, re);
		_errHandler.recover(this, re);
	} finally {
		exitRule();
	}
	return _localctx;
}
 
Example #27
Source File: QueryOptionsFactory.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine,
                        String msg, RecognitionException e) {

    String message = String.format("failed to parse due to %s with offending token: %s", msg,
                                   vocabulary.getDisplayName(e.getOffendingToken().getType()));
    throw new IllegalStateException(message, e);
}
 
Example #28
Source File: XMLParser.java    From manifold with Apache License 2.0 5 votes vote down vote up
public final MiscContext misc() throws RecognitionException
{
  MiscContext _localctx = new MiscContext( _ctx, getState() );
  enterRule( _localctx, 14, RULE_misc );
  int _la;
  try
  {
    enterOuterAlt( _localctx, 1 );
    {
      setState( 93 );
      _la = _input.LA( 1 );
      if( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << COMMENT) | (1L << SEA_WS) | (1L << PI))) != 0)) )
      {
        _errHandler.recoverInline( this );
      }
      consume();
    }
  }
  catch( RecognitionException re )
  {
    _localctx.exception = re;
    _errHandler.reportError( this, re );
    _errHandler.recover( this, re );
  }
  finally
  {
    exitRule();
  }
  return _localctx;
}
 
Example #29
Source File: KsqlParserErrorStrategy.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 5 votes vote down vote up
protected void reportUnwantedToken(Parser recognizer) {
  if (!this.inErrorRecoveryMode(recognizer)) {
    this.beginErrorCondition(recognizer);
    Token t = recognizer.getCurrentToken();
    String tokenName = this.getTokenErrorDisplay(t);
    IntervalSet expecting = this.getExpectedTokens(recognizer);
    String msg =
        "extraneous input " + tokenName + " expecting "
        + expecting.toString(recognizer.getVocabulary());
    recognizer.notifyErrorListeners(t, msg, (RecognitionException) null);
  }
}
 
Example #30
Source File: CompilingTestBase.java    From yql-plus with Apache License 2.0 5 votes vote down vote up
protected OperatorNode<SequenceOperator> parseQuery(String query) throws IOException, RecognitionException {
    OperatorNode<StatementOperator> program = parseQueryProgram(query);
    List<OperatorNode<StatementOperator>> statements = program.getArgument(0);
    for(OperatorNode<StatementOperator> statement : statements) {
        if(statement.getOperator() == StatementOperator.EXECUTE) {
            if(statement.getArgument(1).equals("f1")) {
                return statement.getArgument(0);
            }
        }
    }
    throw new IllegalStateException("Unable to find f1 output query in parsed program?: " + program);
}