Skip to content

Commit

Permalink
Fix type parsing of iterators in range-loops
Browse files Browse the repository at this point in the history
  • Loading branch information
5nord committed Jul 9, 2024
1 parent 89a0fda commit d48a371
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions ttcn3/syntax/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ type (
Tok Token
LParen Token
VarTok Token
Type TypeSpec
Var *Ident
InTok Token
Range Expr
Expand Down
19 changes: 18 additions & 1 deletion ttcn3/syntax/nodes_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion ttcn3/syntax/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2408,7 +2408,7 @@ func (p *parser) parseStmt() Stmt {
case LBRACK:
return p.parseAltGuard()
case FOR:
if p.peek(4).Kind() == IN || p.peek(5).Kind() == IN {
if p.peek(4).Kind() == IN || p.peek(5).Kind() == IN || p.peek(6).Kind() == IN {
return p.parseForRangeLoop()
}
return p.parseForLoop()
Expand Down Expand Up @@ -2485,6 +2485,9 @@ func (p *parser) parseForRangeLoop() *ForRangeStmt {
x.LParen = p.expect(LPAREN)
if p.tok == VAR {
x.VarTok = p.consume()
if p.peek(2).Kind() != IN {
x.Type = p.parseTypeSpec()
}
x.Var = p.parseName()
} else {
x.Var = p.parseIdent()
Expand Down
1 change: 1 addition & 0 deletions ttcn3/syntax/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ func TestStmts(t *testing.T) {
{pass, `for (i:=x; i<23; i:=i+1) {}`},
{pass, `for (x in {1,2,3}) {}`},
{pass, `for (var x in a) {}`},
{pass, `for (var integer x in a) {}`},
{pass, `while (23) {}`},
{pass, `do {} while (23);`},
{pass, `if (1) {}`},
Expand Down

0 comments on commit d48a371

Please sign in to comment.