summaryrefslogtreecommitdiff
path: root/parser.go
diff options
context:
space:
mode:
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) {