Skip to content

Commit 4f95334

Browse files
committed
Fix bug when no spaces after macro def
When defining a macro with no spaces like: #define macro(x)#x The zxbpp crashed. Fixed. Also updated cached parsers.
1 parent f82dddc commit 4f95334

6 files changed

Lines changed: 30 additions & 13 deletions

File tree

src/libzxbpp/zxbpp.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,14 +424,18 @@ def p_warningmsg(p):
424424
def p_define(p):
425425
""" define : DEFINE ID params defs
426426
"""
427+
id_ = p[2]
428+
params = p[3]
429+
defs = p[4]
430+
427431
if ENABLED:
428-
if p[4]:
429-
if p[4][0] in ' \t': # remove leading whitespaces
430-
p[4][0] = p[4][0].lstrip(' \t')
432+
if defs:
433+
if isinstance(defs[0], str) and defs[0] in ' \t': # remove leading whitespaces
434+
defs[0] = defs[0].lstrip(' \t')
431435
else:
432436
warning(p.lineno(1), "missing whitespace after macro name")
433437

434-
ID_TABLE.define(p[2], args=p[3], value=p[4], lineno=p.lineno(2),
438+
ID_TABLE.define(id_, args=params, value=defs, lineno=p.lineno(2),
435439
fname=output.CURRENT_FILE[-1])
436440
p[0] = []
437441

@@ -833,7 +837,7 @@ def main(argv):
833837
return global_.has_errors
834838

835839

836-
parser = yacc.yacc(debug=True)
840+
parser = src.api.utils.get_or_create('zxbpp', lambda: yacc.yacc(debug=True))
837841

838842
parser.defaulted_states = {}
839843
ID_TABLE = DefinesTable()

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, 70950)
2-
'asmparse', (71168, 254311)
3-
'zxnext_asmparse', (325632, 285299)
4-
'zxbparser', (611328, 712099)
1+
'zxbpp', (0, 72571)
2+
'asmparse', (72704, 254311)
3+
'zxnext_asmparse', (327168, 285299)
4+
'zxbparser', (612864, 712099)

src/parsetab/tabs.dbm.dat

1.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, 70950)
2-
'asmparse', (71168, 254311)
3-
'zxnext_asmparse', (325632, 285299)
4-
'zxbparser', (611328, 712099)
1+
'zxbpp', (0, 72571)
2+
'asmparse', (72704, 254311)
3+
'zxnext_asmparse', (327168, 285299)
4+
'zxbparser', (612864, 712099)

tests/functional/prepro63.bi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
3+
#define q(a)XX##a
4+
5+
q(5)
6+

tests/functional/prepro63.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#line 1 "prepro63.bi"
2+
3+
4+
5+
6+
XX5
7+

0 commit comments

Comments
 (0)