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
This commit is contained in:
@@ -421,12 +421,23 @@ def p_stmt(p):
|
|||||||
else:
|
else:
|
||||||
return ws + lh
|
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:
|
with openio(input or '-', 'r') as in_f:
|
||||||
# create parser
|
# create parser
|
||||||
lexemes = LEXEMES.copy()
|
lexemes = LEXEMES.copy()
|
||||||
|
if no_defaults:
|
||||||
|
lexemes['assert'] = []
|
||||||
|
lexemes['unreachable'] = []
|
||||||
|
lexemes['arrow'] = []
|
||||||
lexemes['assert'] += assert_
|
lexemes['assert'] += assert_
|
||||||
lexemes['unreachable'] += unreachable
|
lexemes['unreachable'] += unreachable
|
||||||
|
if arrow and no_defaults:
|
||||||
|
lexemes['arrow'].append('=>')
|
||||||
p = Parser(in_f, lexemes)
|
p = Parser(in_f, lexemes)
|
||||||
|
|
||||||
with openio(output or '-', 'w') as f:
|
with openio(output or '-', 'w') as f:
|
||||||
@@ -478,6 +489,14 @@ if __name__ == "__main__":
|
|||||||
'-u', '--unreachable',
|
'-u', '--unreachable',
|
||||||
action='append',
|
action='append',
|
||||||
help="Additional symbols for unreachable statements.")
|
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(
|
parser.add_argument(
|
||||||
'-l', '--limit',
|
'-l', '--limit',
|
||||||
type=lambda x: int(x, 0),
|
type=lambda x: int(x, 0),
|
||||||
|
|||||||
Reference in New Issue
Block a user