on master help sign in
Text.Lexer: rewrite `exact` and `approx` in terms of `concat`
538aa6aMichael Morgan
libs/contrib/Text/Lexer.idr+10−12
@@ -209,21 +209,19 @@ export
209notLike : Char -> Lexer
209notLike : Char -> Lexer
210notLike x = Pred (\y => toUpper x /= toUpper y)
210notLike x = Pred (\y => toUpper x /= toUpper y)
211
211
212−||| Recognise a specific string
212+||| Recognise a specific string.
213−export
213+||| Fails if the string is empty.
214exact : String -> Lexer
214exact : String -> Lexer
215−exact str with (unpack str)
215+exact str = case map is (unpack str) of
216− exact str | [] = Fail -- Not allowed, Lexer has to consume
216+ [] => fail
217− exact str | (x :: xs)
217+ (x :: xs) => concat (x :: xs)
218− = foldl SeqEmpty (is x) (map is xs)
219
218
220−||| Recognise a specific string case-insensitively
219+||| Recognise a specific string (case-insensitive).
221−export
220+||| Fails if the string is empty.
222approx : String -> Lexer
221approx : String -> Lexer
223−approx str with (unpack str)
222+approx str = case map like (unpack str) of
224− approx str | [] = Fail -- Not allowed, Lexer has to consume
223+ [] => fail
225− approx str | (x :: xs)
224+ (x :: xs) => concat (x :: xs)
226− = foldl SeqEmpty (like x) (map like xs)
227
225
228||| Recognise a lexer or recognise no input. This is not guaranteed
226||| Recognise a lexer or recognise no input. This is not guaranteed
229||| to consume input
227||| to consume input