@Test public void testParse_inputWithSyntaxErrorsGivesResultWithSyntaxErrors() throws Exception { QuestionnaireParsingResult result = parser.parse(RESOURCE_ROOT + "ql/input_form_with_syntax_errors.ql"); assertThat(result, is(notNullValue())); List<SyntaxError> syntaxErrors = result.getSyntaxErrors(); assertThat(syntaxErrors.toString(), syntaxErrors.size(), is(5)); SyntaxError missingFormError = syntaxErrors.get(0); assertThat(missingFormError.getValidationMessage(), is("missing 'form' at 'fom'")); TextLocation textLocation = missingFormError.getTextLocation(); assertThat(textLocation.getColumn(), is(0)); assertThat(textLocation.getLine(), is(1)); }
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);  }