From af542eff9e1e51561a9efa37685ee07b1d01b53e Mon Sep 17 00:00:00 2001 From: Adam Scarr Date: Thu, 10 Aug 2017 21:04:14 +1000 Subject: Add parse logging --- parser.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'parser.go') 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) { -- cgit v1.2.3