com.sonar.sslr.api.RecognitionException Java Examples
The following examples show how to use
com.sonar.sslr.api.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: Assertions.java From sonar-esql-plugin with Apache License 2.0 | 6 votes |
/** * Verifies that the actual <code>{@link Rule}</code> partially matches a given input. * * @param prefixToBeMatched the prefix that must be fully matched * @param remainingInput the remainder of the input, which is not to be matched * @return this assertion object. */ public ParserAssert matchesPrefix(String prefixToBeMatched, String remainingInput) { isNotNull(); try { EsqlTree tree = (EsqlTree) actual.parse(prefixToBeMatched + remainingInput); SyntaxToken lastToken = tree.lastToken(); if (prefixToBeMatched.length() != lastToken.column() + lastToken.text().length()) { throw new RecognitionException(0, "Rule '" + getRuleName() + "' should match:\n" + prefixToBeMatched + "\nwhen followed by:\n" + remainingInput); } } catch (RecognitionException e) { throw new RecognitionException(0, e.getMessage() + "\n" + "Rule '" + getRuleName() + "' should match:\n" + prefixToBeMatched + "\nwhen followed by:\n" + remainingInput); } return this; }
Example #2
Source File: EsqlSensor.java From sonar-esql-plugin with Apache License 2.0 | 6 votes |
private void processRecognitionException(RecognitionException e, SensorContext sensorContext, InputFile inputFile) { if (parsingErrorRuleKey != null) { NewIssue newIssue = sensorContext.newIssue(); NewIssueLocation primaryLocation = newIssue.newLocation() .message(ParsingErrorCheck.MESSAGE) .on(inputFile) .at(inputFile.selectLine(e.getLine())); newIssue .forRule(parsingErrorRuleKey) .at(primaryLocation) .save(); } sensorContext.newAnalysisError() .onFile(inputFile) .at(inputFile.newPointer(e.getLine(), 0)) .message(e.getMessage()) .save(); }
Example #3
Source File: AbstractLanguageAnalyzerSensor.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private void processRecognitionException(RecognitionException e, SensorContext sensorContext, InputFile inputFile) { if (parsingErrorRuleKey != null) { NewIssue newIssue = sensorContext.newIssue(); NewIssueLocation primaryLocation = newIssue.newLocation() .message(e.getMessage()) .on(inputFile) .at(inputFile.selectLine(e.getLine())); newIssue .forRule(parsingErrorRuleKey) .at(primaryLocation) .save(); } }
Example #4
Source File: GherkinSquidSensor.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private void processRecognitionException(RecognitionException e, SensorContext sensorContext, InputFile inputFile) { if (parsingErrorRuleKey != null) { NewIssue newIssue = sensorContext.newIssue(); NewIssueLocation primaryLocation = newIssue.newLocation() .message(e.getMessage()) .on(inputFile) .at(inputFile.selectLine(e.getLine())); newIssue .forRule(parsingErrorRuleKey) .at(primaryLocation) .save(); } }
Example #5
Source File: ParserTest.java From sonar-esql-plugin with Apache License 2.0 | 5 votes |
private void parse(File esql) { ActionParser parser = new ActionParser<>(Charsets.UTF_8, EsqlLegacyGrammar.createGrammarBuilder(), EsqlGrammar.class, new TreeFactory(), new EsqlNodeBuilder(), EsqlLegacyGrammar.PROGRAM); try{ parser.parse(esql); } catch(RecognitionException e ){ System.err.println("Cannot parse "+esql.toPath()); throw e; } }
Example #6
Source File: Assertions.java From sonar-esql-plugin with Apache License 2.0 | 5 votes |
private void parseTillEof(String input) { EsqlTree tree = (EsqlTree) actual.parse(input); InternalSyntaxToken lastToken = (InternalSyntaxToken) tree.lastToken(); int eofIndex = input.length(); if (lastToken.toIndex() != eofIndex) { throw new RecognitionException( 0, "Did not match till EOF, but till line " + lastToken.line() + ": token \"" + lastToken.text() + "\""); } }
Example #7
Source File: Assertions.java From sonar-esql-plugin with Apache License 2.0 | 5 votes |
public ParserAssert matches(String input) { isNotNull(); Preconditions.checkArgument(!hasTrailingWhitespaces(input), "Trailing whitespaces in input are not supported"); String expected = "Rule '" + getRuleName() + "' should match:\n" + input; try { parseTillEof(input); } catch (RecognitionException e) { String actual = e.getMessage(); throw new ParsingResultComparisonFailure(expected, actual); } return this; }
Example #8
Source File: Assertions.java From sonar-esql-plugin with Apache License 2.0 | 5 votes |
public ParserAssert notMatches(String input) { isNotNull(); try { parseTillEof(input); } catch (RecognitionException e) { // expected return this; } throw new AssertionError("Rule '" + getRuleName() + "' should not match:\n" + input); }
Example #9
Source File: EsqlSensorTest.java From sonar-esql-plugin with Apache License 2.0 | 5 votes |
@Test public void cancelled_analysis_causing_recognition_exception() throws Exception { EsqlCheck check = new ExceptionRaisingCheck( new RecognitionException(42, "message", new InterruptedIOException())); analyseFileWithException(check, inputFile("cpd/Person.esql"), "Analysis cancelled"); assertThat(context.allAnalysisErrors()).hasSize(1); }
Example #10
Source File: GherkinGrammarTest.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 4 votes |
@Test(expected = RecognitionException.class) public void parse_error() throws Exception { GherkinParserBuilder .createTestParser(Charsets.UTF_8) .parse("blabla"); }