diff options
author | Bryan Bishop <kanzure@gmail.com> | 2012-11-30 10:12:27 -0600 |
---|---|---|
committer | Bryan Bishop <kanzure@gmail.com> | 2012-11-30 10:12:27 -0600 |
commit | 3d8e7a17769436a099360ad925de1968994f1b49 (patch) | |
tree | 69f5cee8147cb5c2e19e677ccef1239114166ab3 /preprocessor.py | |
parent | 935384f93186b976dfdeab12f46e30ea51e44a17 (diff) |
make preprocessor includable as a module
The preprocessor only runs against stdin when __main__ is activated,
instead of always running on stdin. This allows the file to be included
in an interactive python session or in other scenarios.
Diffstat (limited to 'preprocessor.py')
-rw-r--r-- | preprocessor.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/preprocessor.py b/preprocessor.py index 150ea951d..5f19953bb 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -552,6 +552,7 @@ def include_file(asm): read_line(line) def read_line(l): + """Preprocesses a given line of asm.""" # strip and store any comment on this line if ";" in l: asm, comment = separate_comment(l) @@ -581,5 +582,18 @@ def read_line(l): if comment != None: sys.stdout.write(comment) -for l in sys.stdin: - read_line(l) +def preprocess(lines=None): + """Main entry point for the preprocessor.""" + if not lines: + # read each line from stdin + lines = sys.stdin + elif not isinstance(lines, list): + # split up the input into individual lines + lines = lines.split("\n") + + for l in lines: + read_line(l) + +# only run against stdin when not included as a module +if __name__ == "__main__": + preprocess() |