on master help sign in
add opt combinator to Text.Lexer

This combinator recognises a provided lexer, or recognises no input if the lexer fails. Also corrected an Americanism that I was responsible for introducing.

commit2700cefa5baa1d91a45f0fb85a25371c26aa1fca authorMichael Morgan <michael.morgan@mind-over-data.com> dateSun 27 Aug 2017, 20:23 (9 years ago) parentde2dfc2
1 file changed+7−1
libs/contrib/Text/Lexer.idr+7−1
libs/contrib/Text/Lexer.idr+7−1
@@ -48,6 +48,12 @@ export
4848isNot : Char -> Lexer
4949isNot x = Pred (/=x)
5050
51+||| Recognise a lexer or recognise no input. This is not guaranteed
52+||| to consume input
53+export
54+opt : Lexer -> Recognise False
55+opt l = l <|> Empty
56+
5157||| Recognise a sequence of at least one sub-lexers
5258export
5359some : Lexer -> Lexer
@@ -59,7 +65,7 @@ export
5965many : Lexer -> Recognise False
6066many l = some l <|> Empty
6167
62−||| Recognize the first matching lexer from a non-empty list.
68+||| Recognise the first matching lexer from a non-empty list.
6369export
6470choice : (xs : List Lexer) -> {auto ok : NonEmpty xs} -> Lexer
6571choice (x :: []) = x