tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

consumer_lexical_boundary.tri (1520B)


      1 !import "consumers.lexical-worker" L
      2 !import "consumers.structural" S
      3 !import "consumers.validate" V
      4 !import "prelude" !Local
      5 invalid rules = resultIsErr (L.lCompile (S.makeConsumer t rules))
      6 invalidOpen rules = resultIsErr (L.lCompileOpen (S.makeConsumer t rules))
      7 rule input state output = S.makeRule input state output
      8 valid = S.makeConsumer t [(rule (S.patFork (S.patCapture 0) (S.patStem (S.patCapture 1))) S.patAny (S.outCapture 1))]
      9 checks = foldl and? true [
     10   (equal? (L.lCompile t) (err (V.vDiagnostic "malformed" 0 t "consumer node") t))
     11   (equal? (L.lCompileOpen t) (err (V.vDiagnostic "malformed" 0 t "consumer node") t))
     12   (invalid (t t))
     13   (invalid [(t)])
     14   (invalid [(rule t S.patAny (S.outLiteral 1))])
     15   (invalid [(rule (pair 3 t) S.patAny (S.outLiteral 1))])
     16   (invalid [(rule (pair 6 t) S.patAny (S.outLiteral 1))])
     17   (invalid [(rule S.patAny S.patAny t)])
     18   (invalid [(rule S.patAny S.patAny (pair 2 t))])
     19   (invalid [(rule S.patAny S.patAny (pair 4 t))])
     20   (invalid [(rule S.patAny S.patAny (pair 7 t))])
     21   (invalid [(rule S.patAny S.patAny (S.outCapture 99))])
     22   (resultIsOk (L.lCompile (S.makeConsumer t
     23     [(rule S.patAny S.patAny (S.outBecome (S.outLiteral t)
     24       (S.outLiteral t) (S.outLiteral t)))])))
     25   (invalidOpen [(rule S.patAny S.patAny (pair 4 t))])
     26   (resultIsOk (L.lCompile valid))
     27   (resultIsOk (L.lCompileOpen valid))
     28   (equal? (L.lRunChecked (resultOr t (L.lCompile valid)) (pair 3 (t 4))) (ok 4 t))]
     29 main = matchBool "lexical-boundary-ok" "lexical-boundary-DIFFER" checks
     30 main