From d4c7932193314f795d7e8ccad7f47ddffc88d96a Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 13 Dec 2021 22:25:50 -0800 Subject: [PATCH] parse_arg --- src/language/expressions/generate.py | 62 ++++++++++++++-------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/language/expressions/generate.py b/src/language/expressions/generate.py index 7d375e0eab..64843d89ef 100644 --- a/src/language/expressions/generate.py +++ b/src/language/expressions/generate.py @@ -323,7 +323,7 @@ def parse_input(): force_match('(') args = [] while not match(')'): - arg = parse_arg() + arg = Arg.parse() args += [arg] if arg.idx is not None: if match(')'): @@ -566,42 +566,42 @@ class Arg: self.times = times self.condition = condition -def parse_arg(): - """Parses and returns a function argument.""" - type_ = Type.parse() - if type_ is None: - type_ = types['number'] + def parse(): + """Parses and returns a function argument.""" + type_ = Type.parse() + if type_ is None: + type_ = types['number'] - if toktype != 'id': - sys.stderr.write("argument name expected at `%s'\n" % token) - sys.exit(1) - name = token + if toktype != 'id': + sys.stderr.write("argument name expected at `%s'\n" % token) + sys.exit(1) + name = token - lookahead() - global line + lookahead() + global line - idx = None - times = 1 + idx = None + times = 1 - if line[0] in "[,)": - get_token() - if match('['): - if type_.name not in ('number', 'string'): - sys.stderr.write('only double and string arrays supported\n') - sys.exit(1) - idx = force('id') - if match('*'): - times = force('int') - if times != 2: - sys.stderr.write('multiplication factor must be two\n') + if line[0] in "[,)": + get_token() + if match('['): + if type_.name not in ('number', 'string'): + sys.stderr.write('only double and string arrays supported\n') sys.exit(1) - force_match(']') - condition = None - else: - condition = name + ' ' + accumulate_balanced(',)', swallow_end=False) - get_token() + idx = force('id') + if match('*'): + times = force('int') + if times != 2: + sys.stderr.write('multiplication factor must be two\n') + sys.exit(1) + force_match(']') + condition = None + else: + condition = name + ' ' + accumulate_balanced(',)', swallow_end=False) + get_token() - return Arg(name, type_, idx, times, condition) + return Arg(name, type_, idx, times, condition) def print_header(): """Prints the output file header.""" -- 2.30.2