on master help sign in
Text.Parser: add `match` function for easier terminals
b6f6d42Michael Morgan
libs/contrib/Text/Parser.idr+10
@@ -4,10 +4,20 @@ import Data.Bool.Extra
4
4
5import public Text.Parser.Core
5import public Text.Parser.Core
6import public Text.Quantity
6import public Text.Quantity
7+import public Text.Token
7
8
8%access export
9%access export
9%default total
10%default total
10
11
12+||| Parse a terminal based on a kind of token.
13+match : (Eq k, TokenKind k) =>
14+ (kind : k) ->
15+ Grammar (Token k) True (tokType kind)
16+match kind = terminal $
17+ \(Tok kind' text) => if kind' == kind
18+ then Just $ tokValue kind text
19+ else Nothing
20+
11||| Optionally parse a thing, with a default value if the grammar doesn't
21||| Optionally parse a thing, with a default value if the grammar doesn't
12||| match. May match the empty input.
22||| match. May match the empty input.
13option : {c : Bool} ->
23option : {c : Bool} ->