ast: move all str() methods to ast/str.v

pull/3866/head
Alexander Medvednikov 2020-02-27 21:29:38 +01:00
parent d619944cf5
commit 3204f036da
2 changed files with 41 additions and 41 deletions

View File

@ -516,47 +516,6 @@ pub struct None {
pub:
foo int // todo
}
// string representaiton of expr
pub fn (x Expr) str() string {
match x {
InfixExpr {
return '(${it.left.str()} $it.op.str() ${it.right.str()})'
}
/*
PrefixExpr {
return it.left.str() + it.op.str()
}
*/
IntegerLiteral {
return it.val.str()
}
IntegerLiteral {
return '"$it.val"'
}
else {
return ''
}
}
}
pub fn (node Stmt) str() string {
match node {
VarDecl {
return it.name + ' = ' + it.expr.str()
}
ExprStmt {
return it.expr.str()
}
FnDecl {
return 'fn ${it.name}() { $it.stmts.len stmts }'
}
else {
return '[unhandled stmt str]'
}
}
}
/*
enum BinaryOp {
sum

View File

@ -40,3 +40,44 @@ pub fn (node &FnDecl) str(t &table.Table) string {
}
return f.str()
}
// string representaiton of expr
pub fn (x Expr) str() string {
match x {
InfixExpr {
return '(${it.left.str()} $it.op.str() ${it.right.str()})'
}
/*
PrefixExpr {
return it.left.str() + it.op.str()
}
*/
IntegerLiteral {
return it.val.str()
}
IntegerLiteral {
return '"$it.val"'
}
else {
return ''
}
}
}
pub fn (node Stmt) str() string {
match node {
VarDecl {
return it.name + ' = ' + it.expr.str()
}
ExprStmt {
return it.expr.str()
}
FnDecl {
return 'fn ${it.name}() { $it.stmts.len stmts }'
}
else {
return '[unhandled stmt str]'
}
}
}