From: Ben Pfaff Date: Tue, 14 Dec 2021 06:25:18 +0000 (-0800) Subject: parse_type() X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d15109d3163322d125b78570f1f1c8827edce6ca;p=pspp parse_type() --- diff --git a/src/language/expressions/generate.py b/src/language/expressions/generate.py index 4d42c112cf..7d375e0eab 100644 --- a/src/language/expressions/generate.py +++ b/src/language/expressions/generate.py @@ -157,6 +157,18 @@ class Type: new.fixed_value = fixed_value return new + def parse(): + """If the current token is an identifier that names a type, returns + the type and skips to the next token. Otherwise, returns + None. + """ + if toktype == 'id': + for type_ in types.values(): + if type_.name == token: + get_token() + return type_ + return None + def init_type(type_): global types types[type_.name] = type_ @@ -278,7 +290,7 @@ def parse_input(): else: break - return_type = parse_type() + return_type = Type.parse() if return_type is None: return_type = types['number'] if return_type.name not in ['number', 'string', 'boolean']: @@ -329,7 +341,7 @@ def parse_input(): aux = [] while toktype == 'id': - type_ = parse_type() + type_ = Type.parse() if type_ is None: sys.stderr.write('parse error\n') sys.exit(1) @@ -517,18 +529,6 @@ def get_line(): if comment_ofs >= 0: line = line[:comment_ofs] -def parse_type(): - """If the current token is an identifier that names a type, returns - the type and skips to the next token. Otherwise, returns - undef. - """ - if toktype == 'id': - for type_ in types.values(): - if type_.name == token: - get_token() - return type_ - return None - def force(type_): """Makes sure that 'toktype' equals 'type', reads the next token, and returns the previous 'token'. @@ -568,7 +568,7 @@ class Arg: def parse_arg(): """Parses and returns a function argument.""" - type_ = parse_type() + type_ = Type.parse() if type_ is None: type_ = types['number']