Skip to content

Commit

Permalink
fix for syntax parser
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed Aug 18, 2024
1 parent 5b4afe9 commit 2cd7168
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,13 @@ func (p *parser) while() Statement {
func (p *parser) for_() Statement {
pos := p.pos
p.expect(FOR)
p.expect(LPAREN)
p.expect(DOLAR)
name := p.val
p.expect(NAME)
p.expect(IN)
iterable := p.expression()
p.expect(RPAREN)
body := p.block()
return &For{pos, name, iterable, body}
}
Expand Down Expand Up @@ -329,6 +332,7 @@ func (p *parser) call() Expression {
p.next()
subscript := p.expression()
p.expect(RBRACKET)
p.expect(SEMI)
expr = &Subscript{pos, expr, subscript}
} else {
pos := p.pos
Expand Down Expand Up @@ -435,6 +439,7 @@ func (p *parser) list() Expression {
}
}
p.expect(RBRACKET)
p.expect(SEMI)
return &List{pos, values}
}

Expand Down
14 changes: 12 additions & 2 deletions tests/all-syntax-variations.davi
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,28 @@ echo(time());
echo("Test calculation: 1+2*3=");
echo(1 + 2 * 3);

// Variable declaration
$timeHandler = function() {
$time = time();
return($time);
}
echo($timeHandler());

// Variable assignment
$calculationHandler = function() {
return(5 + 5);
}

echo $calculationHandler();

echo time();


// Foreach loop
$list = ["Bozhidar", "Veselinov", "Slaveykov", "Asenov"];
sort($list);
echo($list);
sort($list, lower);
for ($x in $list) {
echo($x);
}

?>

0 comments on commit 2cd7168

Please sign in to comment.