shithub: mc

ref: f91ae82c02cc2f453580ea019e3cda8cddf1380f
dir: /test/testmatch.myr/

View raw version
use std
use regex

pkg =
	const testmatch	: (pat : byte[:], text : byte[:] -> void)
	const dbgmatch	: (pat : byte[:], text : byte[:] -> void)
;;

const testmatch = {pat, text
	run(regex.compile(pat), text)
}

const dbgmatch = {pat, text
	run(regex.dbgcompile(pat), text)
}

const run = {regex, text
	var i
	match regex
	| `std.Success re:
		match regex.exec(re, text)
		| `std.Some m:
			std.put("Matched. %i matches\n", m.len)
			for i = 0; i < m.len; i++
				std.put("match %i: %s\n", i, m[i])
			;;
		| `std.None:
			std.put("No match\n")
		;;
		regex.free(re)
	| `std.Failure err:
		std.put("failed to compile regex")
	;;
}