diff options
author | Bryan Bishop <kanzure@gmail.com> | 2012-04-26 10:51:37 -0500 |
---|---|---|
committer | Bryan Bishop <kanzure@gmail.com> | 2012-04-26 10:51:37 -0500 |
commit | 216a7ac1ecde92e366e02f74e88f28eebf33b903 (patch) | |
tree | fa672075e800759b8d3ac5751ad8d653534f0a8b | |
parent | a720875a84c1ae89237ca2a0b075accb2c10e83c (diff) |
better comment handling in textpre.py
-rw-r--r-- | textpre.py | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/textpre.py b/textpre.py index d84d85519..e7f191a95 100644 --- a/textpre.py +++ b/textpre.py @@ -266,14 +266,28 @@ chars = { } for l in sys.stdin: - # strip comments - line = l.partition(";") - i = 0 asm = "" - while i < len(line) and l[0] != ";": - asm = asm + line[i] - i = i + 1 + comment = None + in_quotes = False + 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 if "\"" not in asm: @@ -339,3 +353,6 @@ for l in sys.stdin: else: sys.stdout.write(token) even = not even + + if comment != None: + sys.stdout.write(comment) |