node: support leaving php context

This commit is contained in:
mappu 2020-04-05 17:11:11 +12:00
parent d3f238cf01
commit 1224a5906a
2 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,14 @@
<?php
$header = "bar";
?>
<!DOCTYPE html>
<html>
<h1><?=$header?></h1>
<ul>
<?php for($i = 0; $i < 3; ++$i) { ?>
<li><?=$i?></li>
<?php } ?>
</ul>
</html>

10
node.go
View File

@ -3,6 +3,7 @@ package main
import (
"fmt"
"reflect"
"strconv"
//"strconv"
"strings"
@ -376,6 +377,15 @@ func convert(n_ node.Node) (string, error) {
}
return "fmt.Print(" + strings.Join(args, ", ") + ")\n", nil // newline - standalone statement
case *stmt.InlineHtml:
// Convert into fmt.Print
// TODO the result from strconv.Quote is not that nice to maintain if there are multiple newlines
// Should convert it into a backtick-delimeted multiline string instead
return "fmt.Print(" + strconv.Quote(n.Value) + ")\n", nil // newline - standalone statement
case *stmt.Nop:
return "", nil
//
// assign
//