diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 870cc175bc..48d020849f 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -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 diff --git a/vlib/v/ast/str.v b/vlib/v/ast/str.v index 03601aa0b2..1b627e97f0 100644 --- a/vlib/v/ast/str.v +++ b/vlib/v/ast/str.v @@ -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]' + } + } +}