From 14a8b9f1a63bd7cb77a920adeae5f479d9d874aa Mon Sep 17 00:00:00 2001
From: picomeg <megordon5@gmail.com>
Date: Tue, 11 Aug 2020 04:42:34 +0100
Subject: [PATCH] tidier versions of fix and regression test

---
 src/backends/glr.c | 13 +++----------
 src/t_regression.c | 45 +++++++++++++++++++++++----------------------
 2 files changed, 26 insertions(+), 32 deletions(-)

diff --git a/src/backends/glr.c b/src/backends/glr.c
index 61ba3dfb..06722b19 100644
--- a/src/backends/glr.c
+++ b/src/backends/glr.c
@@ -174,16 +174,9 @@ static bool glr_step(HParseResult **result, HSlist *engines,
     HSlistNode *x;
     for(x=engines->head; x; x=x->next) {
       HLREngine *eng = x->elem;
-      if(eng->state == engine->state) {
-    	// check they've both actually consumed the same number of tokens from the input.
-    	// as implemented the engines do not always consume tokens in lockstep.
-    	// TODO: ?--shall we try to actually change it to move in lockstep--?
-    	// This is a quick fix, but it should stay as a sanity check regardless
-
-    	if(eng->input.index == engine->input.index) {
-    		x->elem = lrengine_merge(eng, engine);
-    		break;
-    	}
+      if(eng->state == engine->state && eng->input.index == engine->input.index) {
+    	x->elem = lrengine_merge(eng, engine);
+    	break;
       }
     }
     if(!x)  // no merge happened
diff --git a/src/t_regression.c b/src/t_regression.c
index ff618870..c245eff5 100644
--- a/src/t_regression.c
+++ b/src/t_regression.c
@@ -475,14 +475,15 @@ static void test_issue83() {
 
 static void test_bug60() {
 
-//TODO: there is probably an even smaller example that shows the issue
+//There is probably an even smaller example that shows the issue
+
+	  HParser *zed = NULL;
 	  HParser *alpha = NULL;
-	  HParser *sp = NULL;
 	  HParser *vchar = NULL;
-	  HParser *curly = NULL;
-	  HParser *comment = NULL;
-	  HParser *c_nl = NULL;
-	  HParser *c_sp = NULL;
+	  HParser *why = NULL;
+	  HParser *plural_zed = NULL;
+	  HParser *plural_zed_zed = NULL;
+	  HParser *a_to_zed = NULL;
 	  HParser *alphas = NULL;
 	  HParser *rule = NULL;
 	  HParser *rulelist = NULL;
@@ -490,35 +491,35 @@ static void test_bug60() {
 	  HParseResult *r = NULL;
 	  int n;
 
-	  alpha =  h_ch('z');
+	  zed =  h_ch('z');
 
-	  vchar = h_ch_range(0x7a, 0x7b); // allows z and {
+	  vchar = h_ch_range(0x79, 0x7a); // allows y and z
 
-	  sp = h_ch('b');
+	  alpha = h_ch('a');
 
-	  curly = h_ch('{'); //'=');
+	  why = h_ch('y');
 
-	  comment = h_sequence(
-	      curly,
-	      h_many(h_choice(sp, vchar, NULL)),
+	  plural_zed = h_sequence(
+	      why,
+	      h_many(h_choice(alpha, vchar, NULL)),
 	      NULL);
-	  c_nl = h_choice(comment, alpha, NULL);
-	  c_sp = h_choice(sp, h_sequence(c_nl, sp, NULL), NULL);
+	  plural_zed_zed = h_choice(plural_zed, zed, NULL);
+	  alphas = h_choice(alpha, h_sequence(plural_zed_zed, alpha, NULL), NULL);
 
-	  alphas = h_sequence(
-	      alpha,
-	      h_many(h_sequence(h_many1(c_sp), alpha, NULL)),
+	  a_to_zed = h_sequence(
+	      zed,
+	      h_many(h_sequence(h_many1(alphas), zed, NULL)),
 	      NULL);
-	  rule = h_sequence(alphas, c_nl, NULL);
+	  rule = h_sequence(a_to_zed, plural_zed_zed, NULL);
 	  rulelist = h_many1(h_choice(
 	      rule,
-	      h_sequence(h_many(c_sp), c_nl, NULL),
+	      h_sequence(h_many(alphas), plural_zed_zed, NULL),
 	      NULL));
 
 	  p = rulelist;
 
-	  g_check_parse_ok(p, PB_GLR, "b{zzb", 5);
-	  g_check_parse_match(p, PB_GLR, "b{zzb", 5, "(((u0x62) (u0x7b (u0x7a u0x7a u0x62))))");
+	  g_check_parse_ok(p, PB_GLR, "ayzza", 5);
+	  g_check_parse_match(p, PB_GLR, "ayzza", 5, "(((u0x61) (u0x79 (u0x7a u0x7a u0x61))))");
 
 }
 
-- 
GitLab