on master help sign in
Merge pull request #4039 from msmorgan/feature/lexer-case-insensitive
f925538Jan de Muijnck-Hughes
libs/contrib/Text/Lexer.idr+26−8
@@ -70,6 +70,32 @@ export
70isNot : Char -> Lexer
70isNot : Char -> Lexer
71isNot x = Pred (/=x)
71isNot x = Pred (/=x)
72
72
73+||| Recognise a character case-insensitively
74+export
75+like : Char -> Lexer
76+like x = Pred (\y => toUpper x == toUpper y)
77+
78+||| Recognise anything but the given character case-insensitively
79+export
80+notLike : Char -> Lexer
81+notLike x = Pred (\y => toUpper x /= toUpper y)
82+
83+||| Recognise a specific string
84+export
85+exact : String -> Lexer
86+exact str with (unpack str)
87+ exact str | [] = Fail -- Not allowed, Lexer has to consume
88+ exact str | (x :: xs)
89+ = foldl SeqEmpty (is x) (map is xs)
90+
91+||| Recognise a specific string case-insensitively
92+export
93+approx : String -> Lexer
94+approx str with (unpack str)
95+ approx str | [] = Fail -- Not allowed, Lexer has to consume
96+ approx str | (x :: xs)
97+ = foldl SeqEmpty (like x) (map like xs)
98+
73||| Recognise a lexer or recognise no input. This is not guaranteed
99||| Recognise a lexer or recognise no input. This is not guaranteed
74||| to consume input
100||| to consume input
75export
101export
@@ -191,14 +217,6 @@ export
191digits : Lexer
217digits : Lexer
192digits = some digit
218digits = some digit
193
219
194−||| Recognise a specific string
195−export
196−exact : String -> Lexer
197−exact str with (unpack str)
198− exact str | [] = Fail -- Not allowed, Lexer has to consume
199− exact str | (x :: xs)
200− = foldl SeqEmpty (is x) (map is xs)
201−
202||| Recognise a single hexidecimal digit
220||| Recognise a single hexidecimal digit
203export
221export
204hexDigit : Lexer
222hexDigit : Lexer