on master help sign in
Text.Lexer: add like and approx for case-insensitivity

It occurs to me that these might be controversial names...

commit8c4286e0aed7f881a7c18497ddaed9c90f556a3b authorMichael Morgan <morgan.michael@me.com> dateMon 28 Aug 2017, 08:22 (9 years ago) parent00dc543
1 file changed+18
libs/contrib/Text/Lexer.idr+18
libs/contrib/Text/Lexer.idr+18
@@ -70,6 +70,16 @@ export
7070isNot : Char -> Lexer
7171isNot x = Pred (/=x)
7272
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+
7383||| Recognise a specific string
7484export
7585exact : String -> Lexer
@@ -78,6 +88,14 @@ exact str with (unpack str)
7888 exact str | (x :: xs)
7989 = foldl SeqEmpty (is x) (map is xs)
8090
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+
8199||| Recognise a lexer or recognise no input. This is not guaranteed
82100||| to consume input
83101export