summaryrefslogtreecommitdiff
path: root/parser.go
diff options
context:
space:
mode:
authorAdam Scarr <adam@vektah.net>2017-08-10 22:06:08 +1000
committerAdam Scarr <adam@vektah.net>2017-08-10 22:06:08 +1000
commit8a92b5348f8cf6769f30237df906ee9ce71ad237 (patch)
treeee23dda7188bab1a01892fba4c1c697263c3a9a6 /parser.go
parenta0e66b1c46ec57218f8a95a21ace7cbbceb29ec2 (diff)
Unicode safe by default
Diffstat (limited to 'parser.go')
-rw-r--r--parser.go35
1 files changed, 19 insertions, 16 deletions
diff --git a/parser.go b/parser.go
index 7c3f866..12bb858 100644
--- a/parser.go
+++ b/parser.go
@@ -76,26 +76,14 @@ func ParsifyAll(parsers ...Parserish) []Parser {
return ret
}
-// WS will consume whitespace, it should only be needed when AutoWS is turned off
-func WS() Parser {
- return NewParser("AutoWS", func(ps *State) Result {
- ps.WS(ps)
- return Result{}
- })
-}
-
-// 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) {
+func Run(parser Parserish, input string, ws ...VoidParser) (result interface{}, err error) {
p := Parsify(parser)
ps := NewState(input)
+ if len(ws) > 0 {
+ ps.WS = ws[0]
+ }
ret := p(ps)
ps.AutoWS()
@@ -111,6 +99,21 @@ func Run(parser Parserish, input string) (result interface{}, err error) {
return ret.Result, nil
}
+// WS will consume whitespace, it should only be needed when AutoWS is turned off
+func WS() Parser {
+ return NewParser("AutoWS", func(ps *State) Result {
+ ps.WS(ps)
+ return Result{}
+ })
+}
+
+// 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{}
+}
+
// Regex returns a match if the regex successfully matches
func Regex(pattern string) Parser {
re := regexp.MustCompile("^" + pattern)