test.icl 1.09 KB
Newer Older
Camil Staps's avatar
Camil Staps committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
module test

import StdEnv
import Data.Error
from Data.Func import $
import Regex

Start :: *World -> *World
Start w
# (io,w) = stdio w
# io     = loop (Error "waiting for regex") io
# (ok,w) = fclose io w
= w

loop :: (MaybeErrorString Regex) *File -> *File
loop r f
# (ln,f)        = freadline f
# f             = f <<< ln
| ln % (0,12) == "# End of test"
	= f
| isMember ln.[0] ['#\\']
	= loop r f
| ln.[0] == '/' && ln.[size ln-2] == '/' // modifiers not supported
	= loop (compile $ fromString $ ln % (1,size ln-3)) f
| ln.[0] == '/'
	= loop (Error "skipped modifiers") f
| ln % (0,3) == "    "
	| isError r = loop r f
	= loop r (print_match (fromOk r) (fromString $ ln % (4,size ln-2)) f)
| otherwise
	= loop r f

print_match :: !Regex ![Char] *File -> *File
print_match r s f
| isEmpty matches = f <<< "No match\n"
# f = f <<< " 0: " <<< toString m <<< '\n'
# f = f <<< foldl (+++) "" (map (\(NotNamed i,s) -> if (i < 9) " " "" +++ toString (i+1) +++ ": " +++ toString s +++ "\n") $ sort grps)
= f
where
	(_,m,grps) = hd matches
	matches = match r s

instance < GroupId where (<) (NotNamed a) (NotNamed b) = a < b