From 0144b59b672391a9e579a4712ec80ec27487bfa5 Mon Sep 17 00:00:00 2001
From: Ben Pfaff <blp@cs.stanford.edu>
Date: Sun, 9 Feb 2020 21:26:48 +0000
Subject: [PATCH] xml-parser-generator: Support naming sequences.

---
 src/output/spv/vizml.grammar        | 10 +++++-----
 src/output/spv/xml-parser-generator | 15 +++++++++------
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/src/output/spv/vizml.grammar b/src/output/spv/vizml.grammar
index 02733c2f0f..2146d73b22 100644
--- a/src/output/spv/vizml.grammar
+++ b/src/output/spv/vizml.grammar
@@ -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?
diff --git a/src/output/spv/xml-parser-generator b/src/output/spv/xml-parser-generator
index df34fbf8ff..e5b9e3e68e 100644
--- a/src/output/spv/xml-parser-generator
+++ b/src/output/spv/xml-parser-generator
@@ -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]);'''
-- 
2.30.2