Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request boriel-basic#570 from boriel/bugfix/error_line_num…
Browse files Browse the repository at this point in the history
…bers

fix: fix error line number in macros in ASM
  • Loading branch information
boriel committed Sep 29, 2021
2 parents 47d5624 + 14fa218 commit 58608ca
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/parsetab/tabs.dbm.bak
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'zxbpp', (0, 76970)
'asmparse', (77312, 272467)
'zxnext_asmparse', (350208, 303081)
'zxbparser', (653312, 703160)
'asmparse', (77312, 268394)
'zxnext_asmparse', (346112, 298411)
'zxbparser', (644608, 703160)
Binary file modified src/parsetab/tabs.dbm.dat
Binary file not shown.
6 changes: 3 additions & 3 deletions src/parsetab/tabs.dbm.dir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'zxbpp', (0, 76970)
'asmparse', (77312, 272467)
'zxnext_asmparse', (350208, 303081)
'zxbparser', (653312, 703160)
'asmparse', (77312, 268394)
'zxnext_asmparse', (346112, 298411)
'zxbparser', (644608, 703160)
12 changes: 11 additions & 1 deletion src/zxbasm/asmlex.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from src.api.config import OPTIONS
from src.api.errmsg import error

from src.api import global_


_tokens: Tuple[str, ...] = (
"STRING",
Expand Down Expand Up @@ -192,7 +194,7 @@
"m": "M",
}

preprocessor = {"init": "_INIT", "line": "_LINE"}
preprocessor = {"init": "_INIT"}

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

return t

def t_asm_PREPROCLINE(self, t):
r'\#[ \t]*[Ll][Ii][Nn][Ee][ \t]+([0-9]+)(?:[ \t]+"((?:[^"]|"")*)")?[ \t]*\r?\n'
import re

match = re.match('#[ \t]*[Ll][Ii][Nn][Ee][ \t]+([0-9]+)(?:[ \t]+"((?:[^"]|"")*)")?[ \t]*\r?\n', t.value)
global_.FILENAME = match.groups()[1] or global_.FILENAME
self.lineno = int(match.groups()[0])

def t_preproc_ID(self, t):
r"[_a-zA-Z][_a-zA-Z0-9]*" # preprocessor directives
t.type = preprocessor.get(t.value.lower(), "ID")
Expand Down
11 changes: 0 additions & 11 deletions src/zxbasm/asmparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,17 +926,6 @@ def p_preprocessor_line(p):
p[0] = None


def p_preprocessor_line_line(p):
"""preproc_line : _LINE INTEGER"""
p.lexer.lineno = int(p[2]) + p.lexer.lineno - p.lineno(2)


def p_preprocessor_line_line_file(p):
"""preproc_line : _LINE INTEGER STRING"""
p.lexer.lineno = int(p[2]) + p.lexer.lineno - p.lineno(3) - 1
gl.FILENAME = p[3]


def p_preproc_line_init(p):
"""preproc_line : _INIT STRING"""
INITS.append(Container(p[2].strip('"'), p.lineno(2)))
Expand Down
6 changes: 4 additions & 2 deletions tests/functional/test_errmsg.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,10 @@ line_number_after_macro.bas:11: error: Syntax Error. Unexpected token '+' <PLUS>
>>> process_file('zx48k/tap_asm_error_line.bas', ['-S', '-q'])
tap_asm_error_line.bas:3: error: Syntax error. Unexpected token '10' [INTEGER]
tap_asm_error_line.bas:7: error: Syntax error. Unexpected token '10' [INTEGER]
>>> process_file('zx48k/tap_errline.bas')
tap_errline.bas:10: error: Syntax error. Unexpected token 'HL' [HL]
>>> process_file('zx48k/tap_errline0.bas')
tap_errline0.bas:10: error: Syntax error. Unexpected token 'HL' [HL]
>>> process_file('zx48k/tap_errline1.bas')
tap_errline1.bas:15: error: Syntax error. Unexpected token 'HL' [HL]

# Test error file names
>>> process_file('zx48k/bad_fname_err0.bas', ['-S', '-q'])
Expand Down
20 changes: 20 additions & 0 deletions tests/functional/zx48k/tap_errline1.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
border 0

#define BREAK \
nop \

asm
BREAK
push hl
push de
push af

ld hl,16384
ld de,16385
ld a,(hl)
ex hl,de

pop af
pop de
pop hl
end asm

0 comments on commit 58608ca

Please sign in to comment.