Пример #1
0
 private List<Expr> prefixedConstants(List<String> tokens) {
   return tokens
       .stream()
       .filter(t -> t != null)
       .map(t -> prefixedConstant(t))
       .collect(Collectors.toList());
 }
Пример #2
0
 private GExpansion traverseUniqueChildSequences(GExpansion expansion) {
   main:
   while (expansion.kind == GExpansion.Kind.Sequence) {
     GExpansion child = null;
     List<GExpansion> children = expansion.children;
     for (int i = 0; i < children.size(); i++) {
       GExpansion otherChild = children.get(i);
       if ((otherChild.kind != GExpansion.Kind.LookAhead || otherChild.semanticLookahead == null)
           && otherChild.kind != GExpansion.Kind.Action) {
         if (child == null) child = otherChild;
         else break main;
       }
     }
     expansion = child;
   }
   return expansion;
 }
Пример #3
0
  private void createMatchMethod(
      String symbol,
      String namePrefix,
      GExpansion expansion,
      NodeList<Stmt> stmts,
      NodeList<FormalParameter> params) {
    if (STATISTICS) {
      stmts =
          listOf(
              stmt("historize(\"In " + namePrefix + "\");").build(),
              tryStmt(blockStmt().withStmts(stmts))
                  .withFinallyBlock(
                      blockStmt()
                          .withStmts(
                              listOf(stmt("historize(\"Out " + namePrefix + "\");").build()))));
    }

    List<MethodDecl> methods = perSymbolMatchMethods.get(symbol);
    if (methods == null) {
      methods = new ArrayList<>();
      perSymbolMatchMethods.put(symbol, methods);
    }
    methods.add(matchMethod(namePrefix, stmts, expansion, params));
  }
Пример #4
0
  @Override
  protected ClassDecl contributeBody(
      ClassDecl decl, ImportManager importManager, TreeClassDescriptor[] arg) {
    importManager.addImports(
        listOf(
            importDecl(qualifiedName("org.jlato.internal.bu")).setOnDemand(true),
            importDecl(qualifiedName("org.jlato.internal.bu.coll")).setOnDemand(true),
            importDecl(qualifiedName("org.jlato.internal.bu.decl")).setOnDemand(true),
            importDecl(qualifiedName("org.jlato.internal.bu.expr")).setOnDemand(true),
            importDecl(qualifiedName("org.jlato.internal.bu.name")).setOnDemand(true),
            importDecl(qualifiedName("org.jlato.internal.bu.stmt")).setOnDemand(true),
            importDecl(qualifiedName("org.jlato.internal.bu.type")).setOnDemand(true),
            importDecl(qualifiedName("org.jlato.internal.parser.Token")),
            importDecl(qualifiedName("org.jlato.internal.parser.TokenType")),
            importDecl(qualifiedName("org.jlato.tree.Problem.Severity")),
            importDecl(qualifiedName("org.jlato.parser.ParseException")),
            importDecl(qualifiedName("org.jlato.tree.expr.AssignOp")),
            importDecl(qualifiedName("org.jlato.tree.expr.BinaryOp")),
            importDecl(qualifiedName("org.jlato.tree.expr.UnaryOp")),
            importDecl(qualifiedName("org.jlato.tree.decl.ModifierKeyword")),
            importDecl(qualifiedName("org.jlato.tree.type.Primitive"))));

    List<GProduction> allProductions = productions.getAll();

    int memoizedProductionCount = MEMOIZE_ALL_MATCHES ? allProductions.size() : 0;
    if (!MEMOIZE_ALL_MATCHES) {
      for (GProduction production : allProductions) {
        if (production.memoizeMatches) memoizedProductionCount++;
      }
    }

    NodeList<MemberDecl> members = Trees.emptyList();
    members =
        members.append(
            memberDecl(
                    "protected int memoizedProductionCount() { return "
                        + memoizedProductionCount
                        + "; }")
                .build());

    for (GProduction production : allProductions) {
      if (excluded(production)) continue;

      parseMethods = parseMethods.append(parseMethod(importManager, production));
    }

    for (MethodDecl parseMethod : parseMethods) {
      members = members.append(parseMethod);

      String id = parseMethod.name().id();
      int indexOfUnderscore = id.indexOf('_');
      String symbol =
          id.substring("parse".length(), indexOfUnderscore == -1 ? id.length() : indexOfUnderscore);

      List<MethodDecl> methods = perSymbolMatchMethods.get(symbol);
      if (methods != null) {
        Collections.sort(methods, (m1, m2) -> m1.name().id().compareTo(m2.name().id()));
        members = members.appendAll(listOf(methods));
      }
    }

    return decl.withMembers(members);
  }