on master help sign in
Text.Lexer: add character range lexer
6fec28cMichael Morgan
libs/contrib/Text/Lexer.idr+6
@@ -169,6 +169,12 @@ takeToken lex str
169 = do i <- scan lex 0 str -- i must be > 0 if successful
169 = do i <- scan lex 0 str -- i must be > 0 if successful
170 pure (substr 0 i (getString str), strTail i str)
170 pure (substr 0 i (getString str), strTail i str)
171
171
172+||| Recognise a character range [`a`-`b`]. Also works in reverse!
173+export
174+range : (start : Char) -> (end : Char) -> Lexer
175+range start end = pred (\x => (x >= min start end)
176+ && (x <= max start end))
177+
172||| Recognise a single digit 0-9
178||| Recognise a single digit 0-9
173export
179export
174digit : Lexer
180digit : Lexer