|
10 | 10 | # This is the Lexer for the ZXBpp (ZXBasic Preprocessor) |
11 | 11 | # ---------------------------------------------------------------------- |
12 | 12 |
|
| 13 | +import re |
13 | 14 | import sys |
| 15 | + |
14 | 16 | from src.ply import lex |
| 17 | +from src.api import global_ |
15 | 18 | from src.libzxbpp.base_pplex import BaseLexer |
16 | 19 |
|
17 | 20 |
|
@@ -102,24 +105,13 @@ def t_asm_CONTINUE(self, t): |
102 | 105 | return t |
103 | 106 |
|
104 | 107 | def t_asm_COMMENT(self, t): |
105 | | - r';' |
106 | | - t.lexer.push_state('asmcomment') |
107 | | - |
108 | | - def t_asmcomment_skip(self, t): |
109 | | - r'.' |
| 108 | + r';.*' |
110 | 109 |
|
111 | | - def t_asmcomment_NEWLINE(self, t): |
112 | | - r'\r?\n' |
113 | | - # New line => remove whatever state in top of the stack and replace it with INITIAL |
114 | | - t.lexer.lineno += 1 |
115 | | - t.lexer.pop_state() |
116 | | - return t |
117 | | - |
118 | | - def t_asm_NEWLINE(self, t): |
119 | | - r'\r?\n' |
120 | | - # New line => remove whatever state in top of the stack and replace it with INITIAL |
121 | | - t.lexer.lineno += 1 |
122 | | - return t |
| 110 | + def t_asm_PREPROCLINE(self, t): |
| 111 | + r'\#[ \t]*[Ll][Ii][Nn][Ee][ \t]+([0-9]+)(?:[ \t]+"((?:[^"]|"")*)")?[ \t]*\r?\n' |
| 112 | + match = re.match('#[ \t]*[Ll][Ii][Nn][Ee][ \t]+([0-9]+)(?:[ \t]+"((?:[^"]|"")*)")?[ \t]*\r?\n', t.value) |
| 113 | + t.lexer.lineno = int(match.groups()[0]) |
| 114 | + global_.FILENAME = match.groups()[1] or global_.FILENAME |
123 | 115 |
|
124 | 116 | def t_asm_ID(self, t): |
125 | 117 | r'[_A-Za-z][_A-Za-z0-9]*' |
@@ -149,7 +141,7 @@ def t_prepro_define_defargs_defargsopt_defexpr_pragma_if_NEWLINE(self, t): |
149 | 141 | t.lexer.pop_state() |
150 | 142 | return t |
151 | 143 |
|
152 | | - def t_INITIAL_NEWLINE(self, t): |
| 144 | + def t_INITIAL_asm_NEWLINE(self, t): |
153 | 145 | r'\r?\n' |
154 | 146 | t.lexer.lineno += 1 |
155 | 147 | return t |
|
0 commit comments