1 # cython: language_level=3, py2_import=True
3 # Cython Scanner - Lexical Definitions
7 string_prefixes = "cCuUbB"
11 from Cython.Plex import \
12 Str, Any, AnyBut, AnyChar, Rep, Rep1, Opt, Bol, Eol, Eof, \
13 TEXT, IGNORE, State, Lexicon
14 from Scanning import Method
16 letter = Any("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_")
17 digit = Any("0123456789")
19 octdigit = Any("01234567")
20 hexdigit = Any("0123456789ABCDEFabcdef")
21 indentation = Bol + Rep(Any(" \t"))
25 exponent = Any("Ee") + Opt(Any("+-")) + decimal
26 decimal_fract = (decimal + dot + Opt(decimal)) | (dot + decimal)
28 name = letter + Rep(letter | digit)
29 intconst = decimal | (Str("0") + ((Any("Xx") + Rep1(hexdigit)) |
30 (Any("Oo") + Rep1(octdigit)) |
31 (Any("Bb") + Rep1(bindigit)) ))
32 intsuffix = (Opt(Any("Uu")) + Opt(Any("Ll")) + Opt(Any("Ll"))) | (Opt(Any("Ll")) + Opt(Any("Ll")) + Opt(Any("Uu")))
33 intliteral = intconst + intsuffix
34 fltconst = (decimal_fract + Opt(exponent)) | (decimal + exponent)
35 imagconst = (intconst | fltconst) + Any("jJ")
39 Rep(AnyBut("\\\n'") | (Str("\\") + AnyChar)) +
45 Rep(AnyBut('\\\n"') | (Str("\\") + AnyChar)) +
49 non_sq = AnyBut("'") | (Str('\\') + AnyChar)
52 + Rep(non_sq | (Str("'") + non_sq) | (Str("''") + non_sq))
56 non_dq = AnyBut('"') | (Str('\\') + AnyChar)
59 + Rep(non_dq | (Str('"') + non_dq) | (Str('""') + non_dq))
63 beginstring = Opt(Any(string_prefixes)) + Opt(Any(raw_prefixes)) + (Str("'") | Str('"') | Str("'''") | Str('"""'))
64 two_oct = octdigit + octdigit
65 three_oct = octdigit + octdigit + octdigit
66 two_hex = hexdigit + hexdigit
67 four_hex = two_hex + two_hex
68 escapeseq = Str("\\") + (two_oct | three_oct |
69 Str('u') + four_hex | Str('x') + two_hex |
70 Str('U') + four_hex + four_hex | AnyChar)
76 punct = Any(":,;+-*/|&<>=.%`~^?")
77 diphthong = Str("==", "<>", "!=", "<=", ">=", "<<", ">>", "**", "//",
78 "+=", "-=", "*=", "/=", "%=", "|=", "^=", "&=",
79 "<<=", ">>=", "**=", "//=", "->")
80 spaces = Rep1(Any(" \t\f"))
81 escaped_newline = Str("\\\n")
82 lineterm = Eol + Opt(Str("\n"))
84 comment = Str("#") + Rep(AnyBut("\n"))
92 (punct | diphthong, TEXT),
94 (bra, Method('open_bracket_action')),
95 (ket, Method('close_bracket_action')),
96 (lineterm, Method('newline_action')),
98 #(stringlit, 'STRING'),
99 (beginstring, Method('begin_string_action')),
103 (escaped_newline, IGNORE),
106 (comment + lineterm, Method('commentline')),
107 (Opt(spaces) + Opt(comment) + lineterm, IGNORE),
108 (indentation, Method('indentation_action')),
109 (Eof, Method('eof_action'))
113 (escapeseq, 'ESCAPE'),
114 (Rep1(AnyBut("'\"\n\\")), 'CHARS'),
116 (Str("\n"), Method('unclosed_string_action')),
117 (Str("'"), Method('end_string_action')),
122 (escapeseq, 'ESCAPE'),
123 (Rep1(AnyBut('"\n\\')), 'CHARS'),
125 (Str("\n"), Method('unclosed_string_action')),
126 (Str('"'), Method('end_string_action')),
130 State('TSQ_STRING', [
131 (escapeseq, 'ESCAPE'),
132 (Rep1(AnyBut("'\"\n\\")), 'CHARS'),
133 (Any("'\""), 'CHARS'),
134 (Str("\n"), 'NEWLINE'),
135 (Str("'''"), Method('end_string_action')),
139 State('TDQ_STRING', [
140 (escapeseq, 'ESCAPE'),
141 (Rep1(AnyBut('"\'\n\\')), 'CHARS'),
142 (Any("'\""), 'CHARS'),
143 (Str("\n"), 'NEWLINE'),
144 (Str('"""'), Method('end_string_action')),
148 (Eof, Method('eof_action'))
151 # FIXME: Plex 1.9 needs different args here from Plex 1.1.4
152 #debug_flags = scanner_debug_flags,
153 #debug_file = scanner_dump_file