on master help sign in
Text.Lexer: add `concat`
commita792d6ba267343aa7d33bbb80a41b43bd11258eb authorMichael Morgan <morgan.michael@me.com> dateThu 26 Oct 2017, 18:06 (9 years ago) parent565ccf5
2 files changed+14
libs/contrib/Data/Bool/Extra.idr+4 libs/contrib/Text/Lexer.idr+10
libs/contrib/Data/Bool/Extra.idr+4
@@ -26,3 +26,7 @@ orFalseNeutral True = Refl
2626orTrueTrue : (x : Bool) -> x || True = True
2727orTrueTrue False = Refl
2828orTrueTrue True = Refl
29+
30+orSameAndRightNeutral : (x, right : Bool) -> x || (x && right) = x
31+orSameAndRightNeutral False _ = Refl
32+orSameAndRightNeutral True _ = Refl
libs/contrib/Text/Lexer.idr+10
@@ -1,5 +1,7 @@
11module Text.Lexer
22
3+import Data.Bool.Extra
4+
35import public Control.Delayed
46
57%default total
@@ -61,6 +63,14 @@ export
6163reject : Recognise c -> Recognise False
6264reject = Lookahead False
6365
66+||| Sequence a list of recognisers.
67+export
68+concat : {c : Bool} -> (xs : List (Recognise c)) -> Recognise (c && isCons xs)
69+concat {c} [] = rewrite andFalseFalse c in Empty
70+concat {c} (x :: xs) = rewrite andTrueNeutral c in
71+ rewrite sym (orSameAndRightNeutral c (isCons xs)) in
72+ SeqEmpty x (concat xs)
73+
6474data StrLen : Type where
6575 MkStrLen : String -> Nat -> StrLen
6676