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