on master help sign in
add `choice` combinator for Lexers
0e86734Michael Morgan
libs/contrib/Text/Lexer.idr+6
@@ -59,6 +59,12 @@ export
59many : Lexer -> Recognise False
59many : Lexer -> Recognise False
60many l = some l <|> Empty
60many l = some l <|> Empty
61
61
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+
62||| Recognise many instances of `l` until an instance of `end` is
68||| Recognise many instances of `l` until an instance of `end` is
63||| encountered.
69||| encountered.
64|||
70|||