Skip to content

Commit

Permalink
parse (expr)
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Dec 24, 2024
1 parent caf3607 commit 3f7891d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ build:
test: build
v test compiler
v tests/run_tests.vsh

fmt:
v fmt -w .
7 changes: 7 additions & 0 deletions compiler/ast/Expr.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module ast

pub type Expr = EmptyExpr
| ParenExpr
| Ident
| CharLiteral
| IntegerLiteral
Expand All @@ -23,6 +24,12 @@ pub:

pub const empty_expr = Expr(EmptyExpr{})

pub struct ParenExpr {
pub:
expr Expr
pos FilePos
}

pub struct Ident {
pub:
name string
Expand Down
6 changes: 6 additions & 0 deletions compiler/parser/expr.v
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ fn (mut p Parser) parse_primary_expr() ast.Expr {
expr = p.parse_ident_expr()
}
}
.lparen {
pos := p.tok.pos
p.next()
expr = ast.ParenExpr{p.parse_expr(), pos + p.tok.pos}
p.expect(.rparen)
}
.kw_if {
expr = p.parse_if_expr()
}
Expand Down
2 changes: 1 addition & 1 deletion tests/valid/let_stmt.ri
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let x = 1;

fn main() {
let y = 1;
let abc, def = 1;
let abc, def = (11 + 15) / 99;

fn inside() {
let inside_var = false;
Expand Down

0 comments on commit 3f7891d

Please sign in to comment.