Skip to content

Commit 1807a0f

Browse files
committed
feat: allow using [arch:xxxx] in includes
Now it's possible to include files from other archs, like: #include once [arch:zx48k] <hex.bas>
1 parent 2bdc0d5 commit 1807a0f

6 files changed

Lines changed: 99 additions & 23 deletions

File tree

src/parsetab/tabs.dbm.bak

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'zxbpp', (0, 67003)
2-
'asmparse', (67072, 233956)
3-
'zxnext_asmparse', (301056, 259034)
4-
'zxbparser', (560128, 641214)
1+
'zxbpp', (0, 71563)
2+
'asmparse', (71680, 233956)
3+
'zxnext_asmparse', (305664, 259034)
4+
'zxbparser', (564736, 641214)

src/parsetab/tabs.dbm.dat

4.5 KB
Binary file not shown.

src/parsetab/tabs.dbm.dir

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'zxbpp', (0, 67003)
2-
'asmparse', (67072, 233956)
3-
'zxnext_asmparse', (301056, 259034)
4-
'zxbparser', (560128, 641214)
1+
'zxbpp', (0, 71563)
2+
'asmparse', (71680, 233956)
3+
'zxnext_asmparse', (305664, 259034)
4+
'zxbparser', (564736, 641214)

src/zxbpp/zxbasmpplex.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"OR",
4040
"STRING",
4141
"TEXT",
42+
"CO",
4243
"TOKEN",
4344
"NEWLINE",
4445
"_ENDFILE_",
@@ -48,10 +49,12 @@
4849
"EQ",
4950
"PUSH",
5051
"POP",
52+
"LB",
5153
"LP",
5254
"LLP",
5355
"RRP",
5456
"RP",
57+
"RB",
5558
"COMMA",
5659
"CONTINUE",
5760
"NUMBER",
@@ -133,6 +136,18 @@ def t_prepro_define_pragma_defargs_defargsopt_CONTINUE(self, t):
133136
t.type = "NEWLINE"
134137
return t
135138

139+
def t_prepro_LB(self, t):
140+
r"\["
141+
return t
142+
143+
def t_prepro_RB(self, t):
144+
r"\]"
145+
return t
146+
147+
def t_prepro_CO(self, t):
148+
r"\:"
149+
return t
150+
136151
# Any other character is ignored until EOL
137152
def t_singlecomment_comment_Skip(self, t):
138153
r".+"

src/zxbpp/zxbpp.py

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def search_filename(fname: str, lineno: int, local_first: bool, arch: str = "")
207207

208208
def include_file(filename: str, lineno: int, local_first: bool, arch: str = "") -> str:
209209
"""Performs a file inclusion (#include) in the preprocessor.
210-
Writes down that "filename" was included at the current file,
210+
Writes down that "filename" was included in the current file,
211211
at line <lineno>.
212212
213213
If local_first is True, then it will first search the file in the
@@ -216,7 +216,7 @@ def include_file(filename: str, lineno: int, local_first: bool, arch: str = "")
216216
"""
217217
global CURRENT_DIR
218218

219-
abs_filename = search_filename(filename, lineno, local_first)
219+
abs_filename = search_filename(filename, lineno, local_first, arch=arch)
220220
filename = utils.get_relative_filename_path(abs_filename)
221221

222222
if abs_filename not in INCLUDED:
@@ -236,7 +236,7 @@ def include_file(filename: str, lineno: int, local_first: bool, arch: str = "")
236236

237237
def include_once(filename: str, lineno: int, local_first: bool, arch: str = "") -> str:
238238
"""Performs a file inclusion (#include) in the preprocessor.
239-
Writes down that "filename" was included at the current file,
239+
Writes down that "filename" was included in the current file,
240240
at line <lineno>.
241241
242242
The file is ignored if it was previously included (a warning will
@@ -246,7 +246,7 @@ def include_once(filename: str, lineno: int, local_first: bool, arch: str = "")
246246
local path before looking for it in the include path chain.
247247
This is used when doing a #include "filename".
248248
"""
249-
abs_filename = search_filename(filename, lineno, local_first)
249+
abs_filename = search_filename(filename, lineno, local_first, arch=arch)
250250

251251
if abs_filename not in INCLUDED: # If not already included
252252
return include_file(filename, lineno, local_first, arch) # include it and return
@@ -395,34 +395,55 @@ def p_include_once_ok(p):
395395

396396

397397
def p_include_fname(p):
398-
"""include : INCLUDE FILENAME"""
398+
"""include : INCLUDE include_modifier FILENAME"""
399+
modifier = p[2]
400+
if modifier is None:
401+
p[0] = []
402+
return
403+
404+
filename = p[3]
399405
if ENABLED:
400-
p[0] = include_file(p[2], p.lineno(2), local_first=False)
406+
arch = modifier.get("arch", "")
407+
p[0] = include_file(filename, p.lineno(3), local_first=False, arch=arch)
401408
else:
402409
p[0] = []
403410
p.lexer.next_token = "_ENDFILE_"
404411

