From e2fa16706ce0e07d474460acffa6c249ba7503b1 Mon Sep 17 00:00:00 2001 From: Özgür Kesim Date: Thu, 28 Nov 2019 15:34:30 +0100 Subject: added .Start and .End to Result --- parser.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'parser.go') 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] }) } -- cgit v1.2.3