From cef80b96a4b987b590dc080bbfd40c042cb98d3e Mon Sep 17 00:00:00 2001 From: Thomas Pelletier Date: Mon, 28 Aug 2023 11:02:16 -0400 Subject: [PATCH] parser: add raw to integers (#890) --- unstable/parser.go | 6 ++++++ unstable/parser_test.go | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/unstable/parser.go b/unstable/parser.go index a8eb0529..50358a44 100644 --- a/unstable/parser.go +++ b/unstable/parser.go @@ -1013,6 +1013,7 @@ func (p *Parser) parseIntOrFloatOrDateTime(b []byte) (reference, []byte, error) return p.builder.Push(Node{ Kind: Float, Data: b[:3], + Raw: p.Range(b[:3]), }), b[3:], nil case 'n': if !scanFollowsNan(b) { @@ -1022,6 +1023,7 @@ func (p *Parser) parseIntOrFloatOrDateTime(b []byte) (reference, []byte, error) return p.builder.Push(Node{ Kind: Float, Data: b[:3], + Raw: p.Range(b[:3]), }), b[3:], nil case '+', '-': return p.scanIntOrFloat(b) @@ -1146,6 +1148,7 @@ func (p *Parser) scanIntOrFloat(b []byte) (reference, []byte, error) { return p.builder.Push(Node{ Kind: Integer, Data: b[:i], + Raw: p.Range(b[:i]), }), b[i:], nil } @@ -1169,6 +1172,7 @@ func (p *Parser) scanIntOrFloat(b []byte) (reference, []byte, error) { return p.builder.Push(Node{ Kind: Float, Data: b[:i+3], + Raw: p.Range(b[:i+3]), }), b[i+3:], nil } @@ -1180,6 +1184,7 @@ func (p *Parser) scanIntOrFloat(b []byte) (reference, []byte, error) { return p.builder.Push(Node{ Kind: Float, Data: b[:i+3], + Raw: p.Range(b[:i+3]), }), b[i+3:], nil } @@ -1202,6 +1207,7 @@ func (p *Parser) scanIntOrFloat(b []byte) (reference, []byte, error) { return p.builder.Push(Node{ Kind: kind, Data: b[:i], + Raw: p.Range(b[:i]), }), b[i:], nil } diff --git a/unstable/parser_test.go b/unstable/parser_test.go index 42e62928..b86f7fcd 100644 --- a/unstable/parser_test.go +++ b/unstable/parser_test.go @@ -569,9 +569,9 @@ key5 = [ # Next to start of inline array. // --- // 1:1->1:1 (0->0) | KeyValue [] // 1:1->1:1 (0->0) | Array [] - // 1:1->1:1 (0->0) | Integer [1] - // 1:1->1:1 (0->0) | Integer [2] - // 1:1->1:1 (0->0) | Integer [3] + // 19:11->19:12 (396->397) | Integer [1] + // 19:14->19:15 (399->400) | Integer [2] + // 19:17->19:18 (402->403) | Integer [3] // 19:1->19:6 (386->391) | Key [array] // 19:21->19:46 (406->431) | Comment [# Next to one-line array.] // --- @@ -583,12 +583,12 @@ key5 = [ # Next to start of inline array. // 1:1->1:1 (0->0) | Array [] // 23:10->23:42 (483->515) | Comment [# Next to start of inline array.] // 24:3->24:38 (518->553) | Comment [# Second line before array content.] - // 1:1->1:1 (0->0) | Integer [1] + // 25:3->25:4 (556->557) | Integer [1] // 25:6->25:30 (559->583) | Comment [# Next to first element.] // 26:3->26:25 (586->608) | Comment [# After first element.] // 27:3->27:27 (611->635) | Comment [# Before second element.] - // 1:1->1:1 (0->0) | Integer [2] - // 1:1->1:1 (0->0) | Integer [3] + // 28:3->28:4 (638->639) | Integer [2] + // 29:3->29:4 (643->644) | Integer [3] // 29:6->29:28 (646->668) | Comment [# Next to last element] // 30:3->30:24 (671->692) | Comment [# After last element.] // 23:1->23:5 (474->478) | Key [key5]