on master help sign in
Text.Lexer: add character range lexer

`range` accepts two characters and creates a lexer that recognises characters in between them (inclusive).

commit6fec28cac0507714bdabaf1bff8f779d68769dd8 authorMichael Morgan <morgan.michael@me.com> dateSat 2 Sep 2017, 12:00 (9 years ago) parent4251ad8
1 file changed+6
libs/contrib/Text/Lexer.idr+6
libs/contrib/Text/Lexer.idr+6
@@ -169,6 +169,12 @@ takeToken lex str
169169 = do i <- scan lex 0 str -- i must be > 0 if successful
170170 pure (substr 0 i (getString str), strTail i str)
171171
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+
172178||| Recognise a single digit 0-9
173179export
174180digit : Lexer