def test_self(self): import os filename = os.path.join(os.path.dirname(parse_pgen.__file__), "..", "pgen.pgen") grammar = parse_pgen.load_grammar(filename) self.maxDiff = None pgen_grammar = parse_pgen.pgen_grammar self.assertEqual(pgen_grammar.nonterminals, grammar.nonterminals) self.assertEqual(pgen_grammar.variable_terminals, grammar.variable_terminals) self.assertEqual(pgen_grammar.goals(), grammar.goals()) with open(parse_pgen_generated.__file__) as f: pre_generated = f.read() import io out = io.StringIO() jsparagus.gen.generate_parser(out, grammar) generated_from_file = out.getvalue() self.maxDiff = None self.assertEqual(pre_generated, generated_from_file)
# prose not wrapped in square brackets # To avoid conflict with the `>` token, this is recognized only after a space. PROSE=r'(?<= )>[^\n]*', # prose wrapped in square brackets WPROSE=r'\[>[^]]*\]', # expression denoting a matched terminal or nonterminal MATCH_REF=r'\$(?:0|[1-9][0-9]*)', # the spec also gives a few productions names RUSTCOMMENT=r'//.*\n', ) ESGrammarParser = gen.compile( parse_pgen.load_grammar( os.path.join(os.path.dirname(__file__), "esgrammar.pgen"))) SIGIL_FALSE = '~' SIGIL_TRUE = '+' # Abbreviations for single-character terminals, used in the lexical grammar. ECMASCRIPT_CODE_POINTS = { # From <https://tc39.es/ecma262/#table-31> '<ZWNJ>': grammar.Literal('\u200c'), '<ZWJ>': grammar.Literal('\u200d'), '<ZWNBSP>': grammar.Literal('\ufeff'), # From <https://tc39.es/ecma262/#table-32> '<TAB>': grammar.Literal('\t'), '<VT>': grammar.Literal('\u000b'), '<FF>': grammar.Literal('\u000c'),