def la_not_in_set(self, lookahead_exclusions): if all(len(excl) == 1 for excl in lookahead_exclusions): return grammar.LookaheadRule( OrderedFrozenSet(excl[0] for excl in lookahead_exclusions), False) raise ValueError("unsupported: lookahead > 1 token, {!r}".format( lookahead_exclusions))
def la_not_in_set(self, notin, ob, lookahead_exclusions, cb): assert (notin, ob, cb) == ("<!", '{', '}') if all(len(excl) == 1 for excl in lookahead_exclusions): return grammar.LookaheadRule( OrderedFrozenSet(excl[0] for excl in lookahead_exclusions), False) raise ValueError("unsupported: lookahead > 1 token, {!r}".format( lookahead_exclusions))
""" Functions for loading the ECMAScript lexical and syntactic grammars. """ from jsparagus.ordered import OrderedSet, OrderedFrozenSet from jsparagus import gen from .lexer import ECMASCRIPT_FULL_KEYWORDS, ECMASCRIPT_CONDITIONAL_KEYWORDS from .parse_esgrammar import parse_esgrammar ECMASCRIPT_LEXICAL_SYNTHETIC_TERMINALS = { # Theoretically, this should be the set of all Unicode characters, but that # would take a lot of memory, and in practice, the set is not used. 'SourceCharacter': OrderedFrozenSet([]), } ECMASCRIPT_LEXICAL_GOAL_NTS = [ 'WhiteSpace', 'InputElementDiv', 'InputElementRegExp', ] def load_lexical_grammar(filename): """Load the ECMAScript lexical grammar.""" with open(filename) as f: grammar_text = f.read() g = parse_esgrammar( grammar_text, filename=filename, goals=ECMASCRIPT_LEXICAL_GOAL_NTS, synthetic_terminals=ECMASCRIPT_LEXICAL_SYNTHETIC_TERMINALS, terminal_names=ECMASCRIPT_LEXICAL_SYNTHETIC_TERMINALS.keys()) return gen.expand_parameterized_nonterminals(g)
def la_not_in_nonterminal(self, nt): return grammar.LookaheadRule(OrderedFrozenSet([nt]), False)
def la_ne(self, t): return grammar.LookaheadRule(OrderedFrozenSet([t]), False)
def la_eq(self, t): return grammar.LookaheadRule(OrderedFrozenSet([t]), True)
def la_ne(self, ne, t): assert ne == "!=" return grammar.LookaheadRule(OrderedFrozenSet([t]), False)
def la_eq(self, eq, t): assert eq == "==" return grammar.LookaheadRule(OrderedFrozenSet([t]), True)