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())
|
||||
|
|
|
@ -57,7 +57,7 @@ pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
|
|||
pref: &pref.Preferences{}
|
||||
scope: scope
|
||||
// scope: &ast.Scope{start_pos: 0, parent: 0}
|
||||
|
||||
|
||||
}
|
||||
p.init_parse_fns()
|
||||
p.read_first_token()
|
||||
|
@ -329,7 +329,7 @@ pub fn (p mut Parser) stmt() ast.Stmt {
|
|||
return ast.ExprStmt{
|
||||
expr: expr
|
||||
// typ: typ
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -621,7 +621,7 @@ pub fn (p mut Parser) name_expr() ast.Expr {
|
|||
p.expr_mod = ''
|
||||
return ast.EnumVal{
|
||||
enum_name: enum_name // lp.prepend_mod(enum_name)
|
||||
|
||||
|
||||
val: val
|
||||
pos: p.tok.position()
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -1165,11 +1168,11 @@ fn (p mut Parser) if_expr() ast.Expr {
|
|||
stmts: stmts
|
||||
else_stmts: else_stmts
|
||||
// typ: typ
|
||||
|
||||
|
||||
pos: pos
|
||||
has_else: has_else
|
||||
// left: left
|
||||
|
||||
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
@ -1585,12 +1588,12 @@ fn (p mut Parser) var_decl_and_assign_stmt() ast.Stmt {
|
|||
return ast.VarDecl{
|
||||
name: ident.name
|
||||
// name2: name2
|
||||
|
||||
|
||||
expr: expr // p.expr(token.lowest_prec)
|
||||
|
||||
|
||||
is_mut: info0.is_mut
|
||||
// typ: typ
|
||||
|
||||
|
||||
pos: p.tok.position()
|
||||
}
|
||||
// return p.var_decl(ident[0], exprs[0])
|
||||
|
@ -1728,7 +1731,7 @@ fn (p mut Parser) match_expr() ast.Expr {
|
|||
blocks: blocks
|
||||
match_exprs: match_exprs
|
||||
// typ: typ
|
||||
|
||||
|
||||
cond: cond
|
||||
}
|
||||
return node
|
||||
|
|
Loading…
Reference in New Issue