Skip to content

Commit 5094fb5

Browse files
authored
feat: add Ranges to ForExpressions (#1264)
1 parent 82cc59a commit 5094fb5

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

parser/v2/forexpressionparser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ func (forExpressionParser) Parse(pi *parse.Input) (n Node, matched bool, err err
5252
return r, true, parse.Error("for: "+unterminatedMissingEnd, pi.Position())
5353
}
5454

55+
r.Range = NewRange(pi.PositionAt(start), pi.Position())
5556
return r, true, nil
5657
}

parser/v2/forexpressionparser_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ func TestForExpressionParser(t *testing.T) {
4545
TrailingSpace: "\n",
4646
},
4747
},
48+
Range: Range{
49+
From: Position{Index: 0, Line: 0, Col: 0},
50+
To: Position{Index: 20, Line: 2, Col: 4},
51+
},
4852
},
4953
},
5054
{
@@ -79,6 +83,10 @@ func TestForExpressionParser(t *testing.T) {
7983
TrailingSpace: "\n",
8084
},
8185
},
86+
Range: Range{
87+
From: Position{Index: 0, Line: 0, Col: 0},
88+
To: Position{Index: 41, Line: 2, Col: 4},
89+
},
8290
},
8391
},
8492
{
@@ -113,6 +121,10 @@ func TestForExpressionParser(t *testing.T) {
113121
TrailingSpace: "\n",
114122
},
115123
},
124+
Range: Range{
125+
From: Position{Index: 0, Line: 0, Col: 0},
126+
To: Position{Index: 45, Line: 2, Col: 4},
127+
},
116128
},
117129
},
118130
{
@@ -170,6 +182,10 @@ func TestForExpressionParser(t *testing.T) {
170182
},
171183
},
172184
},
185+
Range: Range{
186+
From: Position{Index: 0, Line: 0, Col: 0},
187+
To: Position{Index: 61, Line: 2, Col: 5},
188+
},
173189
},
174190
},
175191
{
@@ -227,6 +243,10 @@ func TestForExpressionParser(t *testing.T) {
227243
},
228244
},
229245
},
246+
Range: Range{
247+
From: Position{Index: 0, Line: 0, Col: 0},
248+
To: Position{Index: 60, Line: 2, Col: 5},
249+
},
230250
},
231251
},
232252
}

parser/v2/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,7 @@ type CaseExpression struct {
13681368
type ForExpression struct {
13691369
Expression Expression
13701370
Children []Node
1371+
Range Range
13711372
}
13721373

13731374
func (fe ForExpression) ChildNodes() []Node {

0 commit comments

Comments
 (0)