shithub: mc

ref: ae222f2157fa57dd27ff23bcb13c78adc08627b2
dir: /libregex/types.myr/

View raw version
use std

pkg regex =
	type status = union
		`Noimpl
		`Incomplete
		`Unbalanced
		`Emptyparen
		`Badrep
		`Badrange
		`Badescape
	;;

	type regex = struct
		/* compile state */
		debug	: bool
		pat	: byte[:]
		nmatch	: std.size

		/* VM state */
		runq	: rethread#
		expired	: rethread#
		expiredtail	: rethread#
		proglen	: std.size
		prog	: reinst[:]
		nthr	: std.size
		str	: byte[:]
		strp	: std.size
	;;

	type rethread = struct
		next	: rethread#	/* run queue link */

		tid	: std.size	/* just for debugging */
		ip	: std.size	/* the instruction pointer */
		dead	: bool		/* thread died */
		matched	: bool		/* thread matched */

		mstart	: std.size[:]	/* match starts */
		mend	: std.size[:]	/* match ends */
	;;

	type reinst = union
		/* direct consumers */
		`Ibyte	byte
		`Irange	(byte, byte)

		/* groups */
		`Ilbra	std.size
		`Irbra	std.size

		/* anchors */
		`Ibol
		`Ieol
		`Ibow
		`Ieow

		/* control flow */
		`Ifork	(std.size, std.size)
		`Ijmp	std.size
		`Imatch
	;;
;;