Пример #1
0
 def scan_word(self, yy: Scanner):
     text = yy.matched_text().lower(
     )  # By this the language is made caseless.
     if text in self.RESERVED_WORDS:
         if text in self.MONTHS: yy.token('month', self.MONTHS[text])
         else:
             yy.token(
                 text, yy.current_span()
             )  # Sometimes the location of a keyword is used for error reporting.
     else:
         yy.token("id", Name(text, yy.current_span()))
Пример #2
0
 def scan_letter_escape(self, yy: Scanner):
     letter = yy.matched_text()[1]
     codepoint = 7 + 'abtnvfr'.index(letter)
     yy.token('TEXT', AST.Constant(chr(codepoint), yy.current_span(),
                                   'TEXT'))
Пример #3
0
 def scan_imaginary(self, yy: interfaces.Scanner):
     yy.token('number', float(yy.matched_text()[:-1]) * 1j)
Пример #4
0
 def scan_punctuation(self, yy: interfaces.Scanner):
     yy.token(yy.matched_text())
Пример #5
0
 def scan_unicode_escape(self, yy: interfaces.Scanner):
     yy.token('character', chr(int(yy.matched_text()[2:], 16)))
Пример #6
0
 def scan_escaped_literal(self, yy: interfaces.Scanner):
     yy.token('character', yy.matched_text()[1])
Пример #7
0
 def scan_enter_string(self, yy: interfaces.Scanner):
     yy.enter('in_string')
     yy.token(yy.matched_text())
Пример #8
0
 def scan_integer(self, yy: interfaces.Scanner):
     yy.token('number', int(yy.matched_text()))
Пример #9
0
 def scan_hex_integer(self, yy: Scanner):
     yy.token(
         'INTEGER',
         AST.Constant(int(yy.matched_text()[1:], 16), yy.current_span(),
                      'HEX'))
Пример #10
0
 def scan_integer(self, yy: Scanner):
     yy.token(
         'INTEGER',
         AST.Constant(int(yy.matched_text()), yy.current_span(), 'INT'))
Пример #11
0
 def scan_sigil(self, yy: Scanner, kind: str):
     # Like scan_string but removes the first char from the semantic value.
     name = AST.Name(yy.matched_text()[1:], yy.current_span())
     yy.token(kind, AST.Sigil(name, kind))
Пример #12
0
 def scan_escape_literal(self, yy: Scanner):
     yy.token(
         'TEXT',
         AST.Constant(yy.matched_text()[1:], yy.current_span(), 'TEXT'))
Пример #13
0
 def scan_string(self, yy: Scanner, kind):
     # Pick up the token as a constant of string type, not an identifier.
     # Like a bareword in ancient perl?
     yy.token(kind, AST.Constant(yy.matched_text(), yy.current_span(),
                                 kind))
Пример #14
0
 def scan_name(self, yy: Scanner, kind):
     # sort of like an identifier: We need to capture the span in case of semantic error.
     yy.token(kind, AST.Name(yy.matched_text(), yy.current_span()))
Пример #15
0
 def scan_token(self, yy: Scanner, kind):
     # Concrete tokens that won't contribute to the AST
     yy.token(kind, yy.matched_text())
Пример #16
0
 def scan_decimal(self, yy: Scanner):
     yy.token(
         'DECIMAL',
         AST.Constant(float(yy.matched_text()), yy.current_span(), 'DEC'))
Пример #17
0
def match_integer(yy: Scanner):
    # It's sort of assumed you'll be connecting a mini-scanner up to a mini-parser.
    # The parser module expects to get (token, value, start, end) quads, but the
    # scanner handles the start and end. You just call the `.token(...)` method
    # on the parameter, which is a scanning context.
    yy.token('number', int(yy.matched_text()))
Пример #18
0
 def scan_delimited(self, yy: Scanner, kind):
     yy.token(
         kind,
         AST.Constant(yy.matched_text()[1:-1], yy.current_span(), 'STRING'))
Пример #19
0
 def scan_reserved_word(self, yy: interfaces.Scanner):
     yy.token(yy.matched_text(), self.RESERVED[yy.matched_text()])
Пример #20
0
 def scan_integer(self, yy: Scanner):
     yy.token('integer', int(yy.matched_text()))
Пример #21
0
 def scan_stringy_bit(self, yy: interfaces.Scanner):
     yy.token('character', yy.matched_text())
Пример #22
0
 def scan_real(self, yy: Scanner):
     yy.token('real', float(yy.matched_text()))
Пример #23
0
 def scan_shorthand_escape(self, yy: interfaces.Scanner):
     yy.token('character', chr(self.ESCAPES[yy.matched_text()[1]]))
Пример #24
0
 def scan_punctuation(self, yy: Scanner):
     yy.token(yy.matched_text(), yy.current_span())
Пример #25
0
 def scan_leave_string(self, yy: interfaces.Scanner):
     yy.enter('INITIAL')
     yy.token(yy.matched_text())
Пример #26
0
 def scan_sigil(self, yy: Scanner, kind: str):
     text = yy.matched_text()[1:].lower()
     yy.token(kind, Name(text, yy.current_span()))
Пример #27
0
 def scan_real(self, yy: interfaces.Scanner):
     yy.token('number', float(yy.matched_text()))
Пример #28
0
 def scan_string(self, yy: Scanner):
     yy.token('string', yy.matched_text()[1:-1])
Пример #29
0
 def scan_variable(self, yy: interfaces.Scanner):
     yy.token('variable', yy.matched_text())
Пример #30
0
 def scan_punctuation(self, yy: Scanner):
     it = yy.matched_text()
     yy.token(it, it)