@Test public void testParse_validInputGivesResultWithAbstractSyntaxTree() throws Exception { QuestionnaireParsingResult result = parser.parse(RESOURCE_ROOT + "ql/input_form.ql"); assertThat(result, is(notNullValue())); List<SyntaxError> syntaxErrors = result.getSyntaxErrors(); assertThat(syntaxErrors.toString(), syntaxErrors.size(), is(0)); Questionnaire questionnaire = result.getQuestionnaire(); assertThat(questionnaire, is(notNullValue())); assertThat(questionnaire.getName(), is("taxOfficeExample")); List<Statement> statements = questionnaire.getStatements(); assertThat(statements, is(notNullValue())); assertThat(statements.toString(), statements.size(), is(9)); Question hasSoldHouse = (Question) statements.get(0); assertThat(hasSoldHouse.getName(), is("hasSoldHouse")); ConditionalBlock conditionalBlock = (ConditionalBlock) statements.get(7); BinaryExpression condition = (BinaryExpression) conditionalBlock.getCondition(); BinaryOperator operator = condition.getOperator(); assertThat(operator.toString(), is("&&")); }
public QuestionnaireParsingResult parse(String pathname) throws IOException { EncodersQLLexer lexer = new EncodersQLLexer(new ANTLRFileStream(pathname)); EncodersQLParser parser = new EncodersQLParser(new CommonTokenStream(lexer)); final List<SyntaxError> syntaxErrors = new ArrayList<>(); parser.addErrorListener(new BaseErrorListener() { @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int column, String msg, RecognitionException e) { syntaxErrors.add(new SyntaxError(msg, new TextLocation(line, column))); } }); QuestionnaireContext parseTree = parser.questionnaire(); ParseTreeToAbstractSyntaxTree parseTreeToAbstractSyntaxTree = new ParseTreeToAbstractSyntaxTree(); Questionnaire questionnaire = (Questionnaire) parseTreeToAbstractSyntaxTree.visit(parseTree); return new QuestionnaireParsingResult(questionnaire, syntaxErrors); }
QuestionnaireParser { public QuestionnaireParsingResult parse(String pathname) throws IOException { EncodersQLLexer lexer = new EncodersQLLexer(new ANTLRFileStream(pathname)); EncodersQLParser parser = new EncodersQLParser(new CommonTokenStream(lexer)); final List<SyntaxError> syntaxErrors = new ArrayList<>(); parser.addErrorListener(new BaseErrorListener() { @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int column, String msg, RecognitionException e) { syntaxErrors.add(new SyntaxError(msg, new TextLocation(line, column))); } }); QuestionnaireContext parseTree = parser.questionnaire(); ParseTreeToAbstractSyntaxTree parseTreeToAbstractSyntaxTree = new ParseTreeToAbstractSyntaxTree(); Questionnaire questionnaire = (Questionnaire) parseTreeToAbstractSyntaxTree.visit(parseTree); return new QuestionnaireParsingResult(questionnaire, syntaxErrors); } }
QuestionnaireParser { public QuestionnaireParsingResult parse(String pathname) throws IOException { EncodersQLLexer lexer = new EncodersQLLexer(new ANTLRFileStream(pathname)); EncodersQLParser parser = new EncodersQLParser(new CommonTokenStream(lexer)); final List<SyntaxError> syntaxErrors = new ArrayList<>(); parser.addErrorListener(new BaseErrorListener() { @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int column, String msg, RecognitionException e) { syntaxErrors.add(new SyntaxError(msg, new TextLocation(line, column))); } }); QuestionnaireContext parseTree = parser.questionnaire(); ParseTreeToAbstractSyntaxTree parseTreeToAbstractSyntaxTree = new ParseTreeToAbstractSyntaxTree(); Questionnaire questionnaire = (Questionnaire) parseTreeToAbstractSyntaxTree.visit(parseTree); return new QuestionnaireParsingResult(questionnaire, syntaxErrors); }  }
QuestionnaireParser { public QuestionnaireParsingResult parse(String pathname) throws IOException { EncodersQLLexer lexer = new EncodersQLLexer(new ANTLRFileStream(pathname)); EncodersQLParser parser = new EncodersQLParser(new CommonTokenStream(lexer)); final List<SyntaxError> syntaxErrors = new ArrayList<>(); parser.addErrorListener(new BaseErrorListener() { @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int column, String msg, RecognitionException e) { syntaxErrors.add(new SyntaxError(msg, new TextLocation(line, column))); } }); QuestionnaireContext parseTree = parser.questionnaire(); ParseTreeToAbstractSyntaxTree parseTreeToAbstractSyntaxTree = new ParseTreeToAbstractSyntaxTree(); Questionnaire questionnaire = (Questionnaire) parseTreeToAbstractSyntaxTree.visit(parseTree); return new QuestionnaireParsingResult(questionnaire, syntaxErrors); }  QuestionnaireParsingResult parse(String pathname); }
QuestionnaireParser { public QuestionnaireParsingResult parse(String pathname) throws IOException { EncodersQLLexer lexer = new EncodersQLLexer(new ANTLRFileStream(pathname)); EncodersQLParser parser = new EncodersQLParser(new CommonTokenStream(lexer)); final List<SyntaxError> syntaxErrors = new ArrayList<>(); parser.addErrorListener(new BaseErrorListener() { @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int column, String msg, RecognitionException e) { syntaxErrors.add(new SyntaxError(msg, new TextLocation(line, column))); } }); QuestionnaireContext parseTree = parser.questionnaire(); ParseTreeToAbstractSyntaxTree parseTreeToAbstractSyntaxTree = new ParseTreeToAbstractSyntaxTree(); Questionnaire questionnaire = (Questionnaire) parseTreeToAbstractSyntaxTree.visit(parseTree); return new QuestionnaireParsingResult(questionnaire, syntaxErrors); }  QuestionnaireParsingResult parse(String pathname);  }