405412

406413
def p_include_macro(p):
407-
"""include : INCLUDE expr"""
408-
global_fist = RE_GLOBAL_FIRST_FILENAME.match(p[2])
409-
local_first = RE_LOCAL_FIRST_FILENAME.match(p[2])
414+
"""include : INCLUDE include_modifier expr"""
415+
modifier = p[2]
416+
if modifier is None:
417+
p[0] = []
418+
return
419+
420+
expr = p[3]
421+
global_fist = RE_GLOBAL_FIRST_FILENAME.match(expr)
422+
local_first = RE_LOCAL_FIRST_FILENAME.match(expr)
410423
if global_fist is None and local_first is None:
411-
error(p.lineno(1), f"invalid filename {p[2]}")
424+
error(p.lineno(1), f"invalid filename {expr}")
412425
p[0] = []
413426
return
414427

415428
if ENABLED:
416-
p[0] = include_file(p[2][1:-1], p.lineno(2), local_first=local_first is not None)
429+
arch = modifier.get("arch", "")
430+
p[0] = include_file(expr[1:-1], p.lineno(3), local_first=local_first is not None, arch=arch)
417431
else:
418432
p[0] = []
419433
p.lexer.next_token = "_ENDFILE_"
420434

421435

422436
def p_include_once(p):
423-
"""include_once : INCLUDE ONCE STRING"""
437+
"""include_once : INCLUDE ONCE include_modifier STRING"""
438+
modifier = p[3]
439+
if modifier is None:
440+
p[0] = []
441+
return
442+
443+
string = p[4]
424444
if ENABLED:
425-
p[0] = include_once(p[3][1:-1], p.lineno(3), local_first=True)
445+
arch = modifier.get("arch", "")
446+
p[0] = include_once(string[1:-1], p.lineno(4), local_first=True, arch=arch)
426447
else:
427448
p[0] = []
428449

@@ -431,18 +452,43 @@ def p_include_once(p):
431452

432453

433454
def p_include_once_fname(p):
434-
"""include_once : INCLUDE ONCE FILENAME"""
455+
"""include_once : INCLUDE ONCE include_modifier FILENAME"""
435456
p[0] = []
457+
modifier = p[3]
458+
if modifier is None:
459+
return
436460

461+
filename = p[4]
437462
if ENABLED:
438-
p[0] = include_once(p[3], p.lineno(3), local_first=False)
463+
arch = modifier.get("arch", "")
464+
p[0] = include_once(filename, p.lineno(4), local_first=False, arch=arch)
439465
else:
440466
p[0] = []
441467

442468
if not p[0]:
443469
p.lexer.next_token = "_ENDFILE_"
444470

445471

472+
def p_include_modifier(p):
473+
"""include_modifier :
474+
| LB ID CO ID RB
475+
"""
476+
if len(p) == 1:
477+
p[0] = {}
478+
return
479+
480+
modifier = p[2]
481+
value = p[4]
482+
483+
if modifier == "arch":
484+
p[0] = {"arch": value}
485+
else:
486+
p[0] = None
487+
error(p.lineno(1), f"unknown modifier {modifier}")
488+
489+
return
490+
491+
446492
def p_line(p):
447493
"""line : LINE INTEGER NEWLINE"""
448494
if ENABLED:

src/zxbpp/zxbpplex.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"OR",
3737
"STRING",
3838
"TEXT",
39+
"CO",
3940
"TOKEN",
4041
"NEWLINE",
4142
"_ENDFILE_",
@@ -45,10 +46,12 @@
4546
"EQ",
4647
"PUSH",
4748
"POP",
49+
"LB",
4850
"LP",
4951
"LLP",
5052
"RRP",
5153
"RP",
54+
"RB",
5255
"COMMA",
5356
"CONTINUE",
5457
"NUMBER",
@@ -151,6 +154,18 @@ def t_prepro_define_pragma_defargs_defargsopt_CONTINUE(self, t):
151154
t.lexer.lineno += 1
152155
return t
153156

157+
def t_prepro_LB(self, t):
158+
r"\["
159+
return t
160+
161+
def t_prepro_RB(self, t):
162+
r"\]"
163+
return t
164+
165+
def t_prepro_CO(self, t):
166+
r"\:"
167+
return t
168+
154169
def t_INITIAL_comment_beginBlock(self, t):
155170
r"/'"
156171
self.__COMMENT_LEVEL += 1

0 commit comments

Comments
 (0)