[refactoring] update ast structure of "InlinHtml" node

This commit is contained in:
Vadym Slizov 2020-09-14 16:36:01 +03:00
parent 7678303cb9
commit 8b4d65ac4d
7 changed files with 22 additions and 22 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -1062,13 +1062,13 @@ unticked_statement:
} }
| T_INLINE_HTML | T_INLINE_HTML
{ {
$$ = &ast.StmtInlineHtml{ast.Node{}, $1.Value} $$ = &ast.StmtInlineHtml{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
InlineHtmlTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| expr ';' | expr ';'
{ {

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -976,13 +976,13 @@ statement:
} }
| T_INLINE_HTML | T_INLINE_HTML
{ {
$$ = &ast.StmtInlineHtml{ast.Node{}, $1.Value} $$ = &ast.StmtInlineHtml{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
InlineHtmlTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| expr ';' | expr ';'
{ {

View File

@ -535,6 +535,7 @@ func (n *StmtIf) Accept(v NodeVisitor) {
// StmtInlineHtml node // StmtInlineHtml node
type StmtInlineHtml struct { type StmtInlineHtml struct {
Node Node
InlineHtmlTkn *token.Token
Value []byte Value []byte
} }

View File

@ -200,3 +200,7 @@ func (v *FilterTokens) StmtEcho(n *ast.StmtEcho) {
n.SeparatorTkns = nil n.SeparatorTkns = nil
n.SemiColonTkn = nil n.SemiColonTkn = nil
} }
func (v *FilterTokens) StmtInlineHtml(n *ast.StmtInlineHtml) {
n.InlineHtmlTkn = nil
}

View File

@ -2555,18 +2555,13 @@ func (p *Printer) printStmtAltIf(n *ast.StmtIf) {
p.printToken(n.SemiColonTkn, ";") p.printToken(n.SemiColonTkn, ";")
} }
func (p *Printer) printStmtInlineHTML(n ast.Vertex) { func (p *Printer) printStmtInlineHTML(n *ast.StmtInlineHtml) {
nn := n.(*ast.StmtInlineHtml)
p.printFreeFloating(nn, token.Start)
if p.s == PhpState && !bytes.Contains(p.lastWrite, []byte("?>")) { if p.s == PhpState && !bytes.Contains(p.lastWrite, []byte("?>")) {
p.write([]byte("?>")) p.write([]byte("?>"))
} }
p.SetState(HtmlState) p.SetState(HtmlState)
p.write(nn.Value) p.printToken(n.InlineHtmlTkn, string(n.Value))
p.printFreeFloating(nn, token.End)
} }
func (p *Printer) printStmtInterface(n ast.Vertex) { func (p *Printer) printStmtInterface(n ast.Vertex) {