aboutsummaryrefslogtreecommitdiffstats
path: root/subv.py
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2021-10-10 18:55:51 +0000
committers-ol <s+removethis@s-ol.nu>2021-10-10 18:55:51 +0000
commit9d02be627e041fad1df24e78a3041cb33fbbbd39 (patch)
tree9a25c85155616180dae861f0f14a26f7c13ca6df /subv.py
parentfix bswapw, print_hex_word (diff)
downloadsubv-9d02be627e041fad1df24e78a3041cb33fbbbd39.tar.gz
subv-9d02be627e041fad1df24e78a3041cb33fbbbd39.zip
add optional strings stage
Diffstat (limited to 'subv.py')
-rw-r--r--subv.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/subv.py b/subv.py
index 8cee596..6574d1e 100644
--- a/subv.py
+++ b/subv.py
@@ -77,6 +77,19 @@ def parse_segment(line):
raise ValueError("invalid segment line")
+def parse_special(line):
+ """parse a special-line.
+
+ >>> parse_special('@@/test "hello/123 asd"')
+ [('@@', 'test'), '"hello/123 asd"']
+ >>> parse_special('@@/test @@/123 @@/uuu')
+ [('@@', 'test'), '@@/123 @@/uuu']
+ """
+ parts = white.split(line, maxsplit=1)
+ parts[0] = parse_part(parts[0])
+ return parts
+
+
def parse_label(line):
"""parse a label-line.
@@ -156,6 +169,10 @@ def classify(line):
'instr'
>>> classify('ff/8 0/3 2/5')
'instr'
+ >>> classify('@@/8')
+ 'special'
+ >>> classify('@@/test 123 "asdx"')
+ 'special'
"""
if line == "":
return "empty"
@@ -163,6 +180,8 @@ def classify(line):
return "segment"
elif line.endswith(":"): # label
return "label"
+ elif line.startswith("@@/"):
+ return "special"
else:
return "instr"
@@ -185,6 +204,8 @@ def parse(line):
parsed = parse_label(clean)
elif type == "instr":
parsed = parse_instr(clean)
+ elif type == "special":
+ parsed = parse_special(clean)
else:
parsed = None
@@ -324,7 +345,7 @@ def format(line):
if line["comment"]:
packed = packed + " # " + line["comment"]
return packed
- elif type == "empty":
+ elif type == "empty" or type == "special":
return line["raw"]
else:
raise NotImplementedError("type {}".format(type))