Skip to content

Commit c49096d

Browse files
committed
Fix lint issues
1 parent d36bfe1 commit c49096d

2 files changed

Lines changed: 85 additions & 85 deletions

File tree

ast/ast.go

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -14,199 +14,199 @@ type Node interface {
1414

1515
// Source is the root node of a Scanspec AST.
1616
type Source struct {
17-
Block Block `@@`
17+
Block Block `parser:"@@"`
1818
}
1919

2020
type Block struct {
21-
Statements []*Statement `EOL* ( @@ ( EOL+ @@ )* ) EOL*`
21+
Statements []*Statement `parser:"EOL* ( @@ ( EOL+ @@ )* ) EOL*"`
2222
}
2323

2424
type Statement struct {
2525
Pos lexer.Position
2626

27-
VarDecl *VarDecl ` @@`
28-
ScanStmt *ScanStmt `| @@`
29-
ScanlnStmt *ScanlnStmt `| @@`
30-
CheckStmt *CheckStmt `| @@`
31-
IfStmt *IfStmt `| @@`
32-
ForStmt *ForStmt `| @@`
33-
EOLStmt *EOLStmt `| @@`
34-
EOFStmt *EOFStmt `| @@`
35-
AssignStmt *AssignStmt `| @@`
27+
VarDecl *VarDecl `parser:" @@"`
28+
ScanStmt *ScanStmt `parser:"| @@"`
29+
ScanlnStmt *ScanlnStmt `parser:"| @@"`
30+
CheckStmt *CheckStmt `parser:"| @@"`
31+
IfStmt *IfStmt `parser:"| @@"`
32+
ForStmt *ForStmt `parser:"| @@"`
33+
EOLStmt *EOLStmt `parser:"| @@"`
34+
EOFStmt *EOFStmt `parser:"| @@"`
35+
AssignStmt *AssignStmt `parser:"| @@"`
3636
}
3737

3838
type VarDecl struct {
39-
VarSpec VarSpec `"var" @@`
39+
VarSpec VarSpec `parser:"'var' @@"`
4040
}
4141

4242
type ScanStmt struct {
4343
Pos lexer.Position
4444

45-
RefList []Reference `"scan" @@ ( "," @@ )*`
45+
RefList []Reference `parser:"'scan' @@ ( ',' @@ )*"`
4646
}
4747

4848
type ScanlnStmt struct {
4949
Pos lexer.Position
5050

51-
RefList []Reference `"scanln" @@ ( "," @@ )*`
51+
RefList []Reference `parser:"'scanln' @@ ( ',' @@ )*"`
5252
}
5353

5454
type CheckStmt struct {
5555
Pos lexer.Position
5656

57-
ExprList []Expr `"check" @@ ( "," @@ )*`
57+
ExprList []Expr `parser:"'check' @@ ( ',' @@ )*"`
5858
}
5959

6060
type IfStmt struct {
61-
Branches []IfBranch `( @@ ( EOL* "else" @@ )* ) EOL* "end"`
61+
Branches []IfBranch `parser:"( @@ ( EOL* 'else' @@ )* ) EOL* 'end'"`
6262
}
6363

6464
type IfBranch struct {
65-
Condition *Expr `( "if" @@ )? EOL+`
66-
Block Block `@@`
65+
Condition *Expr `parser:"( 'if' @@ )? EOL+"`
66+
Block Block `parser:"@@"`
6767
}
6868

6969
type ForStmt struct {
70-
Range *RangeClause `"for" ( @@`
71-
Scan *ScanStmt `| @@`
72-
Scanln *ScanlnStmt `| @@ ) EOL+`
73-
Block Block `@@ "end"`
70+
Range *RangeClause `parser:"'for' ( @@"`
71+
Scan *ScanStmt `parser:"| @@"`
72+
Scanln *ScanlnStmt `parser:"| @@ ) EOL+"`
73+
Block Block `parser:"@@ 'end'"`
7474
}
7575

7676
type EOLStmt struct {
7777
Pos lexer.Position
7878

79-
EOL bool `@"eol"`
79+
EOL bool `parser:"@'eol'"`
8080
}
8181

8282
type EOFStmt struct {
8383
Pos lexer.Position
8484

85-
EOF bool `@"eof"`
85+
EOF bool `parser:"@'eof'"`
8686
}
8787

8888
type VarSpec struct {
89-
IdentList []string `@Ident ( "," @Ident )*`
90-
Type Type `@@`
89+
IdentList []string `parser:"@Ident ( ',' @Ident )*"`
90+
Type Type `parser:"@@"`
9191
}
9292

9393
type AssignStmt struct {
9494
Pos lexer.Position
9595

96-
Ref Reference `@@`
97-
Value Expr `"=" @@`
96+
Ref Reference `parser:"@@"`
97+
Value Expr `parser:"'=' @@"`
9898
}
9999

100100
type Type struct {
101-
TypeName *string ` @Type`
102-
TypeLit *TypeLit `| @@`
101+
TypeName *string `parser:" @Type"`
102+
TypeLit *TypeLit `parser:"| @@"`
103103
}
104104

105105
type TypeLit struct {
106-
ArrayType *ArrayType `@@`
106+
ArrayType *ArrayType `parser:"@@"`
107107
}
108108

109109
type ArrayType struct {
110-
ArrayLength Expr `"[" @@ "]"`
111-
ElementType Type `@@`
110+
ArrayLength Expr `parser:"'[' @@ ']'"`
111+
ElementType Type `parser:"@@"`
112112
}
113113

114114
type Reference struct {
115115
Pos lexer.Position
116116

117-
Ident string `@Ident`
118-
Indices []Expr `( "[" @@ "]" )*`
117+
Ident string `parser:"@Ident"`
118+
Indices []Expr `parser:"( '[' @@ ']' )*"`
119119
}
120120

121121
type Expr struct {
122122
Pos lexer.Position
123123
Tokens []lexer.Token
124124

125-
Left *LogicalOr `@@`
126-
Right []*OpLogicalOr `@@*`
125+
Left *LogicalOr `parser:"@@"`
126+
Right []*OpLogicalOr `parser:"@@*"`
127127
}
128128

129129
type LogicalOr struct {
130130
Pos lexer.Position
131131

132-
Left *LogicalAnd `@@`
133-
Right []*OpLogicalAnd `@@*`
132+
Left *LogicalAnd `parser:"@@"`
133+
Right []*OpLogicalAnd `parser:"@@*"`
134134
}
135135

136136
type OpLogicalOr struct {
137137
Pos lexer.Position
138138

139-
LogicalOr *LogicalOr `"|" "|" @@`
139+
LogicalOr *LogicalOr `parser:"'|' '|' @@"`
140140
}
141141

142142
type LogicalAnd struct {
143143
Pos lexer.Position
144144

145-
Left *Relative `@@`
146-
Right []*OpRelative `@@*`
145+
Left *Relative `parser:"@@"`
146+
Right []*OpRelative `parser:"@@*"`
147147
}
148148

149149
type OpLogicalAnd struct {
150150
Pos lexer.Position
151151

152-
LogicalAnd *LogicalAnd `"&" "&" @@`
152+
LogicalAnd *LogicalAnd `parser:"'&' '&' @@"`
153153
}
154154

155155
type Relative struct {
156-
Left *Addition `@@`
157-
Right []*OpAddition `@@*`
156+
Left *Addition `parser:"@@"`
157+
Right []*OpAddition `parser:"@@*"`
158158
}
159159

160160
type OpRelative struct {
161161
Pos lexer.Position
162162

163-
Operator Operator `@("=" "=" | "!" "=" | "<" "=" | ">" "=" | "<" | ">")`
164-
Relative *Relative `@@`
163+
Operator Operator `parser:"@('=' '=' | '!' '=' | '<' '=' | '>' '=' | '<' | '>')"`
164+
Relative *Relative `parser:"@@"`
165165
}
166166

167167
type Addition struct {
168-
Left *Multiplication `@@`
169-
Right []*OpMultiplication `@@*`
168+
Left *Multiplication `parser:"@@"`
169+
Right []*OpMultiplication `parser:"@@*"`
170170
}
171171

172172
type OpAddition struct {
173173
Pos lexer.Position
174174

175-
Operator Operator `@("+" | "-")`
176-
Addition *Addition `@@`
175+
Operator Operator `parser:"@('+' | '-')"`
176+
Addition *Addition `parser:"@@"`
177177
}
178178

179179
type Multiplication struct {
180-
Unary *Unary `@@`
181-
Exponent *Primary `( "*" "*" @@ )?`
180+
Unary *Unary `parser:"@@"`
181+
Exponent *Primary `parser:"( '*' '*' @@ )?"`
182182
}
183183

184184
type OpMultiplication struct {
185185
Pos lexer.Position
186186

187-
Operator Operator `@("*" | "/")`
188-
Factor *Multiplication `@@`
187+
Operator Operator `parser:"@('*' | '/')"`
188+
Factor *Multiplication `parser:"@@"`
189189
}
190190

191191
type Unary struct {
192-
Value *Primary `( "+"? @@`
193-
Negated *Primary `| "-" @@ )`
192+
Value *Primary `parser:"( '+'? @@"`
193+
Negated *Primary `parser:"| '-' @@ )"`
194194
}
195195

196196
type Primary struct {
197197
Pos lexer.Position
198198

199-
BasicLit *BasicLit ` @@`
200-
ModuleCallExpr *ModuleCallExpr `| @@`
201-
CallExpr *CallExpr `| @@`
202-
Variable *Variable `| @@`
203-
SubExpr *Expr `| "(" @@ ")"`
199+
BasicLit *BasicLit `parser:" @@"`
200+
ModuleCallExpr *ModuleCallExpr `parser:"| @@"`
201+
CallExpr *CallExpr `parser:"| @@"`
202+
Variable *Variable `parser:"| @@"`
203+
SubExpr *Expr `parser:"| '(' @@ ')'"`
204204
}
205205

206206
type BasicLit struct {
207-
FloatLit *float64 ` @Float`
208-
IntLit *int64 `| @Int`
209-
StringLit *string `| @String`
207+
FloatLit *float64 `parser:" @Float"`
208+
IntLit *int64 `parser:"| @Int"`
209+
StringLit *string `parser:"| @String"`
210210
}
211211

212212
type Operator string
@@ -217,25 +217,25 @@ func (o *Operator) Capture(s []string) error {
217217
}
218218

219219
type RangeClause struct {
220-
Index string `@Ident ":" "="`
221-
Low Expr `@@ "." "." "."`
222-
High Expr `@@`
220+
Index string `parser:"@Ident ':' '='"`
221+
Low Expr `parser:"@@ '.' '.' '.'"`
222+
High Expr `parser:"@@"`
223223
}
224224

225225
type Variable struct {
226-
Ident string `@Ident`
227-
Indices []Expr `( "[" @@ "]" )?`
226+
Ident string `parser:"@Ident"`
227+
Indices []Expr `parser:"( '[' @@ ']' )?"`
228228
}
229229

230230
type CallExpr struct {
231-
Ident string `@Ident`
232-
Args []Expr `"(" ( @@ ( "," @@ )* )? ")"`
231+
Ident string `parser:"@Ident"`
232+
Args []Expr `parser:"'(' ( @@ ( ',' @@ )* )? ')'"`
233233
}
234234

235235
type ModuleCallExpr struct {
236-
Module string `@Ident "."`
237-
Ident string `@Ident "("`
238-
Args []Expr `( @@ ( "," @@ )* )? ")"`
236+
Module string `parser:"@Ident '.'"`
237+
Ident string `parser:"@Ident '('"`
238+
Args []Expr `parser:"( @@ ( ',' @@ )* )? ')'"`
239239
}
240240

241241
func (Source) node() {}

ast/parse.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import (
66
)
77

88
var parser = participle.MustBuild[Source](participle.Lexer(lexer.MustSimple([]lexer.SimpleRule{
9-
{"comment", `#[^\n]*`},
10-
{"whitespace", `[ \t]+`},
11-
{"Float", `\d+\.\d*`},
12-
{"Int", `\d+`},
13-
{"String", `"(\\"|[^"])*"`},
14-
{"Keyword", `end|eof|eol|for|scanln|scan|var`},
15-
{"Type", `\b(bool|float32|float64|int|int64|string)\b`},
16-
{"Ident", `[a-zA-Z_][a-zA-Z0-9_]*`},
17-
{"Punct", `[-[!@#$%^&*()+_={}\|:;"'<,>.?/]|]`},
18-
{"EOL", `[\n\r]+`},
9+
{Name: "comment", Pattern: `#[^\n]*`},
10+
{Name: "whitespace", Pattern: `[ \t]+`},
11+
{Name: "Float", Pattern: `\d+\.\d*`},
12+
{Name: "Int", Pattern: `\d+`},
13+
{Name: "String", Pattern: `"(\\"|[^"])*"`},
14+
{Name: "Keyword", Pattern: `end|eof|eol|for|scanln|scan|var`},
15+
{Name: "Type", Pattern: `\b(bool|float32|float64|int|int64|string)\b`},
16+
{Name: "Ident", Pattern: `[a-zA-Z_][a-zA-Z0-9_]*`},
17+
{Name: "Punct", Pattern: `[-[!@#$%^&*()+_={}\|:;"'<,>.?/]|]`},
18+
{Name: "EOL", Pattern: `[\n\r]+`},
1919
})),
2020
participle.Elide("comment"),
2121
participle.Unquote("String"),

0 commit comments

Comments
 (0)