mirror of https://github.com/pret/pokecrystal.git
better comment handling in textpre.py
This commit is contained in:
parent
a720875a84
commit
216a7ac1ec
29
textpre.py
29
textpre.py
|
@ -266,14 +266,28 @@ chars = {
|
||||||
}
|
}
|
||||||
|
|
||||||
for l in sys.stdin:
|
for l in sys.stdin:
|
||||||
|
|
||||||
# strip comments
|
# strip comments
|
||||||
line = l.partition(";")
|
|
||||||
i = 0
|
|
||||||
asm = ""
|
asm = ""
|
||||||
while i < len(line) and l[0] != ";":
|
comment = None
|
||||||
asm = asm + line[i]
|
in_quotes = False
|
||||||
i = i + 1
|
in_comment = False
|
||||||
|
for letter in l:
|
||||||
|
if in_comment:
|
||||||
|
comment += letter
|
||||||
|
elif in_quotes and letter != "\"":
|
||||||
|
asm += letter
|
||||||
|
elif in_quotes and letter == "\"":
|
||||||
|
in_quotes = False
|
||||||
|
asm += letter
|
||||||
|
elif not in_quotes and letter == "\"":
|
||||||
|
in_quotes = True
|
||||||
|
asm += letter
|
||||||
|
elif not in_quotes and letter != "\"":
|
||||||
|
if letter == ";":
|
||||||
|
in_comment = True
|
||||||
|
comment = ";"
|
||||||
|
else:
|
||||||
|
asm += letter
|
||||||
|
|
||||||
# skip asm with no quotes
|
# skip asm with no quotes
|
||||||
if "\"" not in asm:
|
if "\"" not in asm:
|
||||||
|
@ -339,3 +353,6 @@ for l in sys.stdin:
|
||||||
else:
|
else:
|
||||||
sys.stdout.write(token)
|
sys.stdout.write(token)
|
||||||
even = not even
|
even = not even
|
||||||
|
|
||||||
|
if comment != None:
|
||||||
|
sys.stdout.write(comment)
|
||||||
|
|
Loading…
Reference in New Issue