summaryrefslogtreecommitdiff
path: root/parser.go
diff options
context:
space:
mode:
authorAdam Scarr <adam@vektah.net>2017-08-10 21:04:14 +1000
committerAdam Scarr <adam@vektah.net>2017-08-10 21:08:18 +1000
commitaf542eff9e1e51561a9efa37685ee07b1d01b53e (patch)
treec700bdca58b4f9bbeb89ba1b102b2a779c88f7f3 /parser.go
parentb64fcfaa6115eb4a5f65c12d37f95d842136ae35 (diff)
Add parse logging
Diffstat (limited to 'parser.go')
-rw-r--r--parser.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/parser.go b/parser.go
index 7590ffa..7c3f866 100644
--- a/parser.go
+++ b/parser.go
@@ -52,7 +52,7 @@ type Parserish interface{}
func Parsify(p Parserish) Parser {
switch p := p.(type) {
case func(*State) Result:
- return NewParser("anonymous func", p)
+ return p
case Parser:
return p
case *Parser:
@@ -84,6 +84,13 @@ func WS() Parser {
})
}
+// Cut prevents backtracking beyond this point. Usually used after keywords when you
+// are sure this is the correct path. Improves performance and error reporting.
+func Cut(ps *State) Result {
+ ps.Cut = ps.Pos
+ return Result{}
+}
+
// Run applies some input to a parser and returns the result, failing if the input isnt fully consumed.
// It is a convenience method for the most common way to invoke a parser.
func Run(parser Parserish, input string) (result interface{}, err error) {