Ejemplo n.º 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()))
Ejemplo n.º 2
0
 def scan_sigil(self, yy: Scanner, kind: str):
     text = yy.matched_text()[1:].lower()
     yy.token(kind, Name(text, yy.current_span()))
Ejemplo n.º 3
0
 def scan_delimited(self, yy: Scanner, kind):
     yy.token(
         kind,
         AST.Constant(yy.matched_text()[1:-1], yy.current_span(), 'STRING'))
Ejemplo n.º 4
0
 def scan_punctuation(self, yy: Scanner):
     yy.token(yy.matched_text(), yy.current_span())
Ejemplo n.º 5
0
 def scan_hex_integer(self, yy: Scanner):
     yy.token(
         'INTEGER',
         AST.Constant(int(yy.matched_text()[1:], 16), yy.current_span(),
                      'HEX'))
Ejemplo n.º 6
0
 def scan_decimal(self, yy: Scanner):
     yy.token(
         'DECIMAL',
         AST.Constant(float(yy.matched_text()), yy.current_span(), 'DEC'))
Ejemplo n.º 7
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))
Ejemplo n.º 8
0
 def scan_integer(self, yy: Scanner):
     yy.token(
         'INTEGER',
         AST.Constant(int(yy.matched_text()), yy.current_span(), 'INT'))
Ejemplo n.º 9
0
 def scan_escape_literal(self, yy: Scanner):
     yy.token(
         'TEXT',
         AST.Constant(yy.matched_text()[1:], yy.current_span(), 'TEXT'))
Ejemplo n.º 10
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))
Ejemplo n.º 11
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()))
Ejemplo n.º 12
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'))
Ejemplo n.º 13
0
 def scan_embedded_newline(self, yy: Scanner):
     yy.token('TEXT', AST.Constant('\n', yy.current_span(), 'TEXT'))