From d15109d3163322d125b78570f1f1c8827edce6ca Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 13 Dec 2021 22:25:18 -0800 Subject: [PATCH] parse_type() --- src/language/expressions/generate.py | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) 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'] -- 2.30.2