diff options
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 |
commit | e2fa16706ce0e07d474460acffa6c249ba7503b1 (patch) | |
tree | ba4a907025cb779ee182b78154ce994776f76f79 /parser.go | |
parent | 9bc60a23116a1992e56d3a2754df6523bc565e99 (diff) |
added .Start and .End to Result
Diffstat (limited to 'parser.go')
-rw-r--r-- | parser.go | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -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] }) } |