Skip to content

Commit 5e62646

Browse files
committed
fix: fixes a bug in sections parsing.
Each section must start with {{\n (end of line), inline sections like IF {{ $1 == $2 }} are not allowed.
1 parent 9536b5b commit 5e62646

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

src/arch/z80/peephole/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
TreeType = list[str | list["TreeType"]]
1212

1313
COMMENT: Final[str] = ";;"
14-
RE_REGION = re.compile(r"([_a-zA-Z][a-zA-Z0-9]*)[ \t]*{{")
14+
RE_REGION = re.compile(r"([_a-zA-Z][a-zA-Z0-9]*)[ \t]*\{\{$")
1515
RE_DEF = re.compile(r"([_a-zA-Z][a-zA-Z0-9]*)[ \t]*:[ \t]*(.*)")
1616
RE_IFPARSE = re.compile(r'"(""|[^"])*"|[(),]|\b[_a-zA-Z]+\b|[^," \t()]+')
1717
RE_ID = re.compile(r"\b[_a-zA-Z]+\b")

tests/arch/zx48k/peephole/test_parser.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,46 @@ def test_in_list(self):
355355
"WITH": ["pop $1", "$2"],
356356
"DEFINE": [],
357357
}
358+
359+
def test_parse_cond(self):
360+
result = parser.parse_str(
361+
"""
362+
OLEVEL: 1
363+
OFLAG: 14
364+
REPLACE {{
365+
$1
366+
}}
367+
368+
WITH {{
369+
}}
370+
371+
IF {{
372+
$1 == "nop"
373+
}}
374+
"""
375+
)
376+
assert result == {
377+
"OLEVEL": 1,
378+
"OFLAG": 14,
379+
"REPLACE": ["$1"],
380+
"WITH": [],
381+
"DEFINE": [],
382+
"IF": ["$1", "==", "nop"],
383+
}
384+
385+
def test_parse_if_must_start_in_a_new_line(self):
386+
result = parser.parse_str(
387+
"""
388+
OLEVEL: 1
389+
OFLAG: 14
390+
REPLACE {{
391+
$1
392+
}}
393+
394+
WITH {{
395+
}}
396+
;; this is not valid
397+
IF {{ $1 == "nop" }}
398+
"""
399+
)
400+
assert result is None

0 commit comments

Comments
 (0)