Skip to content

Commit 14fa218

Browse files
committed
fix: fix error line number in macros in ASM
1 parent 47d5624 commit 14fa218

8 files changed

Lines changed: 41 additions & 20 deletions

File tree

src/parsetab/tabs.dbm.bak

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
'zxbpp', (0, 76970)
2-
'asmparse', (77312, 272467)
3-
'zxnext_asmparse', (350208, 303081)
4-
'zxbparser', (653312, 703160)
2+
'asmparse', (77312, 268394)
3+
'zxnext_asmparse', (346112, 298411)
4+
'zxbparser', (644608, 703160)

src/parsetab/tabs.dbm.dat

-8.5 KB
Binary file not shown.

src/parsetab/tabs.dbm.dir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
'zxbpp', (0, 76970)
2-
'asmparse', (77312, 272467)
3-
'zxnext_asmparse', (350208, 303081)
4-
'zxbparser', (653312, 703160)
2+
'asmparse', (77312, 268394)
3+
'zxnext_asmparse', (346112, 298411)
4+
'zxbparser', (644608, 703160)

src/zxbasm/asmlex.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from src.api.config import OPTIONS
1919
from src.api.errmsg import error
2020

21+
from src.api import global_
22+
2123

2224
_tokens: Tuple[str, ...] = (
2325
"STRING",
@@ -192,7 +194,7 @@
192194
"m": "M",
193195
}
194196

195-
preprocessor = {"init": "_INIT", "line": "_LINE"}
197+
preprocessor = {"init": "_INIT"}
196198

197199
# List of token names.
198200
_tokens = tuple(
@@ -336,6 +338,14 @@ def t_INITIAL_ID(self, t):
336338

337339
return t
338340

341+
def t_asm_PREPROCLINE(self, t):
342+
r'\#[ \t]*[Ll][Ii][Nn][Ee][ \t]+([0-9]+)(?:[ \t]+"((?:[^"]|"")*)")?[ \t]*\r?\n'
343+
import re
344+
345+
match = re.match('#[ \t]*[Ll][Ii][Nn][Ee][ \t]+([0-9]+)(?:[ \t]+"((?:[^"]|"")*)")?[ \t]*\r?\n', t.value)
346+
global_.FILENAME = match.groups()[1] or global_.FILENAME
347+
self.lineno = int(match.groups()[0])
348+
339349
def t_preproc_ID(self, t):
340350
r"[_a-zA-Z][_a-zA-Z0-9]*" # preprocessor directives
341351
t.type = preprocessor.get(t.value.lower(), "ID")

src/zxbasm/asmparse.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -926,17 +926,6 @@ def p_preprocessor_line(p):
926926
p[0] = None
927927

928928

929-
def p_preprocessor_line_line(p):
930-
"""preproc_line : _LINE INTEGER"""
931-
p.lexer.lineno = int(p[2]) + p.lexer.lineno - p.lineno(2)
932-
933-
934-
def p_preprocessor_line_line_file(p):
935-
"""preproc_line : _LINE INTEGER STRING"""
936-
p.lexer.lineno = int(p[2]) + p.lexer.lineno - p.lineno(3) - 1
937-
gl.FILENAME = p[3]
938-
939-
940929
def p_preproc_line_init(p):
941930
"""preproc_line : _INIT STRING"""
942931
INITS.append(Container(p[2].strip('"'), p.lineno(2)))

tests/functional/test_errmsg.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,10 @@ line_number_after_macro.bas:11: error: Syntax Error. Unexpected token '+' <PLUS>
225225
>>> process_file('zx48k/tap_asm_error_line.bas', ['-S', '-q'])
226226
tap_asm_error_line.bas:3: error: Syntax error. Unexpected token '10' [INTEGER]
227227
tap_asm_error_line.bas:7: error: Syntax error. Unexpected token '10' [INTEGER]
228-
>>> process_file('zx48k/tap_errline.bas')
229-
tap_errline.bas:10: error: Syntax error. Unexpected token 'HL' [HL]
228+
>>> process_file('zx48k/tap_errline0.bas')
229+
tap_errline0.bas:10: error: Syntax error. Unexpected token 'HL' [HL]
230+
>>> process_file('zx48k/tap_errline1.bas')
231+
tap_errline1.bas:15: error: Syntax error. Unexpected token 'HL' [HL]
230232

231233
# Test error file names
232234
>>> process_file('zx48k/bad_fname_err0.bas', ['-S', '-q'])
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
border 0
2+
3+
#define BREAK \
4+
nop \
5+
6+
asm
7+
BREAK
8+
push hl
9+
push de
10+
push af
11+
12+
ld hl,16384
13+
ld de,16385
14+
ld a,(hl)
15+
ex hl,de
16+
17+
pop af
18+
pop de
19+
pop hl
20+
end asm

0 commit comments

Comments
 (0)