public Builder addRule(Rule rule) { List<Rule> rules = definitions.get(rule.getHead()); if (rules == null) { rules = new ArrayList<>(); definitions.put(rule.getHead(), rules); } rules.add(rule); this.rules.add(rule); return this; }
public Start getStartSymbol(Nonterminal nt) { Start start = Start.from(nt); if (definitions.keySet().contains(start)) return start; Rule startRule; if (layout != null) startRule = Rule.withHead(start) .setLabel("Start") .addSymbol(layout) .addSymbol(nt) .addSymbol(layout) .setRecursion(Recursion.NON_REC) .setAssociativity(Associativity.UNDEFINED) .setPrecedence(-1) .setPrecedenceLevel(PrecedenceLevel.getFirstAndDone()) .build(); else startRule = Rule.withHead(start) .addSymbol(nt) .setRecursion(Recursion.NON_REC) .setAssociativity(Associativity.UNDEFINED) .setPrecedence(-1) .setPrecedenceLevel(PrecedenceLevel.getFirstAndDone()) .build(); definitions.put(start, CollectionsUtil.list(startRule)); rules.add(startRule); return start; }
private static Set<RuntimeException> validate( List<Rule> rules, Map<Nonterminal, List<Rule>> definitions) { return rules .stream() .filter(r -> r.getBody() != null) .<RuntimeException>flatMap( r -> r.getBody() .stream() .filter(s -> !definitions.containsKey(s)) .filter(s -> s instanceof Nonterminal) .map(s -> new NonterminalNotDefinedException((Nonterminal) s))) .collect(Collectors.toSet()); }
public Builder addExceptPatterns(Collection<ExceptPattern> patterns) { exceptPatterns.addAll(patterns); return this; }
public Builder addExceptPattern(ExceptPattern pattern) { exceptPatterns.add(pattern); return this; }
public Builder addPrecedencePatterns(Collection<PrecedencePattern> patterns) { precedencePatterns.addAll(patterns); return this; }
public Builder addPrecedencePattern(PrecedencePattern pattern) { precedencePatterns.add(pattern); return this; }