shithub: mc

Download patch

ref: eb21d4f1381f73045c81df0840aa50df20515045
parent: 3c96292a713f091b96d015aedcf824a7ea82f1cf
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jun 11 07:55:43 EDT 2016

Simplify reluctant match types.

--- a/lib/regex/compile.myr
+++ b/lib/regex/compile.myr
@@ -100,10 +100,8 @@
 	|`Alt	(a, b): genalt(re, a, b, t)
 	|`Cat	(a, b): gen(re, a); gen(re, b)
 	/* repetition */
-	|`Star	a:	genstar(re, a, false, t)
-	|`Rstar a:	genstar(re, a, true, t)
-	|`Plus	a:	gen(re, a); genstar(re, a, false, t)
-	|`Rplus	a:	gen(re, a); genstar(re, a, true, t)
+	|`Star	(a, r):	genstar(re, a, r, t)
+	|`Plus	(a, r):	gen(re, a); genstar(re, a, r, t)
 	|`Quest	a:	genquest(re, a)
 
 	/* end matches */
@@ -434,18 +432,12 @@
 		dump(re, a, indent + 1)
 		dump(re, b, indent + 1)
 	/* repetition */
-	| `Star	a:
-		std.put("Star\n")
+	| `Star	(a, r):
+		std.put("Star reluct={}\n", r)
 		dump(re, a, indent + 1)
-	| `Rstar a:
-		std.put("Rstar\n")
+	| `Plus	(a, r):
+		std.put("Plus reluct={}\n", r)
 		dump(re, a, indent + 1)
-	| `Plus	a:
-		std.put("Plus\n")
-		dump(re, a, indent + 1)
-	| `Rplus a:
-		std.put("Rplus\n")
-		dump(re, a, indent + 1)
 	| `Quest	a:
 		std.put("Quest\n")
 		dump(re, a, indent + 1)
@@ -546,17 +538,9 @@
 	| `Some t:
 		idx = re.idx
 		if matchc(re, '*')
-                        if matchc(re, '?')
-				ret = mk(re, `Rstar t, idx)
-                        else
-				ret = mk(re, `Star t, idx)
-			;;
+			ret = mk(re, `Star (t, matchc(re, '?')), idx)
 		elif matchc(re, '+')
-                        if matchc(re, '?')
-				ret = mk(re, `Rplus t, idx)
-			else
-				ret = mk(re, `Plus t, idx)
-			;;
+			ret = mk(re, `Plus (t, matchc(re, '?')), idx)
 		elif matchc(re, '?')
 			ret = mk(re, `Quest t, idx)
 		else
@@ -874,10 +858,8 @@
 	| `Alt	(a, b): astfree(a); astfree(b)
 	| `Cat	(a, b): astfree(a); astfree(b)
 	/* repetition */
-	| `Star	a:	astfree(a)
-	| `Rstar a:	astfree(a)
-	| `Plus	a:	astfree(a)
-	| `Rplus a:	astfree(a)
+	| `Star	(a, r):	astfree(a)
+	| `Plus	(a, r):	astfree(a)
 	| `Quest a:	astfree(a)
 
 	/* end matches */
--- a/lib/regex/types.myr
+++ b/lib/regex/types.myr
@@ -44,10 +44,8 @@
 		`Cat	(ast#, ast#)
 
 		/* repetition */
-		`Star	ast#
-		`Rstar  ast#
-		`Plus	ast#
-		`Rplus	ast#
+		`Star	(ast#, bool)
+		`Plus	(ast#, bool)
 		`Quest	ast#	
 
 		/* end matches */