From: Ben Pfaff Date: Tue, 14 Dec 2021 06:25:50 +0000 (-0800) Subject: parse_arg X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fctables2;p=pspp parse_arg --- 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."""