consumer_become_lexical.tri (3022B)
1 -- Differential tail-delegation tests: explicit state overrides both defaults. 2 !import "consumers.structural" S 3 !import "consumers.lexical-worker" L 4 !import "prelude" !Local 5 6 rule input state output = S.makeRule input state output 7 stateIR = S.makeConsumer 11 [(rule S.patAny (S.patCapture 0) (S.outCapture 0))] 8 stateWorker = resultOr t (L.lCompile stateIR) 9 explicitIR target = S.makeConsumer 99 [(rule S.patAny S.patAny 10 (S.outBecome (S.outLiteral target) (S.outLiteral 7) (S.outLiteral 23)))] 11 12 fromInputIR = S.makeConsumer 99 [(rule (S.patCapture 0) S.patAny 13 (S.outBecome (S.outCapture 0) (S.outLiteral 7) (S.outLiteral 23)))] 14 fromInput = resultOr t (L.lCompile fromInputIR) 15 fromStateIR target = S.makeConsumer (pair target 23) [(rule S.patAny 16 (S.patFork (S.patCapture 0) (S.patCapture 1)) 17 (S.outBecome (S.outCapture 0) (S.outLiteral 7) (S.outCapture 1)))] 18 19 middleIR target = S.makeConsumer 5 [(rule S.patAny S.patAny 20 (S.outBecome (S.outLiteral target) (S.outLiteral 7) (S.outLiteral 43)))] 21 middleWorker = resultOr t (L.lCompile (middleIR stateWorker)) 22 topIR middle = S.makeConsumer 31 [(rule S.patAny S.patAny 23 (S.outBecome (S.outLiteral middle) (S.outLiteral 7) (S.outLiteral 29)))] 24 25 missingIR = S.makeConsumer 0 t 26 missingWorker = resultOr t (L.lCompile missingIR) 27 failingCall worker = S.outCall (S.outLiteral worker) (S.outLiteral t) 0 (S.outCapture 0) 28 failureIR target argument state = S.makeConsumer 99 [(rule S.patAny S.patAny 29 (S.outBecome target argument state))] 30 31 checks = foldl and? true [ 32 (equal? (L.lRunChecked (resultOr t (L.lCompile (explicitIR stateWorker))) t) 33 (S.runConsumer (explicitIR stateIR) t)) 34 (equal? (L.lRunChecked (resultOr t (L.lCompile (explicitIR stateWorker))) t) 35 (ok 23 t)) 36 (equal? (L.lRunChecked fromInput stateWorker) 37 (S.runConsumer fromInputIR stateIR)) 38 (equal? (L.lRunChecked fromInput stateWorker) (ok 23 t)) 39 (equal? (L.lRunChecked (resultOr t (L.lCompile (fromStateIR stateWorker))) t) 40 (S.runConsumer (fromStateIR stateIR) t)) 41 (equal? (L.lRunChecked (resultOr t (L.lCompile (topIR middleWorker))) t) 42 (S.runConsumer (topIR (middleIR stateIR)) t)) 43 (equal? (L.lRunChecked (resultOr t (L.lCompile (topIR middleWorker))) t) 44 (ok 43 t)) 45 (equal? (L.lRunChecked (resultOr t (L.lCompile (failureIR 46 (failingCall missingWorker) (S.outLiteral 7) (S.outLiteral 23)))) t) 47 (S.runConsumer (failureIR (failingCall missingIR) 48 (S.outLiteral 7) (S.outLiteral 23)) t)) 49 (equal? (L.lRunChecked (resultOr t (L.lCompile (failureIR 50 (S.outLiteral stateWorker) (failingCall missingWorker) (S.outLiteral 23)))) t) 51 (S.runConsumer (failureIR (S.outLiteral stateIR) 52 (failingCall missingIR) (S.outLiteral 23)) t)) 53 (equal? (L.lRunChecked (resultOr t (L.lCompile (failureIR 54 (S.outLiteral stateWorker) (S.outLiteral 7) (failingCall missingWorker)))) t) 55 (S.runConsumer (failureIR (S.outLiteral stateIR) 56 (S.outLiteral 7) (failingCall missingIR)) t))] 57 main = matchBool "consumer-become-ok" "consumer-become-DIFFER" checks 58 main