[refactoring] update ast structure of "Encapsed", "EncapsedStringPart" and "Heredoc" nodes
This commit is contained in:
parent
e3ad9747f4
commit
e6a23dfa3a
BIN
internal/php5/php5.go
generated
BIN
internal/php5/php5.go
generated
Binary file not shown.
@ -4467,11 +4467,15 @@ backticks_expr:
|
|||||||
}
|
}
|
||||||
| T_ENCAPSED_AND_WHITESPACE
|
| T_ENCAPSED_AND_WHITESPACE
|
||||||
{
|
{
|
||||||
part := &ast.ScalarEncapsedStringPart{ast.Node{}, $1.Value}
|
$$ = []ast.Vertex{
|
||||||
$$ = []ast.Vertex{part}
|
&ast.ScalarEncapsedStringPart{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenPosition($1),
|
||||||
part.GetNode().Position = position.NewTokenPosition($1)
|
},
|
||||||
|
EncapsedStrTkn: $1,
|
||||||
|
Value: $1.Value,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| encaps_list
|
| encaps_list
|
||||||
{
|
{
|
||||||
@ -4593,25 +4597,32 @@ common_scalar:
|
|||||||
}
|
}
|
||||||
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
|
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
|
||||||
{
|
{
|
||||||
encapsed := &ast.ScalarEncapsedStringPart{ast.Node{}, $2.Value}
|
$$ = &ast.ScalarHeredoc{
|
||||||
$$ = &ast.ScalarHeredoc{ast.Node{}, $1.Value, []ast.Vertex{encapsed}}
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokensPosition($1, $3),
|
||||||
// save position
|
},
|
||||||
encapsed.GetNode().Position = position.NewTokenPosition($2)
|
OpenHeredocTkn: $1,
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
Parts: []ast.Vertex{
|
||||||
|
&ast.ScalarEncapsedStringPart{
|
||||||
// save comments
|
Node: ast.Node{
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
Position: position.NewTokenPosition($2),
|
||||||
|
},
|
||||||
|
EncapsedStrTkn: $2,
|
||||||
|
Value: $2.Value,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
CloseHeredocTkn: $3,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| T_START_HEREDOC T_END_HEREDOC
|
| T_START_HEREDOC T_END_HEREDOC
|
||||||
{
|
{
|
||||||
$$ = &ast.ScalarHeredoc{ast.Node{}, $1.Value, nil}
|
$$ = &ast.ScalarHeredoc{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokensPosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $2)
|
},
|
||||||
|
OpenHeredocTkn: $1,
|
||||||
// save comments
|
CloseHeredocTkn: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -5180,23 +5191,25 @@ scalar:
|
|||||||
}
|
}
|
||||||
| '"' encaps_list '"'
|
| '"' encaps_list '"'
|
||||||
{
|
{
|
||||||
$$ = &ast.ScalarEncapsed{ast.Node{}, $2}
|
$$ = &ast.ScalarEncapsed{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokensPosition($1, $3),
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
},
|
||||||
|
OpenQoteTkn: $1,
|
||||||
// save comments
|
Parts: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
CloseQoteTkn: $1,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| T_START_HEREDOC encaps_list T_END_HEREDOC
|
| T_START_HEREDOC encaps_list T_END_HEREDOC
|
||||||
{
|
{
|
||||||
$$ = &ast.ScalarHeredoc{ast.Node{}, $1.Value, $2}
|
$$ = &ast.ScalarHeredoc{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokensPosition($1, $3),
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
},
|
||||||
|
OpenHeredocTkn: $1,
|
||||||
// save comments
|
Parts: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
CloseHeredocTkn: $3,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| T_CLASS_C
|
| T_CLASS_C
|
||||||
{
|
{
|
||||||
@ -5976,14 +5989,16 @@ encaps_list:
|
|||||||
}
|
}
|
||||||
| encaps_list T_ENCAPSED_AND_WHITESPACE
|
| encaps_list T_ENCAPSED_AND_WHITESPACE
|
||||||
{
|
{
|
||||||
encapsed := &ast.ScalarEncapsedStringPart{ast.Node{}, $2.Value}
|
$$ = append(
|
||||||
$$ = append($1, encapsed)
|
$1,
|
||||||
|
&ast.ScalarEncapsedStringPart{
|
||||||
// save position
|
Node: ast.Node{
|
||||||
encapsed.GetNode().Position = position.NewTokenPosition($2)
|
Position: position.NewTokenPosition($2),
|
||||||
|
},
|
||||||
// save comments
|
EncapsedStrTkn: $2,
|
||||||
yylex.(*Parser).setFreeFloating(encapsed, token.Start, $2.SkippedTokens)
|
Value: $2.Value,
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
| encaps_var
|
| encaps_var
|
||||||
{
|
{
|
||||||
@ -5991,14 +6006,16 @@ encaps_list:
|
|||||||
}
|
}
|
||||||
| T_ENCAPSED_AND_WHITESPACE encaps_var
|
| T_ENCAPSED_AND_WHITESPACE encaps_var
|
||||||
{
|
{
|
||||||
encapsed := &ast.ScalarEncapsedStringPart{ast.Node{}, $1.Value}
|
$$ = []ast.Vertex{
|
||||||
$$ = []ast.Vertex{encapsed, $2}
|
&ast.ScalarEncapsedStringPart{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenPosition($1),
|
||||||
encapsed.GetNode().Position = position.NewTokenPosition($1)
|
},
|
||||||
|
EncapsedStrTkn: $1,
|
||||||
// save comments
|
Value: $1.Value,
|
||||||
yylex.(*Parser).setFreeFloating(encapsed, token.Start, $1.SkippedTokens)
|
},
|
||||||
|
$2,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
BIN
internal/php7/php7.go
generated
BIN
internal/php7/php7.go
generated
Binary file not shown.
@ -3878,11 +3878,15 @@ backticks_expr:
|
|||||||
}
|
}
|
||||||
| T_ENCAPSED_AND_WHITESPACE
|
| T_ENCAPSED_AND_WHITESPACE
|
||||||
{
|
{
|
||||||
part := &ast.ScalarEncapsedStringPart{ast.Node{}, $1.Value}
|
$$ = []ast.Vertex{
|
||||||
$$ = []ast.Vertex{part}
|
&ast.ScalarEncapsedStringPart{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenPosition($1),
|
||||||
part.GetNode().Position = position.NewTokenPosition($1)
|
},
|
||||||
|
EncapsedStrTkn: $1,
|
||||||
|
Value: $1.Value,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| encaps_list
|
| encaps_list
|
||||||
{
|
{
|
||||||
@ -4040,45 +4044,54 @@ scalar:
|
|||||||
}
|
}
|
||||||
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
|
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
|
||||||
{
|
{
|
||||||
encapsed := &ast.ScalarEncapsedStringPart{ast.Node{}, $2.Value}
|
$$ = &ast.ScalarHeredoc{
|
||||||
$$ = &ast.ScalarHeredoc{ast.Node{}, $1.Value, []ast.Vertex{encapsed}}
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokensPosition($1, $3),
|
||||||
// save position
|
},
|
||||||
encapsed.GetNode().Position = position.NewTokenPosition($2)
|
OpenHeredocTkn: $1,
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
Parts: []ast.Vertex{
|
||||||
|
&ast.ScalarEncapsedStringPart{
|
||||||
// save comments
|
Node: ast.Node{
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
Position: position.NewTokenPosition($2),
|
||||||
|
},
|
||||||
|
EncapsedStrTkn: $2,
|
||||||
|
Value: $2.Value,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
CloseHeredocTkn: $3,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| T_START_HEREDOC T_END_HEREDOC
|
| T_START_HEREDOC T_END_HEREDOC
|
||||||
{
|
{
|
||||||
$$ = &ast.ScalarHeredoc{ast.Node{}, $1.Value, nil}
|
$$ = &ast.ScalarHeredoc{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokensPosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $2)
|
},
|
||||||
|
OpenHeredocTkn: $1,
|
||||||
// save comments
|
CloseHeredocTkn: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
}
|
||||||
}
|
}
|
||||||
| '"' encaps_list '"'
|
| '"' encaps_list '"'
|
||||||
{
|
{
|
||||||
$$ = &ast.ScalarEncapsed{ast.Node{}, $2}
|
$$ = &ast.ScalarEncapsed{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokensPosition($1, $3),
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
},
|
||||||
|
OpenQoteTkn: $1,
|
||||||
// save comments
|
Parts: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
CloseQoteTkn: $1,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| T_START_HEREDOC encaps_list T_END_HEREDOC
|
| T_START_HEREDOC encaps_list T_END_HEREDOC
|
||||||
{
|
{
|
||||||
$$ = &ast.ScalarHeredoc{ast.Node{}, $1.Value, $2}
|
$$ = &ast.ScalarHeredoc{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokensPosition($1, $3),
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
},
|
||||||
|
OpenHeredocTkn: $1,
|
||||||
// save comments
|
Parts: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
CloseHeredocTkn: $3,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| dereferencable_scalar
|
| dereferencable_scalar
|
||||||
{
|
{
|
||||||
@ -4615,14 +4628,16 @@ encaps_list:
|
|||||||
}
|
}
|
||||||
| encaps_list T_ENCAPSED_AND_WHITESPACE
|
| encaps_list T_ENCAPSED_AND_WHITESPACE
|
||||||
{
|
{
|
||||||
encapsed := &ast.ScalarEncapsedStringPart{ast.Node{}, $2.Value}
|
$$ = append(
|
||||||
$$ = append($1, encapsed)
|
$1,
|
||||||
|
&ast.ScalarEncapsedStringPart{
|
||||||
// save position
|
Node: ast.Node{
|
||||||
encapsed.GetNode().Position = position.NewTokenPosition($2)
|
Position: position.NewTokenPosition($2),
|
||||||
|
},
|
||||||
// save comments
|
EncapsedStrTkn: $2,
|
||||||
yylex.(*Parser).setFreeFloating(encapsed, token.Start, $2.SkippedTokens)
|
Value: $2.Value,
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
| encaps_var
|
| encaps_var
|
||||||
{
|
{
|
||||||
@ -4630,14 +4645,16 @@ encaps_list:
|
|||||||
}
|
}
|
||||||
| T_ENCAPSED_AND_WHITESPACE encaps_var
|
| T_ENCAPSED_AND_WHITESPACE encaps_var
|
||||||
{
|
{
|
||||||
encapsed := &ast.ScalarEncapsedStringPart{ast.Node{}, $1.Value}
|
$$ = []ast.Vertex{
|
||||||
$$ = []ast.Vertex{encapsed, $2}
|
&ast.ScalarEncapsedStringPart{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenPosition($1),
|
||||||
encapsed.GetNode().Position = position.NewTokenPosition($1)
|
},
|
||||||
|
EncapsedStrTkn: $1,
|
||||||
// save comments
|
Value: $1.Value,
|
||||||
yylex.(*Parser).setFreeFloating(encapsed, token.Start, $1.SkippedTokens)
|
},
|
||||||
|
$2,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -126,7 +126,9 @@ func (n *ScalarDnumber) Accept(v NodeVisitor) {
|
|||||||
// ScalarEncapsed node
|
// ScalarEncapsed node
|
||||||
type ScalarEncapsed struct {
|
type ScalarEncapsed struct {
|
||||||
Node
|
Node
|
||||||
Parts []Vertex
|
OpenQoteTkn *token.Token
|
||||||
|
Parts []Vertex
|
||||||
|
CloseQoteTkn *token.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *ScalarEncapsed) Accept(v NodeVisitor) {
|
func (n *ScalarEncapsed) Accept(v NodeVisitor) {
|
||||||
@ -136,7 +138,8 @@ func (n *ScalarEncapsed) Accept(v NodeVisitor) {
|
|||||||
// ScalarEncapsedStringPart node
|
// ScalarEncapsedStringPart node
|
||||||
type ScalarEncapsedStringPart struct {
|
type ScalarEncapsedStringPart struct {
|
||||||
Node
|
Node
|
||||||
Value []byte
|
EncapsedStrTkn *token.Token
|
||||||
|
Value []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *ScalarEncapsedStringPart) Accept(v NodeVisitor) {
|
func (n *ScalarEncapsedStringPart) Accept(v NodeVisitor) {
|
||||||
@ -146,8 +149,9 @@ func (n *ScalarEncapsedStringPart) Accept(v NodeVisitor) {
|
|||||||
// ScalarHeredoc node
|
// ScalarHeredoc node
|
||||||
type ScalarHeredoc struct {
|
type ScalarHeredoc struct {
|
||||||
Node
|
Node
|
||||||
Label []byte
|
OpenHeredocTkn *token.Token
|
||||||
Parts []Vertex
|
Parts []Vertex
|
||||||
|
CloseHeredocTkn *token.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *ScalarHeredoc) Accept(v NodeVisitor) {
|
func (n *ScalarHeredoc) Accept(v NodeVisitor) {
|
||||||
|
@ -1224,9 +1224,6 @@ func (v *Dump) ScalarHeredoc(n *ast.ScalarHeredoc) {
|
|||||||
v.printIndentIfNotSingle(v.indent - 1)
|
v.printIndentIfNotSingle(v.indent - 1)
|
||||||
v.print("&ast.ScalarHeredoc{\n")
|
v.print("&ast.ScalarHeredoc{\n")
|
||||||
v.printNode(n.GetNode())
|
v.printNode(n.GetNode())
|
||||||
|
|
||||||
v.printIndent(v.indent)
|
|
||||||
v.print(fmt.Sprintf("Label: %q,\n", n.Label))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Dump) ScalarLnumber(n *ast.ScalarLnumber) {
|
func (v *Dump) ScalarLnumber(n *ast.ScalarLnumber) {
|
||||||
|
@ -558,7 +558,7 @@ func (p *PrettyPrinter) printScalarEncapsed(n ast.Vertex) {
|
|||||||
func (p *PrettyPrinter) printScalarHeredoc(n ast.Vertex) {
|
func (p *PrettyPrinter) printScalarHeredoc(n ast.Vertex) {
|
||||||
nn := n.(*ast.ScalarHeredoc)
|
nn := n.(*ast.ScalarHeredoc)
|
||||||
|
|
||||||
io.WriteString(p.w, string(nn.Label))
|
io.WriteString(p.w, string(nn.OpenHeredocTkn.Value))
|
||||||
|
|
||||||
for _, part := range nn.Parts {
|
for _, part := range nn.Parts {
|
||||||
switch part.(type) {
|
switch part.(type) {
|
||||||
@ -571,7 +571,7 @@ func (p *PrettyPrinter) printScalarHeredoc(n ast.Vertex) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
io.WriteString(p.w, strings.Trim(string(nn.Label), "<\"'\n"))
|
io.WriteString(p.w, strings.Trim(string(nn.OpenHeredocTkn.Value), "<\"'\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PrettyPrinter) printScalarMagicConstant(n ast.Vertex) {
|
func (p *PrettyPrinter) printScalarMagicConstant(n ast.Vertex) {
|
||||||
|
@ -687,7 +687,7 @@ func (p *Printer) printScalarHeredoc(n ast.Vertex) {
|
|||||||
p.printFreeFloatingOrDefault(nn, token.Start, p.bufStart)
|
p.printFreeFloatingOrDefault(nn, token.Start, p.bufStart)
|
||||||
p.bufStart = ""
|
p.bufStart = ""
|
||||||
|
|
||||||
p.write(nn.Label)
|
p.write(nn.OpenHeredocTkn.Value)
|
||||||
|
|
||||||
for _, part := range nn.Parts {
|
for _, part := range nn.Parts {
|
||||||
switch part.(type) {
|
switch part.(type) {
|
||||||
@ -710,7 +710,7 @@ func (p *Printer) printScalarHeredoc(n ast.Vertex) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p.write([]byte(strings.Trim(string(nn.Label), "<\"'\n")))
|
p.write([]byte(strings.Trim(string(nn.OpenHeredocTkn.Value), "<\"'\n")))
|
||||||
|
|
||||||
p.printFreeFloating(nn, token.End)
|
p.printFreeFloating(nn, token.End)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user