mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
fix syntax errors
This commit is contained in:
parent
c587125674
commit
d92f91f22f
@ -503,12 +503,9 @@ class Parser:
|
||||
if not line.startswith(("%import ", "%import\t")):
|
||||
raise self.PError("expected import")
|
||||
try:
|
||||
_, arg = line.split(maxsplit=1)
|
||||
_, filename = line.split(maxsplit=1)
|
||||
except ValueError:
|
||||
raise self.PError("invalid import statement")
|
||||
if not arg.startswith('"') or not arg.endswith('"'):
|
||||
raise self.PError("filename must be between quotes")
|
||||
filename = arg[1:-1]
|
||||
if not filename:
|
||||
raise self.PError("invalid filename")
|
||||
self._parse_import_file(filename)
|
||||
@ -678,25 +675,28 @@ class Parser:
|
||||
raise self.PError("ZP block cannot contain code statements")
|
||||
self.cur_block.statements.append(self.parse_statement(line))
|
||||
elif line:
|
||||
match = re.fullmatch(r"(?P<label>\S+)\s*:(?P<rest>.*)", line)
|
||||
if match:
|
||||
if is_zp_block:
|
||||
raise self.PError("ZP block cannot contain code labels")
|
||||
self.parse_label(line)
|
||||
label = match.group("label")
|
||||
rest = match.group("rest")
|
||||
self.parse_label(label, rest)
|
||||
else:
|
||||
raise self.PError("invalid statement in block")
|
||||
else:
|
||||
raise self.PError("invalid statement in block")
|
||||
return True, None # continue with more statements
|
||||
|
||||
def parse_label(self, line: str) -> None:
|
||||
label_line = line.split(maxsplit=1)
|
||||
if str.isidentifier(label_line[0]):
|
||||
labelname = label_line[0]
|
||||
def parse_label(self, labelname: str, rest: str) -> None:
|
||||
if str.isidentifier(labelname):
|
||||
if labelname in self.cur_block.label_names:
|
||||
raise self.PError("label already defined")
|
||||
if labelname in self.cur_block.symbols:
|
||||
raise self.PError("symbol already defined")
|
||||
self.cur_block.symbols.define_label(labelname, self.sourceref)
|
||||
self.cur_block.statements.append(Label(labelname, self.sourceref))
|
||||
if len(label_line) > 1:
|
||||
rest = label_line[1]
|
||||
if rest:
|
||||
self.cur_block.statements.append(self.parse_statement(rest))
|
||||
else:
|
||||
raise self.PError("invalid label name")
|
||||
@ -775,7 +775,13 @@ class Parser:
|
||||
raise self.PError("invalid statement")
|
||||
subroutine_block.statements.append(self.parse_statement(line))
|
||||
elif line:
|
||||
self.parse_label(line)
|
||||
match = re.fullmatch(r"(?P<label>\S+)\s*:(?P<rest>.*)", line)
|
||||
if match:
|
||||
label = match.group("label")
|
||||
rest = match.group("rest")
|
||||
self.parse_label(label, rest)
|
||||
else:
|
||||
raise self.PError("invalid statement in subroutine")
|
||||
else:
|
||||
raise self.PError("invalid statement in subroutine")
|
||||
self.cur_block = current_block
|
||||
@ -1087,11 +1093,10 @@ class Parser:
|
||||
if len(aline) < 2:
|
||||
raise self.PError("invalid asminclude or asmbinary directive")
|
||||
filename = aline[1]
|
||||
if not filename.startswith('"') or not filename.endswith('"'):
|
||||
raise self.PError("filename must be between quotes")
|
||||
filename = filename[1:-1]
|
||||
if not filename:
|
||||
raise self.PError("invalid filename")
|
||||
if filename[0] in "'\"" or filename[-1] in "'\"":
|
||||
raise self.PError("invalid filename, should not use quotes")
|
||||
filename_in_sourcedir = os.path.join(os.path.split(self.sourceref.file)[0], filename)
|
||||
filename_in_output_location = os.path.join(self.outputdir, filename)
|
||||
if not os.path.isfile(filename_in_sourcedir):
|
||||
|
@ -171,6 +171,7 @@ def p_directive_args(p):
|
||||
def p_directive_arg(p):
|
||||
"""directive_arg : NAME
|
||||
| INTEGER
|
||||
| STRING
|
||||
"""
|
||||
p[0] = p[1]
|
||||
|
||||
|
@ -56,8 +56,8 @@ class PreprocessingParser(Parser):
|
||||
def parse_memory_def(self, line: str, is_zeropage: bool=False) -> None:
|
||||
super().parse_memory_def(line, is_zeropage)
|
||||
|
||||
def parse_label(self, line: str) -> None:
|
||||
super().parse_label(line)
|
||||
def parse_label(self, labelname: str, rest: str) -> None:
|
||||
super().parse_label(labelname, rest)
|
||||
|
||||
def parse_subroutine_def(self, line: str) -> None:
|
||||
super().parse_subroutine_def(line)
|
||||
|
@ -719,18 +719,16 @@ class AstNode:
|
||||
for name, value in nvars.items():
|
||||
if name == "sourceref":
|
||||
continue
|
||||
if type(value) in (str, int, float, bool, type(None)):
|
||||
elif type(value) in (str, int, float, bool, type(None)):
|
||||
attrs.append((name, tostr(value, level+1)))
|
||||
for name, value in nvars.items():
|
||||
if type(value) is list:
|
||||
elif type(value) is list:
|
||||
strvalue = "["
|
||||
strvalue += (",\n" + indent*(level+1)).join(tostr(v, level+1) for v in value) + "\n" + (1+level)*indent + "]"
|
||||
attrs.append((name, strvalue))
|
||||
for name, value in nvars.items():
|
||||
if name == "sourceref":
|
||||
continue
|
||||
if type(value) is not list and type(value) not in (str, int, float, bool, type(None)):
|
||||
elif type(value) is not list and type(value) not in (str, int, float, bool, type(None)):
|
||||
attrs.append((name, tostr(value, level+2)))
|
||||
else:
|
||||
raise TypeError("WEIRD TYPE", type(value))
|
||||
attrstr = ("\n" + indent*(1+level)).join("{} = {}".format(name, sv) for name, sv in attrs)
|
||||
result = "\n" + indent * level + "<{0:s} l={1:d} c={2:d}".format(clsname, node.sourceref.line, node.sourceref.column)
|
||||
return result + "{} |end {} l={:d}|>".format(attrstr, clsname, node.sourceref.line)
|
||||
|
@ -133,14 +133,14 @@
|
||||
var .byte expr_fault2 = 1 + (8/3)+sin(33) + max(1,2,3)
|
||||
|
||||
|
||||
sin
|
||||
sin:
|
||||
return
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
start
|
||||
start:
|
||||
|
||||
; --- immediate primitive value assignments ----
|
||||
|
||||
|
@ -3,10 +3,10 @@
|
||||
%output prg, basic
|
||||
%zp clobber
|
||||
|
||||
%import "c64lib"
|
||||
%import c64lib
|
||||
|
||||
~ main {
|
||||
start
|
||||
start:
|
||||
[$d020]=0
|
||||
return
|
||||
blockdtypes1.max()
|
||||
@ -138,7 +138,7 @@ start
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -317,7 +317,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -491,7 +491,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -670,7 +670,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -844,7 +844,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -1023,7 +1023,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -1197,7 +1197,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -1376,7 +1376,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -1550,7 +1550,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -1729,7 +1729,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -1903,7 +1903,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -2082,7 +2082,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -2256,7 +2256,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -2435,7 +2435,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -2609,7 +2609,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -2788,7 +2788,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -2962,7 +2962,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -3141,7 +3141,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -3315,7 +3315,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -3494,7 +3494,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -3668,7 +3668,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -3847,7 +3847,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -4021,7 +4021,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -4200,7 +4200,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -4374,7 +4374,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -4553,7 +4553,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -4727,7 +4727,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -4906,7 +4906,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -5080,7 +5080,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -5259,7 +5259,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -5433,7 +5433,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -5612,7 +5612,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -5786,7 +5786,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -5965,7 +5965,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -6139,7 +6139,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -6318,7 +6318,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -6492,7 +6492,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -6671,7 +6671,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
@ -6845,7 +6845,7 @@ bar
|
||||
; because zp-vars get assigned a specific address (from a pool). Also, it's a byte.
|
||||
|
||||
|
||||
max
|
||||
max:
|
||||
return
|
||||
|
||||
|
||||
@ -7024,7 +7024,7 @@ max
|
||||
sub sub4 (string: XY, other : A) -> (Y?) = $dd22
|
||||
|
||||
|
||||
bar
|
||||
bar:
|
||||
goto sub1
|
||||
goto sub2 (1 )
|
||||
goto sub3 (3)
|
||||
|
@ -8,17 +8,18 @@
|
||||
|
||||
~ main {
|
||||
start:
|
||||
A=0
|
||||
[$d020]=A
|
||||
X=false
|
||||
Y=true
|
||||
return
|
||||
;A=0
|
||||
;[$d020]=A
|
||||
;X=false
|
||||
;Y=true
|
||||
;return
|
||||
|
||||
;included_assembly
|
||||
%asminclude "included.source" test_include
|
||||
%asminclude " included.sourcelynx walla derp ", test_include
|
||||
%asminclude " included.sourcelynx walla derp ", "test_include"
|
||||
|
||||
;included_binary
|
||||
%asmbinary "included.binary"
|
||||
%asmbinary "included.binary" $40
|
||||
%asmbinary "included.binary" $40 $200
|
||||
%asmbinary " included.binary 234 "
|
||||
%asmbinary " included.binary", $40
|
||||
%asmbinary "included.binary", $40, $200
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user