Skip to content

Commit

Permalink
Add --parser option to fasm.tool
Browse files Browse the repository at this point in the history
Signed-off-by: Dusty DeWeese <[email protected]>
  • Loading branch information
HackerFoo committed Dec 10, 2020
1 parent 35cc007 commit e4379f4
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions fasm/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,26 @@
# SPDX-License-Identifier: ISC

import argparse
from fasm import fasm_tuple_to_string, parse_fasm_filename
import importlib
import fasm.parser
from fasm import fasm_tuple_to_string


def nullable_string(val):
if not val:
return None
return val


def get_fasm_parser(name=None):
module_name = None
if name is None:
module_name = 'fasm.parser'
elif name in fasm.parser.available:
module_name = 'fasm.parser.' + name
else:
raise Exception("Parser '{}' is not available.".format(name))
return importlib.import_module(module_name)


def main():
Expand All @@ -20,12 +39,20 @@ def main():
'--canonical',
action='store_true',
help='Return canonical form of FASM.')
parser.add_argument(
'--parser',
type=nullable_string,
help='Select FASM parser to use. '
'Default is to choose the best implementation available.')

args = parser.parse_args()

fasm_tuples = parse_fasm_filename(args.file)

print(fasm_tuple_to_string(fasm_tuples, args.canonical))
try:
fasm_parser = get_fasm_parser(args.parser)
fasm_tuples = fasm_parser.parse_fasm_filename(args.file)
print(fasm_tuple_to_string(fasm_tuples, args.canonical))
except Exception as e:
print('Error: ' + str(e))


if __name__ == '__main__':
Expand Down

0 comments on commit e4379f4

Please sign in to comment.