v2: ParExpr; mut var decl
parent
7f5a15372f
commit
6a198df3af
|
@ -11,7 +11,7 @@ import (
|
|||
pub type Expr = InfixExpr | IfExpr | StringLiteral | IntegerLiteral | CharLiteral |
|
||||
FloatLiteral | Ident | CallExpr | BoolLiteral | StructInit | ArrayInit | SelectorExpr | PostfixExpr |
|
||||
AssignExpr | PrefixExpr | MethodCallExpr | IndexExpr | RangeExpr | MatchExpr |
|
||||
CastExpr | EnumVal | Assoc | SizeOf | None | MapInit | OrExpr
|
||||
CastExpr | EnumVal | Assoc | SizeOf | None | MapInit | OrExpr | ParExpr
|
||||
|
||||
pub type Stmt = VarDecl | GlobalDecl | FnDecl | Return | Module | Import | ExprStmt |
|
||||
ForStmt | StructDecl | ForCStmt | ForInStmt | CompIf | ConstDecl | Attr | BranchStmt |
|
||||
|
@ -433,6 +433,12 @@ pub:
|
|||
stmts []Stmt
|
||||
}
|
||||
|
||||
// `(3+4)`
|
||||
pub struct ParExpr {
|
||||
pub:
|
||||
expr Expr
|
||||
}
|
||||
|
||||
pub struct AssignExpr {
|
||||
pub:
|
||||
op token.Kind
|
||||
|
|
|
@ -101,6 +101,9 @@ fn (f mut Fmt) stmt(node ast.Stmt) {
|
|||
match node {
|
||||
ast.AssignStmt {
|
||||
for i, left in it.left {
|
||||
if left.var_info().is_mut {
|
||||
f.write('mut ')
|
||||
}
|
||||
f.expr(left)
|
||||
if i < it.left.len - 1 {
|
||||
f.write(', ')
|
||||
|
@ -426,6 +429,11 @@ fn (f mut Fmt) expr(node ast.Expr) {
|
|||
f.write(it.var_name + ' := ')
|
||||
f.expr(it.expr)
|
||||
}
|
||||
ast.ParExpr{
|
||||
f.write('(')
|
||||
f.expr(it.expr)
|
||||
f.write(')')
|
||||
}
|
||||
ast.PostfixExpr {
|
||||
f.expr(it.expr)
|
||||
f.write(it.op.str())
|
||||
|
|
|
@ -684,6 +684,9 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,table.Type) {
|
|||
p.check(.lpar)
|
||||
node,typ = p.expr(0)
|
||||
p.check(.rpar)
|
||||
node = ast.ParExpr{
|
||||
expr: node
|
||||
}
|
||||
}
|
||||
.key_if {
|
||||
node = p.if_expr()
|
||||
|
|
Loading…
Reference in New Issue