From 7d95a2ff296b4f99b4478b5434ee9580e9ae7bac Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 14 Feb 2024 02:45:37 -0600 Subject: [PATCH] Added ability to disable default patterns in prettyasserts.py - -n/--no-defaults - disable default patterns The default patterns can be brought back explicitly with: - -a/--assert - enable assert pattern - -u/--unreachable - enable unreachable pattern - -A/--arrow - enable arrow patterns Technically the default configuration is equivalent to the follow: $ ./scripts/prettyasserts.py \ -a assert \ -a __builtin_assert \ -u unreachable \ -u __builtin_unreachable \ -A \ input.a.c -o output.c This isn't really useful for littlefs, but may be useful elsewhere --- scripts/prettyasserts.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/scripts/prettyasserts.py b/scripts/prettyasserts.py index 4f4be9b8..aa7eb687 100755 --- a/scripts/prettyasserts.py +++ b/scripts/prettyasserts.py @@ -421,12 +421,23 @@ def p_stmt(p): else: return ws + lh -def main(input=None, output=None, assert_=[], unreachable=[], limit=LIMIT): +def main(input=None, output=None, + assert_=[], + unreachable=[], + arrow=False, + no_defaults=False, + limit=LIMIT): with openio(input or '-', 'r') as in_f: # create parser lexemes = LEXEMES.copy() + if no_defaults: + lexemes['assert'] = [] + lexemes['unreachable'] = [] + lexemes['arrow'] = [] lexemes['assert'] += assert_ lexemes['unreachable'] += unreachable + if arrow and no_defaults: + lexemes['arrow'].append('=>') p = Parser(in_f, lexemes) with openio(output or '-', 'w') as f: @@ -478,6 +489,14 @@ if __name__ == "__main__": '-u', '--unreachable', action='append', help="Additional symbols for unreachable statements.") + parser.add_argument( + '-A', '--arrow', + action='store_true', + help="Enable arrow (=>) expressions, this is enabled by default.") + parser.add_argument( + '-n', '--no-defaults', + action='store_true', + help="Disable the default statements/expressions.") parser.add_argument( '-l', '--limit', type=lambda x: int(x, 0),