com.sonar.sslr.impl.Parser类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(159)

本文整理了Java中com.sonar.sslr.impl.Parser类的一些代码示例,展示了Parser类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parser类的具体详情如下:
包路径:com.sonar.sslr.impl.Parser
类名称:Parser

Parser介绍

[英]To create a new instance of this class use Parser#builder(Grammar).

This class is not intended to be instantiated or subclassed by clients.
[中]要创建此类的新实例,请使用Parser#builder(Grammar)
该类不打算由客户端实例化或子类化。

代码示例

代码示例来源:origin: org.sonarsource.sslr/sslr-testing-harness

public static AstNode parseString(String source) {
 return P.parse(source);
}

代码示例来源:origin: fundacionjala/enforce-sonarqube-plugin

/**
   * Re-parses a query that was retrieved as a String.
   *
   * @param astNode The String's node.
   * @return The query as a new QUERY_EXPRESSION node.
   */
  public static AstNode parseQuery(AstNode astNode) {
    AstNode parsedQuery = null;
    try {
      String string = astNode.getTokenOriginalValue();
      String queryAsString = StringUtils.substringBetween(string, "'", "'");
      Parser<Grammar> queryParser = ApexParser.create(new ApexConfiguration(Charsets.UTF_8));
      queryParser.setRootRule(queryParser.getGrammar().rule(ApexGrammarRuleKey.QUERY_EXPRESSION));
      parsedQuery = queryParser.parse(queryAsString);
    } catch (Exception e) {
      ChecksLogger.logCheckError(CLASS_TO_LOG, METHOD_TO_LOG, e.toString());
    }
    return parsedQuery;
  }
}

代码示例来源:origin: org.codehaus.sonar-plugins.dotnet.csharp/sonar-csharp-squid-plugin

public IgnoreUsingDirectivePreprocessor(CSharpConfiguration conf) {
 this.parser = CSharpParser.create(conf);
 this.parser.setRootRule(this.parser.getGrammar().usingDirective);
}

代码示例来源:origin: fundacionjala/enforce-sonarqube-plugin

/**
   * Creates a Parser integrated with Grammar and Lexer.
   *
   * @param config apex configuration.
   * @return a parser
   * @throws IllegalArgumentException when configuration is null.
   */
  public static Parser<Grammar> create(ApexConfiguration config) {
    if (config == null) {
      throw new IllegalArgumentException(ERROR_MESSAGE);
    }
    return Parser.builder(ApexGrammar.create())
        .withLexer(ApexLexer.create(config)).build();
  }
}

代码示例来源:origin: org.sonarsource.sslr/sslr-testing-harness

private Parser createParserWithEofMatcher() {
 RuleDefinition rule = actual.getRootRule();
 RuleDefinition endOfInput = new RuleDefinition(new EndOfInput())
   .is(new FirstOfExpression(EndOfInputExpression.INSTANCE, new TokenTypeExpression(GenericTokenType.EOF)));
 RuleDefinition withEndOfInput = new RuleDefinition(new WithEndOfInput(actual.getRootRule().getRuleKey()))
   .is(rule, endOfInput);
 Parser parser = Parser.builder(actual).build();
 parser.setRootRule(withEndOfInput);
 return parser;
}

代码示例来源:origin: org.codehaus.sonar.sslr-squid-bridge/sslr-squid-bridge

protected AstScanner(Builder<G> builder) {
 this.visitors = Lists.newArrayList(builder.visitors);
 this.parser = builder.baseParser;
 this.context = builder.context;
 this.context.setGrammar(parser.getGrammar());
 this.context.getProject().setSourceCodeIndexer(indexer);
 this.context.setCommentAnalyser(builder.commentAnalyser);
 this.metrics = builder.metrics;
 this.filesMetric = builder.filesMetric;
 indexer.index(context.getProject());
}

代码示例来源:origin: Backelite/sonar-swift

