Package org.intellij.grammar.analysis

Examples of org.intellij.grammar.analysis.BnfFirstNextAnalyzer$TextStrategy


  @Nullable
  public String generateDoc(final PsiElement element, final PsiElement originalElement) {
    if (element instanceof BnfRule) {
      final BnfRule rule = (BnfRule)element;
      BnfFirstNextAnalyzer analyzer = new BnfFirstNextAnalyzer();
      Set<String> first = analyzer.asStrings(analyzer.calcFirst(rule));
      Set<String> next = analyzer.asStrings(analyzer.calcNext(rule).keySet());

      StringBuilder docBuilder = new StringBuilder();
      String[] firstS = first.toArray(new String[first.size()]);
      Arrays.sort(firstS);
      docBuilder.append("<h1>Starts with:</h1>");
View Full Code Here


  /**
   * @noinspection StringEquality
   */
  private IElementType[] generateAutoRecoverCall(BnfRule rule) {
    BnfFirstNextAnalyzer analyzer = new BnfFirstNextAnalyzer();
    Set<BnfExpression> nextExprSet = analyzer.calcNext(rule).keySet();
    Set<String> nextSet = analyzer.asStrings(nextExprSet);
    List<IElementType> tokenTypes = new ArrayList<IElementType>(nextSet.size());

    for (String s : nextSet) {
      if (myFile.getRule(s) != null) continue; // ignore left recursion
      if (s == BnfFirstNextAnalyzer.MATCHES_EOF || s == BnfFirstNextAnalyzer.MATCHES_NOTHING) continue;
View Full Code Here

    if (info.rootRule == rule || Rule.isPrivate(rule)) return info;
    return info.priorityMap.containsKey(rule) ? info : null;
  }

  private void buildExpressionRules() {
    BnfFirstNextAnalyzer analyzer = new BnfFirstNextAnalyzer();
    for (BnfRule rule : myFile.getRules()) {
      if (Rule.isPrivate(rule) || Rule.isFake(rule)) continue;
      if (myRootRulesMap.containsKey(rule)) continue;
      Map<PsiElement, RuleGraphHelper.Cardinality> contentRules = myRuleGraph.getFor(rule);
      if (!contentRules.isEmpty()) continue;
      if (!analyzer.asStrings(analyzer.calcFirst(rule)).contains(rule.getName())) continue;

      ExpressionInfo expressionInfo = new ExpressionInfo(rule);
      addToPriorityMap(rule, myRuleGraph.getExtendsRules(rule), expressionInfo);
      List<BnfRule> rules = ParserGeneratorUtil.topoSort(expressionInfo.priorityMap.keySet(), myRuleGraph);
      for (BnfRule r : rules) {
View Full Code Here

    generateNodeChildren(rule, funcName, children, visited);
  }

  /** @noinspection StringEquality*/
  private String generateAutoRecoverCall(BnfRule rule) {
    BnfFirstNextAnalyzer analyzer = new BnfFirstNextAnalyzer();
    Set<BnfExpression> nextExprSet = analyzer.calcNext(rule).keySet();
    Set<String> nextSet = analyzer.asStrings(nextExprSet);
    List<String> tokenTypes = new ArrayList<String>(nextSet.size());

    for (String s : nextSet) {
      if (myFile.getRule(s) != null) continue; // ignore left recursion
      if (s == BnfFirstNextAnalyzer.MATCHES_EOF || s == BnfFirstNextAnalyzer.MATCHES_NOTHING) continue;
View Full Code Here

    return constantName;
  }

  public String generateFirstCheck(BnfRule rule, String frameName, boolean skipIfOne) {
    if (generateFirstCheck <= 0) return frameName;
    BnfFirstNextAnalyzer analyzer = new BnfFirstNextAnalyzer();
    Set<String> firstSet = analyzer.asStrings(analyzer.calcFirst(rule));
    List<String> firstElementTypes = new ArrayList<String>(firstSet.size());
    for (String s : firstSet) {
      if (myFile.getRule(s) != null) continue; // ignore left recursion
      @SuppressWarnings("StringEquality")
      boolean unknown = s == BnfFirstNextAnalyzer.MATCHES_EOF || s == BnfFirstNextAnalyzer.MATCHES_ANY;
View Full Code Here

  private void doTest(String text, boolean first, String... expected) {
    BnfFile f = (BnfFile)myFixture.configureByText("a.bnf", text);
    List<BnfRule> rules = f.getRules();
    assertFalse(rules.isEmpty());
    BnfFirstNextAnalyzer analyzer = new BnfFirstNextAnalyzer();
    Set<String> strings = analyzer.asStrings(first? analyzer.calcFirst(rules.get(0)) : analyzer.calcNext(rules.get(0)).keySet());
    String[] result = ArrayUtil.toStringArray(strings);
    Arrays.sort(result);
    assertOrderedEquals(result, expected);
  }
View Full Code Here

  private void doTest(String text, boolean first, String... expected) {
    BnfFile f = (BnfFile)myFixture.configureByText("a.bnf", text);
    List<BnfRule> rules = f.getRules();
    assertFalse(rules.isEmpty());
    BnfFirstNextAnalyzer analyzer = new BnfFirstNextAnalyzer();
    Set<String> strings = analyzer.asStrings(first? analyzer.calcFirst(rules.get(0)) : analyzer.calcNext(rules.get(0)).keySet());
    String[] result = ArrayUtil.toStringArray(strings);
    Arrays.sort(result);
    assertOrderedEquals(result, expected);
  }
View Full Code Here

  }

  private static void checkChoice(BnfChoice choice, ProblemsHolder problemsHolder) {
    Set<BnfExpression> visited = new THashSet<BnfExpression>();
    THashSet<BnfExpression> first = new THashSet<BnfExpression>();
    BnfFirstNextAnalyzer analyzer = new BnfFirstNextAnalyzer();
    List<BnfExpression> list = choice.getExpressionList();
    for (int i = 0, listSize = list.size() - 1; i < listSize; i++) {
      BnfExpression child = list.get(i);
      Set<String> firstSet = analyzer.asStrings(analyzer.calcFirstInner(child, first, visited));
      if (firstSet.contains(BnfFirstNextAnalyzer.MATCHES_NOTHING)) {
        registerProblem(choice, child, "Branch is unable to match anything due to & or ! conditions", problemsHolder);
      }
      else if (firstSet.contains(BnfFirstNextAnalyzer.MATCHES_EOF)) {
        registerProblem(choice, child, "Branch matches empty input making the rest branches unreachable", problemsHolder);
View Full Code Here

  public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    if (file instanceof BnfFile) {
      BnfFile bnfFile = (BnfFile)file;
      ExpressionHelper expressionHelper = ExpressionHelper.getCached(bnfFile);
      BnfFirstNextAnalyzer analyzer = new BnfFirstNextAnalyzer();
      ArrayList<ProblemDescriptor> list = new ArrayList<ProblemDescriptor>();
      for (BnfRule rule : bnfFile.getRules()) {
        String ruleName = rule.getName();
        boolean exprParsing = ExpressionGeneratorHelper.getInfoForExpressionParsing(expressionHelper, rule) != null;

        if (!exprParsing && analyzer.asStrings(analyzer.calcFirst(rule)).contains(ruleName)) {
          list.add(manager.createProblemDescriptor(rule.getId(), "'" + ruleName + "' employs left-recursion unsupported by generator",
                                                   isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
        }
      }
      if (!list.isEmpty()) return list.toArray(new ProblemDescriptor[list.size()]);
View Full Code Here

    return map;
  }

  private static Map<BnfRule, Cardinality> getRulesToTheLeft(BnfRule rule) {
    Map<BnfRule, Cardinality> result = ContainerUtil.newLinkedHashMap();
    Map<BnfExpression, BnfExpression> nextMap = new BnfFirstNextAnalyzer().setBackward(true).setPublicRuleOpaque(true).calcNext(rule);
    BnfFile containingFile = (BnfFile)rule.getContainingFile();
    for (BnfExpression e : nextMap.keySet()) {
      if (!(e instanceof BnfReferenceOrToken)) continue;
      BnfRule r = containingFile.getRule(e.getText());
      if (r == null || ParserGeneratorUtil.Rule.isPrivate(r)) continue;
View Full Code Here

TOP

Related Classes of org.intellij.grammar.analysis.BnfFirstNextAnalyzer$TextStrategy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.