shithub: mc

Download patch

ref: 6f329f4bad91511ade5355a473241d41332b6ad8
parent: 921fafdfaf1319d022fac101dd021fdd2eaea8cd
author: Ori Bernstein <[email protected]>
date: Mon Oct 28 21:05:11 EDT 2013

Convert the interpreter to use new match syntax.

--- a/interp.myr
+++ b/interp.myr
@@ -16,16 +16,13 @@
 	re.strp = 0
 	run(re)
 	match re.matched
-	`std.None:
-		-> false
-		;;
-	`std.Some thr:	
+	|`std.None: -> false
+	| `std.Some thr:
 		for i = 0; i < re.nmatch; i++
 			std.put("match %z:", i)
 			std.put("[%z..%z]\n", thr.mstart[i], thr.mend[i])
 		;;
 		-> thr.mend[0] == str.len
-		;;
 	;;
 }
 
@@ -61,7 +58,7 @@
 	str = re.str
 	match re.prog[thr.ip]
 	/* Char matching. Consume exactly one byte from the string. */
-	`Ibyte b:
+	| `Ibyte b:
 		trace(re, "\t%z:\tByte %b\n", thr.ip, b)
 		if !in(re, str)
 			kill(re, tid, "end of string")
@@ -71,8 +68,7 @@
 			thr.ip++
 			trace(re, "\t\tmatched %b with %b\n", b, str[re.strp])
 		;;
-		;;
-	`Irange (start, end):
+	| `Irange (start, end):
 		trace(re, "\t%z:\tRange (%b, %b)\t", thr.ip, start, end)
 		if !in(re, str) || start > str[re.strp] || end < str[re.strp]
 			kill(re, tid, "bad range")
@@ -79,8 +75,7 @@
 		else
 			thr.ip++
 		;;
-		;;
-	`Idot:
+	| `Idot:
 		trace(re, "\t%z:\tDot\n", thr.ip)
 		if in(re, str)
 			kill(re, tid, "past end")
@@ -87,12 +82,11 @@
 		else
 			thr.ip++
 		;;
-		;;
 	/*
 	  Non-consuming. All of these recursively call step() until
 	  exactly one byte is consumed from the string.
 	 */
-	`Ibol:
+	| `Ibol:
 		trace(re, "\t%z:\tBol\n", thr.ip)
 		if re.strp == 0 || str[re.strp - 1] == '\n' castto(byte)
 			thr.ip++
@@ -100,8 +94,7 @@
 		else
 			kill(re, tid, "not beginning of line")
 		;;
-		;;
-	`Ieol:
+	| `Ieol:
 		trace(re, "\t%z:\tEol\n", thr.ip)
 		if re.strp == str.len || str[re.strp] == '\n' castto(byte)
 			step(re, tid)
@@ -108,35 +101,29 @@
 		else
 			kill(re, tid, "not end of line")
 		;;
-		;;
-	`Ilbra	m:
+	| `Ilbra m:
 		trace(re, "\t%z:\tLbra %z\n", thr.ip, m)
 		trace(re, "\t\tmatch start = %z\n", re.strp)
 		thr.mstart[m] = re.strp
 		thr.ip++
 		step(re, tid)
-		;;
-	`Irbra	m:
+	| `Irbra m:
 		trace(re, "\t%z:\tRbra %z\n", thr.ip, m)
 		thr.mend[m] = re.strp
 		thr.ip++
 		step(re, tid)
-		;;
-	`Ifork	(lip, rip):
+	| `Ifork (lip, rip):
 		trace(re, "\t%z:\tFork (%z, %z)\n", thr.ip, rip, lip)
 		mstart = std.sldup(thr.mstart)
 		mend = std.sldup(thr.mend)
 		jmp(re, tid, rip)
 		fork(re, thr, lip, mstart, mend)
-		;;
-	`Ijmp ip:
+	| `Ijmp ip:
 		trace(re, "\t%z:\tJmp %z\n", thr.ip, ip)
 		jmp(re, tid, ip)
-		;;
-	`Imatch:
+	| `Imatch:
 		trace(re, "\t%z:\tMatch\n", thr.ip)
 		finish(re, tid)
-		;;
 	;;
 }
 
@@ -190,8 +177,8 @@
 const finish = {re, tid
 	trace(re, "finish\n", tid)
 	match re.matched
-	`std.Some thr:	std.free(thr);;
-	`std.None:	;;
+	| `std.None:
+	| `std.Some thr:	std.free(thr)
 	;;
 	re.matched = `std.Some re.thr[tid]
 	re.thr[tid] = re.thr[re.nthr - 1]
--- a/main.myr
+++ b/main.myr
@@ -3,9 +3,9 @@
 
 const main = {
 	var found
-	match regex.compile("[a-z0-9]*bc")
+	match regex.compile(".*bc")
 	`std.Success re:
-		found = regex.exec(re, "a123bc")
+		found = regex.exec(re, "Abc")
 		std.put("Found = %t: len = %z\n", found, re.strp)
 		-> 0
 		;;