@Test public void plusPart() { Grammar g = new Grammar(); Terminal id = g.newTerminal("id"); Terminal error = g.newTerminal("error"); g.newRule(g.getStart(), plus(id)); LRParser parser = new LRParser(new SLRTableGenerator(g).generateTable()); assertFalse(parser.parse(error)); assertFalse(parser.parse(new Terminal[0])); assertEquals("[id, id, id]", "" + parser.parse(asLexemes(id, id, id))); }
public static NonTerminal plus(Symbol symbol) { Grammar g = symbol.getGrammar(); NonTerminal plus = g.newNonTerminal(g.uniqueName("plus_")); g.newRule(plus, symbol, star(symbol)).setHandler(new RuleHandler() { @Override public Object handle(RuleContext ctx) { Object head = ctx.get(0); PersistentList list = (PersistentList) ctx.get(1); return PersistentList.cons(head, list); } }); return plus; }
GrammarSugar { public static NonTerminal plus(Symbol symbol) { Grammar g = symbol.getGrammar(); NonTerminal plus = g.newNonTerminal(g.uniqueName("plus_")); g.newRule(plus, symbol, star(symbol)).setHandler(new RuleHandler() { @Override public Object handle(RuleContext ctx) { Object head = ctx.get(0); PersistentList list = (PersistentList) ctx.get(1); return PersistentList.cons(head, list); } }); return plus; } }
GrammarSugar { public static NonTerminal plus(Symbol symbol) { Grammar g = symbol.getGrammar(); NonTerminal plus = g.newNonTerminal(g.uniqueName("plus_")); g.newRule(plus, symbol, star(symbol)).setHandler(new RuleHandler() { @Override public Object handle(RuleContext ctx) { Object head = ctx.get(0); PersistentList list = (PersistentList) ctx.get(1); return PersistentList.cons(head, list); } }); return plus; }  }
GrammarSugar { public static NonTerminal plus(Symbol symbol) { Grammar g = symbol.getGrammar(); NonTerminal plus = g.newNonTerminal(g.uniqueName("plus_")); g.newRule(plus, symbol, star(symbol)).setHandler(new RuleHandler() { @Override public Object handle(RuleContext ctx) { Object head = ctx.get(0); PersistentList list = (PersistentList) ctx.get(1); return PersistentList.cons(head, list); } }); return plus; }  static NonTerminal seq(Symbol... symbols); static NonTerminal optional(Symbol symbol); static NonTerminal plus(Symbol symbol); static NonTerminal star(Symbol symbol); static NonTerminal star(Symbol symbol, StarRulesUpdater updater); static NonTerminal oneOf(Symbol first, Symbol... symbols); static NonTerminal oneOf(OneOfRuleUpdater updater, Symbol first, Symbol... symbols); static NonTerminal separated(Symbol item, Symbol separator); static NonTerminal separated(Symbol item, Symbol separator, boolean atLeastOne); static NonTerminal terminated(Symbol item, Symbol separator); static NonTerminal terminated(Symbol item, Symbol separator, boolean trailingOptional); static NonTerminal terminated(Symbol item, Symbol separator, boolean trailingOptional, boolean emptyStart); static NonTerminal terminated(Symbol item, Symbol separator, Symbol terminator, boolean trailingOptional, boolean emptyStart); }
GrammarSugar { public static NonTerminal plus(Symbol symbol) { Grammar g = symbol.getGrammar(); NonTerminal plus = g.newNonTerminal(g.uniqueName("plus_")); g.newRule(plus, symbol, star(symbol)).setHandler(new RuleHandler() { @Override public Object handle(RuleContext ctx) { Object head = ctx.get(0); PersistentList list = (PersistentList) ctx.get(1); return PersistentList.cons(head, list); } }); return plus; }  static NonTerminal seq(Symbol... symbols); static NonTerminal optional(Symbol symbol); static NonTerminal plus(Symbol symbol); static NonTerminal star(Symbol symbol); static NonTerminal star(Symbol symbol, StarRulesUpdater updater); static NonTerminal oneOf(Symbol first, Symbol... symbols); static NonTerminal oneOf(OneOfRuleUpdater updater, Symbol first, Symbol... symbols); static NonTerminal separated(Symbol item, Symbol separator); static NonTerminal separated(Symbol item, Symbol separator, boolean atLeastOne); static NonTerminal terminated(Symbol item, Symbol separator); static NonTerminal terminated(Symbol item, Symbol separator, boolean trailingOptional); static NonTerminal terminated(Symbol item, Symbol separator, boolean trailingOptional, boolean emptyStart); static NonTerminal terminated(Symbol item, Symbol separator, Symbol terminator, boolean trailingOptional, boolean emptyStart);  }