summaryrefslogtreecommitdiff
path: root/combinator.go
diff options
context:
space:
mode:
authorAdam Scarr <adam@vektah.net>2017-08-07 22:57:06 +1000
committerAdam Scarr <adam@vektah.net>2017-08-07 22:57:06 +1000
commit6e1c004fea8d841f554c2e94ff39e1fcee94b4e3 (patch)
tree5ee131da4ca938fc30d59ba7c6dc402a77fefe07 /combinator.go
parent4594587e3b7d1b474ce2444e821294c63cabe3da (diff)
Add Bind for constants
Diffstat (limited to 'combinator.go')
-rw-r--r--combinator.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/combinator.go b/combinator.go
index f072913..e83a0c1 100644
--- a/combinator.go
+++ b/combinator.go
@@ -123,6 +123,19 @@ func Maybe(parser Parserish) Parser {
})
}
+func Bind(parser Parserish, val interface{}) Parser {
+ p := Parsify(parser)
+
+ return func(ps *State) Node {
+ node := p(ps)
+ if ps.Errored() {
+ return node
+ }
+ node.Result = val
+ return node
+ }
+}
+
func Map(parser Parserish, f func(n Node) Node) Parser {
p := Parsify(parser)