@@ -14,199 +14,199 @@ type Node interface {
1414
1515// Source is the root node of a Scanspec AST.
1616type Source struct {
17- Block Block `@@ `
17+ Block Block `parser:"@@" `
1818}
1919
2020type Block struct {
21- Statements []* Statement `EOL* ( @@ ( EOL+ @@ )* ) EOL*`
21+ Statements []* Statement `parser:" EOL* ( @@ ( EOL+ @@ )* ) EOL*" `
2222}
2323
2424type 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
3838type VarDecl struct {
39- VarSpec VarSpec `" var" @@`
39+ VarSpec VarSpec `parser:"' var' @@" `
4040}
4141
4242type ScanStmt struct {
4343 Pos lexer.Position
4444
45- RefList []Reference `" scan" @@ ( "," @@ )*`
45+ RefList []Reference `parser:"' scan' @@ ( ',' @@ )*" `
4646}
4747
4848type ScanlnStmt struct {
4949 Pos lexer.Position
5050
51- RefList []Reference `" scanln" @@ ( "," @@ )*`
51+ RefList []Reference `parser:"' scanln' @@ ( ',' @@ )*" `
5252}
5353
5454type CheckStmt struct {
5555 Pos lexer.Position
5656
57- ExprList []Expr `" check" @@ ( "," @@ )*`
57+ ExprList []Expr `parser:"' check' @@ ( ',' @@ )*" `
5858}
5959
6060type IfStmt struct {
61- Branches []IfBranch `( @@ ( EOL* " else" @@ )* ) EOL* " end"`
61+ Branches []IfBranch `parser:" ( @@ ( EOL* ' else' @@ )* ) EOL* ' end' "`
6262}
6363
6464type IfBranch struct {
65- Condition * Expr `( "if" @@ )? EOL+`
66- Block Block `@@ `
65+ Condition * Expr `parser:"( 'if' @@ )? EOL+" `
66+ Block Block `parser:"@@" `
6767}
6868
6969type 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
7676type EOLStmt struct {
7777 Pos lexer.Position
7878
79- EOL bool `@" eol"`
79+ EOL bool `parser:"@' eol' "`
8080}
8181
8282type EOFStmt struct {
8383 Pos lexer.Position
8484
85- EOF bool `@" eof"`
85+ EOF bool `parser:"@' eof' "`
8686}
8787
8888type VarSpec struct {
89- IdentList []string `@Ident ( "," @Ident )*`
90- Type Type `@@ `
89+ IdentList []string `parser:" @Ident ( ',' @Ident )*" `
90+ Type Type `parser:"@@" `
9191}
9292
9393type AssignStmt struct {
9494 Pos lexer.Position
9595
96- Ref Reference `@@ `
97- Value Expr `"=" @@`
96+ Ref Reference `parser:"@@" `
97+ Value Expr `parser:"'=' @@" `
9898}
9999
100100type Type struct {
101- TypeName * string ` @Type`
102- TypeLit * TypeLit `| @@`
101+ TypeName * string `parser:" @Type" `
102+ TypeLit * TypeLit `parser:" | @@" `
103103}
104104
105105type TypeLit struct {
106- ArrayType * ArrayType `@@ `
106+ ArrayType * ArrayType `parser:"@@" `
107107}
108108
109109type ArrayType struct {
110- ArrayLength Expr `"[" @@ "] "`
111- ElementType Type `@@ `
110+ ArrayLength Expr `parser:"'[' @@ ']' "`
111+ ElementType Type `parser:"@@" `
112112}
113113
114114type 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
121121type 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
129129type LogicalOr struct {
130130 Pos lexer.Position
131131
132- Left * LogicalAnd `@@ `
133- Right []* OpLogicalAnd `@@*`
132+ Left * LogicalAnd `parser:"@@" `
133+ Right []* OpLogicalAnd `parser:" @@*" `
134134}
135135
136136type OpLogicalOr struct {
137137 Pos lexer.Position
138138
139- LogicalOr * LogicalOr `"|" "|" @@`
139+ LogicalOr * LogicalOr `parser:"'|' '|' @@" `
140140}
141141
142142type LogicalAnd struct {
143143 Pos lexer.Position
144144
145- Left * Relative `@@ `
146- Right []* OpRelative `@@*`
145+ Left * Relative `parser:"@@" `
146+ Right []* OpRelative `parser:" @@*" `
147147}
148148
149149type OpLogicalAnd struct {
150150 Pos lexer.Position
151151
152- LogicalAnd * LogicalAnd `"&" "&" @@`
152+ LogicalAnd * LogicalAnd `parser:"'&' '&' @@" `
153153}
154154
155155type Relative struct {
156- Left * Addition `@@ `
157- Right []* OpAddition `@@*`
156+ Left * Addition `parser:"@@" `
157+ Right []* OpAddition `parser:" @@*" `
158158}
159159
160160type OpRelative struct {
161161 Pos lexer.Position
162162
163- Operator Operator `@("=" "=" | "!" "=" | "<" "=" | ">" "=" | "<" | ">") `
164- Relative * Relative `@@ `
163+ Operator Operator `parser:"@('=' '=' | '!' '=' | '<' '=' | '>' '=' | '<' | '>')" `
164+ Relative * Relative `parser:"@@" `
165165}
166166
167167type Addition struct {
168- Left * Multiplication `@@ `
169- Right []* OpMultiplication `@@*`
168+ Left * Multiplication `parser:"@@" `
169+ Right []* OpMultiplication `parser:" @@*" `
170170}
171171
172172type OpAddition struct {
173173 Pos lexer.Position
174174
175- Operator Operator `@("+" | "-") `
176- Addition * Addition `@@ `
175+ Operator Operator `parser:"@('+' | '-')" `
176+ Addition * Addition `parser:"@@" `
177177}
178178
179179type Multiplication struct {
180- Unary * Unary `@@ `
181- Exponent * Primary `( "*" "*" @@ )?`
180+ Unary * Unary `parser:"@@" `
181+ Exponent * Primary `parser:"( '*' '*' @@ )?" `
182182}
183183
184184type OpMultiplication struct {
185185 Pos lexer.Position
186186
187- Operator Operator `@("*" | "/") `
188- Factor * Multiplication `@@ `
187+ Operator Operator `parser:"@('*' | '/')" `
188+ Factor * Multiplication `parser:"@@" `
189189}
190190
191191type Unary struct {
192- Value * Primary `( "+" ? @@`
193- Negated * Primary `| "-" @@ )`
192+ Value * Primary `parser:"( '+' ? @@" `
193+ Negated * Primary `parser:"| '-' @@ )" `
194194}
195195
196196type 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
206206type 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
212212type Operator string
@@ -217,25 +217,25 @@ func (o *Operator) Capture(s []string) error {
217217}
218218
219219type 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
225225type Variable struct {
226- Ident string `@Ident`
227- Indices []Expr `( "[" @@ "]" )?`
226+ Ident string `parser:" @Ident" `
227+ Indices []Expr `parser:"( '[' @@ ']' )?" `
228228}
229229
230230type CallExpr struct {
231- Ident string `@Ident`
232- Args []Expr `"(" ( @@ ( "," @@ )* )? ") "`
231+ Ident string `parser:" @Ident" `
232+ Args []Expr `parser:"'(' ( @@ ( ',' @@ )* )? ')' "`
233233}
234234
235235type 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
241241func (Source ) node () {}
0 commit comments