public static Parser<ObjectiveCGrammar> create(ObjectiveCConfiguration conf) {
  return Parser.builder((ObjectiveCGrammar) new ObjectiveCGrammarImpl())
      .withLexer(ObjectiveCLexer.create(conf))
      .build();
}

代码示例来源:origin: SonarSource/sslr

private Parser createParserWithEofMatcher() {
 RuleDefinition rule = actual.getRootRule();
 RuleDefinition endOfInput = new RuleDefinition(new EndOfInput())
   .is(new FirstOfExpression(EndOfInputExpression.INSTANCE, new TokenTypeExpression(GenericTokenType.EOF)));
 RuleDefinition withEndOfInput = new RuleDefinition(new WithEndOfInput(actual.getRootRule().getRuleKey()))
   .is(rule, endOfInput);
 Parser parser = Parser.builder(actual).build();
 parser.setRootRule(withEndOfInput);
 return parser;
}

代码示例来源:origin: sonar-perl/sonar-perl

protected void setRootRule(GrammarRuleKey ruleKey) {
    p.setRootRule(p.getGrammar().rule(ruleKey));
  }
}

代码示例来源:origin: sonar-perl/sonar-perl

@Test
public void ok() {
  p.getGrammar().rule(PerlGrammar.ATOM).mock();
  assertThat(p).matches("ATOM");
  assertThat(p).matches("ATOM ATOM");
  assertThat(p).matches("\n");
  assertThat(p).matches("ATOM\nATOM");
}

代码示例来源:origin: uartois/sonar-golang

public static AstNode parseString(String source) {
return P.parse(source);
}

代码示例来源:origin: Backelite/sonar-swift

public static Parser<SwiftGrammar> create(SwiftConfiguration conf) {
  return Parser.builder((SwiftGrammar) new SwiftGrammarImpl())
      .withLexer(SwiftLexer.create(conf))
      .build();
}

代码示例来源:origin: SonarSource/sslr

public static AstNode parseString(String source) {
 return P.parse(source);
}

代码示例来源:origin: SonarSource/sslr

public static Parser<Grammar> create() {
 return Parser.builder(MiniCGrammar.create()).withLexer(MiniCLexer.create()).build();
}

代码示例来源:origin: org.codehaus.sonar.sslr/sslr-toolkit

public void setSourceCode(File source, Charset charset) {
 this.astNode = configurationModel.getParser().parse(source);
 try {
  this.sourceCode = Files.toString(source, charset);
 } catch (IOException e) {
  Throwables.propagate(e);
 }
}

代码示例来源:origin: org.sonarsource.sslr/sslr-testing-harness

public static Parser<Grammar> create() {
 return Parser.builder(MiniCGrammar.create()).withLexer(MiniCLexer.create()).build();
}

代码示例来源:origin: org.sonarsource.sslr/sslr-toolkit

public void setSourceCode(File source, Charset charset) {
 this.astNode = configurationModel.getParser().parse(source);
 try {
  this.sourceCode = new String(Files.readAllBytes(Paths.get(source.getPath())), charset);
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: uartois/sonar-golang

public static Parser<Grammar> create() {
return Parser.builder(GoGrammar.create()).withLexer(GoLexer.create()).build();
}

代码示例来源:origin: org.sonarsource.sslr/sslr-testing-harness

public static AstNode parseFile(String filePath) {
 File file = FileUtils.toFile(MiniCParser.class.getResource(filePath));
 if (file == null || !file.exists()) {
  throw new AssertionError("The file \"" + filePath + "\" does not exist.");
 }
 return P.parse(file);
}

代码示例来源:origin: octo-technology/sonar-objective-c

public static Parser<ObjectiveCGrammar> create(ObjectiveCConfiguration conf, ParsingEventListener... parsingEventListeners) {
  return Parser.builder((ObjectiveCGrammar) new ObjectiveCGrammarImpl())
      .withLexer(ObjectiveCLexer.create(conf))
      .setParsingEventListeners(parsingEventListeners).build();
}

相关文章