Java Code Examples for com.sonar.sslr.api.typed.ActionParser#parse()
The following examples show how to use
com.sonar.sslr.api.typed.ActionParser#parse() .
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: CssCheckVerifier.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private static void verify(CssCheck check, File file, Charset charset, ActionParser<Tree> parser, String language) { TreeImpl tree = (TreeImpl) parser.parse(file); CssTreeVisitorContext context = new CssTreeVisitorContext(tree, file, language); CssCheckVerifier checkVerifier = new CssCheckVerifier(); checkVerifier.scanFile(context); List<TestIssue> expectedIssues = checkVerifier.expectedIssues .stream() .sorted((i1, i2) -> Integer.compare(i1.line(), i2.line())) .collect(Collectors.toList()); if (check instanceof CharsetAwareVisitor) { ((CharsetAwareVisitor) check).setCharset(charset); } Iterator<Issue> actualIssues = getActualIssues(check, context); for (TestIssue expected : expectedIssues) { if (actualIssues.hasNext()) { verifyIssue(expected, actualIssues.next(), file); } else { throw new AssertionError("Missing issue at line " + expected.line() + " in file " + file.getAbsolutePath()); } } if (actualIssues.hasNext()) { Issue issue = actualIssues.next(); throw new AssertionError("Unexpected issue at line " + line(issue) + ": \"" + message(issue) + "\"" + " in file " + file.getAbsolutePath()); } }
Example 2
Source File: TreeCheckTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 5 votes |
public static Collection<CheckMessage> getIssues(String relativePath, CssCheck check, ActionParser<Tree> parser) { File file = new File(relativePath); TreeImpl tree = (TreeImpl) parser.parse(file); CssTreeVisitorContext context = new CssTreeVisitorContext(tree, file, "css"); List<Issue> issues = check.scanFile(context); return getCheckMessages(issues); }
Example 3
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 4
Source File: TestUtils.java From sonar-esql-plugin with Apache License 2.0 | 5 votes |
private static EsqlVisitorContext createContext(InputFile file, ActionParser<Tree> parser) { try { ProgramTree programTree = (ProgramTree) parser.parse(file.contents()); return new EsqlVisitorContext(programTree, file, new MapSettings().asConfig()); } catch (IOException e) { throw new RuntimeException(e); } }