com.sonar.sslr.api.typed.ActionParser Java Examples

The following examples show how to use com.sonar.sslr.api.typed.ActionParser. 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: TreeCheckTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #2
Source File: TestUtils.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #3
Source File: Assertions.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
public static ParserAssert assertThat(LexerlessGrammarBuilder b, GrammarRuleKey rule) {
  return new ParserAssert(new ActionParser<Tree>(
    Charsets.UTF_8,
    b,
    EsqlGrammar.class,
    new TreeFactory(),
    new EsqlNodeBuilder(),
    rule));
}
 
Example #4
Source File: LegacyParserTest.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  LexerlessGrammarBuilder b = EsqlLegacyGrammar.createGrammarBuilder();
  // Only called to completed the grammar
  new ActionParser<AstNode>(Charsets.UTF_8, b, EsqlGrammar.class, new TreeFactory(), new AstNodeBuilder(), EsqlLegacyGrammar.SPACING);
  g = b.build();
}
 
Example #5
Source File: ParserTest.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
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: CssCheckVerifier.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #7
Source File: ScssParser.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static ActionParser<Tree> createParser(Charset charset, GrammarRuleKey rootRule) {
  return new ScssParser(
    charset,
    LexicalGrammar.createScssGrammar(),
    ScssGrammar.class,
    new TreeFactory(),
    new ScssNodeBuilder(),
    rootRule);
}
 
Example #8
Source File: LessParser.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static ActionParser<Tree> createParser(Charset charset, GrammarRuleKey rootRule) {
  return new LessParser(
    charset,
    LexicalGrammar.createLessGrammar(),
    LessGrammar.class,
    new TreeFactory(),
    new LessNodeBuilder(),
    rootRule);
}
 
Example #9
Source File: CssParser.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static ActionParser<Tree> createParser(Charset charset, GrammarRuleKey rootRule) {
  return new CssParser(
    charset,
    LexicalGrammar.createCssGrammar(),
    CssGrammar.class,
    new TreeFactory(),
    new CssNodeBuilder(),
    rootRule);
}
 
Example #10
Source File: EmbeddedCssParser.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static ActionParser<Tree> createParser(Charset charset, GrammarRuleKey rootRule) {
  return new EmbeddedCssParser(
    charset,
    LexicalGrammar.createEmbeddedCssGrammar(),
    EmbeddedCssGrammar.class,
    new TreeFactory(),
    new EmbeddedCssNodeBuilder(),
    rootRule);
}
 
Example #11
Source File: LessAnalyzerSensor.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public ActionParser<Tree> parser(FileSystem fileSystem) {
  return LessParser.createParser(fileSystem.encoding());
}
 
Example #12
Source File: CssParser.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
@VisibleForTesting
public static ActionParser<Tree> createTestParser(Charset charset, GrammarRuleKey rootRule) {
  return createParser(charset, rootRule);
}
 
Example #13
Source File: TestUtils.java    From sonar-esql-plugin with Apache License 2.0 4 votes vote down vote up
private static ActionParser<Tree> newParser() {
    return EsqlParserBuilder.createParser();
}
 
Example #14
Source File: Assertions.java    From sonar-esql-plugin with Apache License 2.0 4 votes vote down vote up
public ParserAssert(ActionParser<Tree> actual) {
  super(ParserAssert.class, actual);
}
 
Example #15
Source File: EmbeddedCssParser.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static ActionParser<Tree> createParser(Charset charset) {
  return createParser(charset, LexicalGrammar.FILE_WITH_EMBEDDED_CSS);
}
 
Example #16
Source File: EsqlTreeModelTest.java    From sonar-esql-plugin with Apache License 2.0 4 votes vote down vote up
private ActionParser<Tree> getParser(GrammarRuleKey rule){
	return  new ActionParser<>(Charsets.UTF_8, EsqlLegacyGrammar.createGrammarBuilder(), EsqlGrammar.class,
			new TreeFactory(), new EsqlNodeBuilder(), rule);

}
 
Example #17
Source File: DoubleDispatchVisitorTest.java    From sonar-esql-plugin with Apache License 2.0 4 votes vote down vote up
private TestVisitor getTestVisitor(String code) {
	ActionParser<Tree> p = EsqlParserBuilder.createParser();
	TestVisitor testVisitor = new TestVisitor();
	testVisitor.visitProgram((ProgramTree) p.parse(code));
	return testVisitor;
}
 
Example #18
Source File: EsqlParserBuilder.java    From sonar-esql-plugin with Apache License 2.0 4 votes vote down vote up
public static ActionParser<Tree> createParser(GrammarRuleKey rootRule){
 return new EsqlParser(rootRule);
}
 
Example #19
Source File: EsqlParserBuilder.java    From sonar-esql-plugin with Apache License 2.0 4 votes vote down vote up
public static ActionParser<Tree> createParser() {
  return new EsqlParser();
}
 
Example #20
Source File: EmbeddedCssParser.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
@VisibleForTesting
public static ActionParser<Tree> createTestParser(Charset charset, GrammarRuleKey rootRule) {
  return createParser(charset, rootRule);
}
 
Example #21
Source File: GherkinTreeTest.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ActionParser<Tree> parser() {
  return parser;
}
 
Example #22
Source File: ScssAnalyzerSensor.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public ActionParser<Tree> parser(FileSystem fileSystem) {
  return ScssParser.createParser(fileSystem.encoding());
}
 
Example #23
Source File: LessParser.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
@VisibleForTesting
public static ActionParser<Tree> createTestParser(Charset charset, GrammarRuleKey rootRule) {
  return createParser(charset, rootRule);
}
 
Example #24
Source File: EmbeddedCssAnalyzerSensor.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public ActionParser<Tree> parser(FileSystem fileSystem) {
  return EmbeddedCssParser.createParser(fileSystem.encoding());
}
 
Example #25
Source File: CssAnalyzerSensor.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public ActionParser<Tree> parser(FileSystem fileSystem) {
  return CssParser.createParser(fileSystem.encoding());
}
 
Example #26
Source File: CssParser.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static ActionParser<Tree> createParser(Charset charset) {
  return createParser(charset, LexicalGrammar.STYLESHEET);
}
 
Example #27
Source File: ScssTreeTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ActionParser<Tree> parser() {
  return parser;
}
 
Example #28
Source File: LessTreeTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ActionParser<Tree> parser() {
  return parser;
}
 
Example #29
Source File: EmbeddedCssTreeTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ActionParser<Tree> parser() {
  return parser;
}
 
Example #30
Source File: CssTreeTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ActionParser<Tree> parser() {
  return parser;
}