@@ -1,5 +1,7 @@
1module Text.Lexer
1module Text.Lexer
3import public Text.Lexer.Core
5import public Text.Lexer.Core
5%default total
7%default total
@@ -18,10 +20,19 @@ opt l = l <|> empty
18non : (l : Lexer) -> Lexer
20non : (l : Lexer) -> Lexer
19non l = reject l <+> any
21non l = reject l <+> any
21−||| Recognise the first matching lexer in a container. Always consumes input
23+||| Produce recognisers by applying a function to elements of a container, and
24+||| recognise the first match. Consumes input if the function produces consuming
22−||| if an option succeeds. Fails if the container is empty.
25+||| recognisers. Fails if the container is empty.
23−choice : Foldable t => t Lexer -> Lexer
26+choiceMap : {c : Bool} ->
27+ Foldable t => (a -> Recognise c) -> t a -> Recognise c
28+choiceMap {c} f xs = foldr (\x, acc => rewrite sym (andSameNeutral c) in
24−choice xs = foldr (<|>) fail xs
30+ fail xs
32+||| Recognise the first matching recogniser in a container. Consumes input if
33+||| recognisers in the list consume. Fails if the container is empty.
34+choice : Foldable t => t (Recognise c) -> Recognise c
26||| Sequence a list of recognisers. Guaranteed to consume input if the list is
37||| Sequence a list of recognisers. Guaranteed to consume input if the list is
27||| non-empty and the recognisers consume.
38||| non-empty and the recognisers consume.