Skip to content

Commit e2d377e

Browse files
committed
Simplify ZXBPP
Also allows #line detection within asm blocks
1 parent 30aef4f commit e2d377e

1 file changed

Lines changed: 10 additions & 18 deletions

File tree

src/libzxbpp/zxbpplex.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
# This is the Lexer for the ZXBpp (ZXBasic Preprocessor)
1111
# ----------------------------------------------------------------------
1212

13+
import re
1314
import sys
15+
1416
from src.ply import lex
17+
from src.api import global_
1518
from src.libzxbpp.base_pplex import BaseLexer
1619

1720

@@ -102,24 +105,13 @@ def t_asm_CONTINUE(self, t):
102105
return t
103106

104107
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';.*'
110109

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
123115

124116
def t_asm_ID(self, t):
125117
r'[_A-Za-z][_A-Za-z0-9]*'
@@ -149,7 +141,7 @@ def t_prepro_define_defargs_defargsopt_defexpr_pragma_if_NEWLINE(self, t):
149141
t.lexer.pop_state()
150142
return t
151143

152-
def t_INITIAL_NEWLINE(self, t):
144+
def t_INITIAL_asm_NEWLINE(self, t):
153145
r'\r?\n'
154146
t.lexer.lineno += 1
155147
return t

0 commit comments

Comments
 (0)