xml-parser-generator: Support naming sequences. vizml
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 9 Feb 2020 21:26:48 +0000 (21:26 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 9 Feb 2020 21:26:48 +0000 (21:26 +0000)
src/output/spv/vizml.grammar
src/output/spv/xml-parser-generator

index 02733c2f0fbd65fedf962c1c473f8a0a1cd9fdda..2146d73b22e892ea0f05d6c7112d9e3e53b149bf 100644 (file)
@@ -25,12 +25,12 @@ visualization
    :version
    :schemaLocation?
    :clip?
-=> (visualization_extension | location)*
-   (userSource | delimitedFileSource | embeddedSource)+
+=> (visualization_extension | location)*[extensions]
+   (userSource | delimitedFileSource | embeddedSource)+[sources]
    (sourceVariable | derivedVariable | expressionVariable
-    | intervalDomain | categoricalDomain)+
-   (graph | labelFrame | container | legend)+
-   (style | layerController | styleCycle)+
+    | intervalDomain | categoricalDomain)+[variables]
+   (graph | labelFrame | container | legend)+[graphs]
+   (style | layerController | styleCycle)+[styles]
    popup*
    resources?
    facetSortController?
index df34fbf8fffb41b8de9bbe1afa9c22a79d0ca505..e5b9e3e68ea23bdc61db8e4f757ef6e1ccad12a9 100644 (file)
@@ -45,7 +45,7 @@ def get_line():
 
 def expect(type):
     if token[0] != type:
-        fatal("syntax error expecting %s" % type)
+        fatal("syntax error at %s expecting %s" % (token[0], type))
 
 
 def match(type):
@@ -142,6 +142,11 @@ def parse_quantified():
     if token[0] in ['*', '+', '?']:
         item = {'type': token[0], 'item': item}
         get_token()
+        if match('['):
+            expect('id')
+            item['seq_name'] = token[1]
+            get_token()
+            must_match(']')
     return item
 
 
@@ -284,7 +289,7 @@ def parse_production():
             elif (term['type'] in ('*', '+')
                   and term['item']['type'] == 'nonterminal'):
                 pass
-            else:
+            elif 'seq_name' not in term:
                 n += 1
                 term['seq_name'] = 'seq' if n == 1 else 'seq%d' % n
 
@@ -766,8 +771,7 @@ def print_free_members(attributes, rhs, indent):
                              prefix, nt_name, member_name,
                              member_name))
                 else:
-                    n += 1
-                    seq_name = 'seq' if n == 1 else 'seq%d' % n
+                    seq_name = term['seq_name']
                     print('''\
     for (size_t i = 0; i < p->n_%s; i++)
         p->%s[i]->class_->spvxml_node_free (p->%s[i]);
@@ -834,8 +838,7 @@ def print_recurse_members(attributes, rhs, function):
                           % (member_name,
                              prefix, function, nt_name, member_name))
                 else:
-                    n += 1
-                    seq_name = 'seq' if n == 1 else 'seq%d' % n
+                    seq_name = term['seq_name']
                     print('''\
     for (size_t i = 0; i < p->n_%s; i++)
         p->%s[i]->class_->spvxml_node_%s (ctx, p->%s[i]);'''