Skip to content

Commit 1c1fd01

Browse files
Parse response redirects
1 parent 13fa4e7 commit 1c1fd01

22 files changed

+258
-127
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ linters:
8181
checks:
8282
- all
8383

84+
gocognit:
85+
min-complexity: 40
86+
8487
gosec:
8588
excludes:
8689
- G104 # Errors not checked, handled by errcheck

internal/syntax/ast/ast.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ type Node interface {
2020
// File is an ast [Node] representing a single .http file.
2121
type File struct {
2222
// Name is the name of the file.
23-
Name string
23+
Name string `yaml:"name"`
2424

2525
// Statements is the list of ast statements in the file.
26-
Statements []Statement
26+
Statements []Statement `yaml:"statements"`
2727

2828
// Type is the type of the node, in this case [KindFile].
29-
Type Kind
29+
Type Kind `yaml:"type"`
3030
}
3131

3232
// Start returns the first token in a file.

internal/syntax/ast/ast_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,32 @@ func TestNode(t *testing.T) {
406406
end: token.Token{Kind: token.LeftAngle, Start: 31, End: 32},
407407
kind: ast.KindBodyFile,
408408
},
409+
{
410+
name: "response redirect",
411+
node: ast.ResponseRedirect{
412+
File: ast.TextLiteral{
413+
Value: "response.json",
414+
Token: token.Token{Kind: token.Text, Start: 34, End: 47},
415+
Type: ast.KindTextLiteral,
416+
},
417+
Type: ast.KindResponseRedirect,
418+
Token: token.Token{Kind: token.RightAngle, Start: 31, End: 32},
419+
},
420+
start: token.Token{Kind: token.RightAngle, Start: 31, End: 32},
421+
end: token.Token{Kind: token.Text, Start: 34, End: 47},
422+
kind: ast.KindResponseRedirect,
423+
},
424+
{
425+
name: "response redirect no file",
426+
node: ast.ResponseRedirect{
427+
File: nil,
428+
Token: token.Token{Kind: token.RightAngle, Start: 31, End: 32},
429+
Type: ast.KindResponseRedirect,
430+
},
431+
start: token.Token{Kind: token.RightAngle, Start: 31, End: 32},
432+
end: token.Token{Kind: token.RightAngle, Start: 31, End: 32},
433+
kind: ast.KindResponseRedirect,
434+
},
409435
{
410436
name: "empty file",
411437
node: ast.File{Type: ast.KindFile},

internal/syntax/ast/expression.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ type Expression interface {
1111
// Ident is a named identifier expression.
1212
type Ident struct {
1313
// Name is the ident's name.
14-
Name string
14+
Name string `yaml:"name"`
1515

1616
// The [token.Ident] token.
17-
Token token.Token
17+
Token token.Token `yaml:"token"`
1818

1919
// Type is the kind of ast node, in this case [KindIdent].
20-
Type Kind
20+
Type Kind `yaml:"type"`
2121
}
2222

2323
// Start returns the first token in the Ident, which is
@@ -43,13 +43,13 @@ func (i Ident) expressionNode() {}
4343
// TextLiteral is a literal text expression.
4444
type TextLiteral struct {
4545
// The text value (unquoted)
46-
Value string
46+
Value string `yaml:"value"`
4747

4848
// The [token.Text] token.
49-
Token token.Token
49+
Token token.Token `yaml:"token"`
5050

5151
// Type is [KindTextLiteral].
52-
Type Kind
52+
Type Kind `yaml:"type"`
5353
}
5454

5555
// Start returns the first token of the TextLiteral, which is
@@ -75,13 +75,13 @@ func (t TextLiteral) expressionNode() {}
7575
// URL is a literal URL expression.
7676
type URL struct {
7777
// The url value (unquoted)
78-
Value string
78+
Value string `yaml:"value"`
7979

8080
// The [token.URL] token.
81-
Token token.Token
81+
Token token.Token `yaml:"token"`
8282

8383
// Type is [KindURL].
84-
Type Kind
84+
Type Kind `yaml:"type"`
8585
}
8686

8787
// Start returns the first token of the URL, which is
@@ -107,16 +107,16 @@ func (u URL) expressionNode() {}
107107
// Interp is a text interpolation expression.
108108
type Interp struct {
109109
// Expr is the expression inside the interpolation.
110-
Expr Expression
110+
Expr Expression `yaml:"expr"`
111111

112112
// Open is the opening interpolation token.
113-
Open token.Token
113+
Open token.Token `yaml:"open"`
114114

115115
// Close is the closing interpolation token.
116-
Close token.Token
116+
Close token.Token `yaml:"close"`
117117

118118
// Type is [KindInterp].
119-
Type Kind
119+
Type Kind `yaml:"type"`
120120
}
121121

122122
// Start returns the first token of the interpolation, i.e
@@ -154,17 +154,17 @@ func (i Interp) expressionNode() {}
154154
type InterpolatedExpression struct {
155155
// Left is the expression before the interp, it may itself
156156
// be any other valid expression, including more nested InterpolatedExpressions.
157-
Left Expression
157+
Left Expression `yaml:"left"`
158158

159159
// Right is the expression immediately after the interp, like Left
160160
// it may also be any valid expression.
161-
Right Expression
161+
Right Expression `yaml:"right"`
162162

163163
// Interp is the [Interp] expression in between Left and Right.
164-
Interp Interp
164+
Interp Interp `yaml:"interp"`
165165

166166
// Type is [KindInterpolatedExpression].
167-
Type Kind
167+
Type Kind `yaml:"type"`
168168
}
169169

170170
// Start returns the first token associated with the left expression if there is one,
@@ -198,10 +198,10 @@ func (i InterpolatedExpression) expressionNode() {}
198198
// Body is the http body expression.
199199
type Body struct {
200200
// Token is the [token.Body] token.
201-
Token token.Token
201+
Token token.Token `yaml:"token"`
202202

203203
// Type is [KindBody].
204-
Type Kind
204+
Type Kind `yaml:"type"`
205205
}
206206

207207
// Start returns the first token associated with the body, which
@@ -227,13 +227,13 @@ func (b Body) expressionNode() {}
227227
// BodyFile is a http body from a filepath.
228228
type BodyFile struct {
229229
// Value is the expression of the filepath.
230-
Value Expression
230+
Value Expression `yaml:"value"`
231231

232232
// Token is the [token.LeftAngle] token.
233-
Token token.Token
233+
Token token.Token `yaml:"token"`
234234

235235
// Type is [KindBodyFile].
236-
Type Kind
236+
Type Kind `yaml:"type"`
237237
}
238238

239239
// Start returns the first token associated with the BodyFile, which

internal/syntax/ast/kind.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
KindInterpolatedExpression // InterpolatedExpression
2323
KindBody // Body
2424
KindBodyFile // BodyFile
25+
KindResponseRedirect // ResponseRedirect
2526
)
2627

2728
// MarshalText implements [encoding.TextMarshaler] for [Kind].

internal/syntax/ast/kind_string.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)