parse_arg ctables2
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 14 Dec 2021 06:25:50 +0000 (22:25 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 14 Dec 2021 06:25:50 +0000 (22:25 -0800)
src/language/expressions/generate.py

index 7d375e0eab93a9f1cdebe395aefb4c083857c7f8..64843d89efe294a546cdd47dc27662b743c4c8d0 100644 (file)
@@ -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."""