Пример #1
0
 def chr(self, t):
     assert t[0] == "<" or t[0] == 'U'
     if t[0] == "<":
         assert t[-1] == ">"
         if t not in ECMASCRIPT_CODE_POINTS:
             raise ValueError("unrecognized character abbreviation {!r}".format(t))
         return ECMASCRIPT_CODE_POINTS[t]
     else:
         assert t[1] == "+"
         return grammar.Literal(chr(int(t[2:], base=16)))
Пример #2
0
 def expand_lexical_rhs(self, rhs):
     body, reducer, condition = rhs
     out = []
     for e in body:
         if isinstance(e, str):
             # The terminal symbols of the lexical grammar are characters, so
             # add each character of this string as a separate element.
             out += [grammar.Literal(ch) for ch in e]
         else:
             out.append(e)
     return [out, reducer, condition]
Пример #3
0
    # 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'),
    '<SP>': grammar.Literal(' '),
    '<NBSP>': grammar.Literal('\u00a0'),
    # <ZWNBSP> already defined above
    '<USP>': grammar.UnicodeCategory('Zs'),

    # From <https://tc39.es/ecma262/#table-33>
    '<LF>': grammar.Literal('\u000a'),
    '<CR>': grammar.Literal('\u000d'),