static Object addSpacing(Object value, LexerlessGrammarBuilder b) { return b.sequence(value, WHITESPACES); }
private static Object punctuator(String value, LexerlessGrammarBuilder b) { return b.sequence(value, spacing); }
private static Object character(LexerlessGrammarBuilder b, String value) { return b.sequence(SPACING, value); }
private static Object keyword(String value, LexerlessGrammarBuilder b) { return b.sequence(value, b.nextNot(letterOrDigit), spacing); }
private static Object word(LexerlessGrammarBuilder b, String word) { return b.sequence(SPACING, word, b.nextNot(IDENTIFIER_PART)); }
private static Object stringLiteral(LexerlessGrammarBuilder b) { return b.sequence(b.next("\""), b.regexp("\"([^\"\\\\]*+(\\\\[\\s\\S])?+)*+\"")); }
private static Object characterLiteral(LexerlessGrammarBuilder b) { return b.sequence(b.next("'"), b.regexp("'([^'\\\\]*+(\\\\[\\s\\S])?+)*+'")); }
private static Object characterLiteral(LexerlessGrammarBuilder b) { return b.sequence(b.next("'"), b.regexp("'([^'\\\\]*+(\\\\[\\s\\S])?+)*+'")); }
private static Object stringLiteral(LexerlessGrammarBuilder b) { return b.sequence(b.next("\""), b.regexp("\"([^\"\\\\]*+(\\\\[\\s\\S])?+)*+\"")); }
private static Object characterLiteral(LexerlessGrammarBuilder b) { return b.sequence(b.next("'"), b.regexp("'([^'\\\\]*+(\\\\[\\s\\S])?+)*+'")); }
private static Object characterLiteral(LexerlessGrammarBuilder b) { return b.sequence(b.next("'"), b.regexp("'([^'\\\\]*+(\\\\[\\s\\S])?+)*+'")); }
private static Object stringLiteral(LexerlessGrammarBuilder b) { return b.sequence(b.next("\""), b.regexp("\"([^\"\\\\]*+(\\\\[\\s\\S])?+)*+\"")); }
private static Object stringLiteral(LexerlessGrammarBuilder b) { return b.sequence(b.next("\""), b.regexp("\"([^\"\\\\]*+(\\\\[\\s\\S])?+)*+\"")); }
private static Object word(LexerlessGrammarBuilder b, String word) { return b.sequence(SPACING, b.regexp("(?i)" + word), b.nextNot(b.regexp(LexicalConstant.IDENTIFIER_PART))); }
private static Object word(LexerlessGrammarBuilder b, String word) { return b.sequence(SPACING, b.regexp("(?i)" + word), b.nextNot(b.regexp(LexicalConstant.IDENTIFIER_PART))); }
public static Grammar requiresPositiveMemoizationOnMoreThanJustLastRule() { LexerlessGrammarBuilder b = LexerlessGrammarBuilder.create(); b.rule(A).is( b.firstOf( b.sequence(b.optional(B), 'a'), // rule 'C' will match and override the memoization result of 'B': b.sequence(C, '!'), b.sequence(b.optional(B), 'b'))); b.rule(B).is('(', A, ')'); // rule 'C' will override each following memoization result of 'A': b.rule(C).is('(', b.optional(C)); return b.build(); }
/** * To eliminate indirect left recursion - transform to immediate left recursion, then factor out non recursive alternatives. */ public static Grammar eliminatedIndirectLeftRecursion() { LexerlessGrammarBuilder b = LexerlessGrammarBuilder.create(); b.rule(A).is(b.firstOf(b.sequence(S2, T1), S1), b.zeroOrMore(T2, T1)); otherRules(b); return b.build(); }