vfmt: make work with comptime

pull/4971/head
Alexander Medvednikov 2020-05-27 03:33:37 +02:00
parent 23c0bb600c
commit 7c9279c447
5 changed files with 14 additions and 10 deletions

View File

@ -6,7 +6,7 @@ const (
port = 8082 port = 8082
) )
pub struct App { struct App {
pub mut: pub mut:
vweb vweb.Context // TODO embed vweb vweb.Context // TODO embed
cnt int cnt int

View File

@ -359,7 +359,6 @@ pub fn (mut f Fmt) stmt(node ast.Stmt) {
f.stmts(it.stmts) f.stmts(it.stmts)
f.writeln('}') f.writeln('}')
} }
ast.ComptimeCall {}
} }
} }
@ -539,6 +538,7 @@ pub fn (mut f Fmt) expr(node ast.Expr) {
ast.CharLiteral { ast.CharLiteral {
f.write('`$it.val`') f.write('`$it.val`')
} }
ast.ComptimeCall {}
ast.ConcatExpr { ast.ConcatExpr {
for i, val in it.vals { for i, val in it.vals {
if i != 0 { if i != 0 {

View File

@ -55,6 +55,7 @@ fn (mut p Parser) hash() ast.HashStmt {
} }
fn (mut p Parser) vweb() ast.ComptimeCall { fn (mut p Parser) vweb() ast.ComptimeCall {
p.check(.dollar)
p.check(.name) // skip `vweb.html()` TODO p.check(.name) // skip `vweb.html()` TODO
p.check(.dot) p.check(.dot)
p.check(.name) p.check(.name)

View File

@ -386,13 +386,7 @@ pub fn (mut p Parser) top_stmt() ast.Stmt {
return p.struct_decl() return p.struct_decl()
} }
.dollar { .dollar {
if p.peek_tok.kind == .key_if { return p.comp_if()
return p.comp_if()
} else if p.peek_tok.kind == .name {
return ast.ExprStmt{
expr: p.vweb()
}
}
} }
.hash { .hash {
return p.hash() return p.hash()
@ -501,7 +495,13 @@ pub fn (mut p Parser) stmt() ast.Stmt {
return p.return_stmt() return p.return_stmt()
} }
.dollar { .dollar {
return p.comp_if() if p.peek_tok.kind == .key_if {
return p.comp_if()
} else if p.peek_tok.kind == .name {
return ast.ExprStmt{
expr: p.vweb()
}
}
} }
.key_continue, .key_break { .key_continue, .key_break {
tok := p.tok tok := p.tok

View File

@ -283,9 +283,12 @@ fn handle_conn<T>(conn net.Socket, app mut T) {
$if debug { $if debug {
println('action=$action') println('action=$action')
} }
app.$action()
/*
app.$action() or { app.$action() or {
conn.send_string(http_404) or {} conn.send_string(http_404) or {}
} }
*/
conn.close() or {} conn.close() or {}
app.reset() app.reset()
} }