summaryrefslogtreecommitdiff
path: root/parser.go
diff options
context:
space:
mode:
authorÖzgür Kesim <oec@codeblau.de>2019-11-28 15:34:30 +0100
committerÖzgür Kesim <oec@codeblau.de>2019-11-28 15:34:30 +0100
commite2fa16706ce0e07d474460acffa6c249ba7503b1 (patch)
treeba4a907025cb779ee182b78154ce994776f76f79 /parser.go
parent9bc60a23116a1992e56d3a2754df6523bc565e99 (diff)
added .Start and .End to Result
Diffstat (limited to 'parser.go')
-rw-r--r--parser.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/parser.go b/parser.go
index f008d33..c2fbb3e 100644
--- a/parser.go
+++ b/parser.go
@@ -109,6 +109,8 @@ func Regex(pattern string) Parser {
return NewParser(pattern, func(ps *State, node *Result) {
ps.WS(ps)
if match := re.FindString(ps.Get()); match != "" {
+ node.Start = ps.Pos
+ node.End = ps.Pos + len(match)
ps.Advance(len(match))
node.Token = match
return
@@ -128,6 +130,8 @@ func Exact(match string) Parser {
return
}
+ node.Start = ps.Pos
+ node.End = ps.Pos + 1
ps.Advance(1)
node.Token = match
@@ -141,6 +145,9 @@ func Exact(match string) Parser {
return
}
+ node.Start = ps.Pos
+ node.End = ps.Pos + len(match)
+
ps.Advance(len(match))
node.Token = match
@@ -241,6 +248,8 @@ func charsImpl(matcher string, stopOn bool, repetition ...int) Parser {
return
}
+ node.Start = ps.Pos
+ node.End = ps.Pos + matched
node.Token = ps.Input[ps.Pos : ps.Pos+matched]
ps.Advance(matched)
}
@@ -265,6 +274,8 @@ func Until(terminators ...string) Parser {
if ps.Pos == startPos {
ps.ErrorHere("something")
}
+ node.Start = startPos
+ node.End = ps.Pos
node.Token = ps.Input[startPos:ps.Pos]
})
}