on master help sign in
Merge pull request #4025 from msmorgan/feature/lexer-choice

add `choice` combinator for Lexers

commit14148f62878908be3243d9e53fb6f45f70c628e5 authorNiklas Larsson <metaniklas@gmail.com> dateSun 27 Aug 2017, 01:28 (9 years ago) parentb9161b10e86734
1 file changed+6
libs/contrib/Text/Lexer.idr+6
libs/contrib/Text/Lexer.idr+6
@@ -59,6 +59,12 @@ export
5959many : Lexer -> Recognise False
6060many l = some l <|> Empty
6161
62+||| Recognize the first matching lexer from a non-empty list.
63+export
64+choice : (xs : List Lexer) -> {auto ok : NonEmpty xs} -> Lexer
65+choice (x :: []) = x
66+choice (x :: xs@(_ :: _)) = x <|> choice xs
67+
6268||| Recognise many instances of `l` until an instance of `end` is
6369||| encountered.
6470|||