replace meta.SemiColonToken; fix printing stmt.TraitAdaptationList
This commit is contained in:
parent
5a715a4a11
commit
33c2a5b5c6
14
php5/php5.go
14
php5/php5.go
@ -3455,8 +3455,8 @@ yydefault:
|
||||
yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token))
|
||||
|
||||
// save comments
|
||||
yyDollar[1].token.Meta.SetTokenName(meta.SemiColonToken).AppendTo(yyVAL.node.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken(yyVAL.node, yyDollar[1].token, meta.SemiColonToken)
|
||||
yyDollar[1].token.Meta.SetTokenName(meta.NodeStart).AppendTo(yyVAL.node.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken(yyVAL.node, yyDollar[1].token, meta.NodeStart)
|
||||
|
||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||
}
|
||||
@ -4905,8 +4905,8 @@ yydefault:
|
||||
yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token))
|
||||
|
||||
// save comments
|
||||
yyDollar[1].token.Meta.SetTokenName(meta.SemiColonToken).AppendTo(yyVAL.node.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken(yyVAL.node, yyDollar[1].token, meta.SemiColonToken)
|
||||
yyDollar[1].token.Meta.SetTokenName(meta.NodeStart).AppendTo(yyVAL.node.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken(yyVAL.node, yyDollar[1].token, meta.NodeStart)
|
||||
|
||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||
}
|
||||
@ -4919,7 +4919,7 @@ yydefault:
|
||||
yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token))
|
||||
|
||||
// save comments
|
||||
yyDollar[1].token.Meta.SetTokenName(meta.OpenCurlyBracesToken).AppendTo(yyVAL.node.GetMeta())
|
||||
yyDollar[1].token.Meta.SetTokenName(meta.NodeStart).AppendTo(yyVAL.node.GetMeta())
|
||||
yyDollar[3].token.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo(yyVAL.node.GetMeta())
|
||||
|
||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||
@ -5111,8 +5111,8 @@ yydefault:
|
||||
yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token))
|
||||
|
||||
// save comments
|
||||
yyDollar[1].token.Meta.SetTokenName(meta.SemiColonToken).AppendTo(yyVAL.node.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken(yyVAL.node, yyDollar[1].token, meta.SemiColonToken)
|
||||
yyDollar[1].token.Meta.SetTokenName(meta.NodeStart).AppendTo(yyVAL.node.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken(yyVAL.node, yyDollar[1].token, meta.NodeStart)
|
||||
|
||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||
}
|
||||
|
14
php5/php5.y
14
php5/php5.y
@ -1309,8 +1309,8 @@ unticked_statement:
|
||||
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
|
||||
|
||||
// save comments
|
||||
$1.Meta.SetTokenName(meta.SemiColonToken).AppendTo($$.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken($$, $1, meta.SemiColonToken)
|
||||
$1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken($$, $1, meta.NodeStart)
|
||||
|
||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||
}
|
||||
@ -2709,8 +2709,8 @@ trait_adaptations:
|
||||
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
|
||||
|
||||
// save comments
|
||||
$1.Meta.SetTokenName(meta.SemiColonToken).AppendTo($$.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken($$, $1, meta.SemiColonToken)
|
||||
$1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken($$, $1, meta.NodeStart)
|
||||
|
||||
|
||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||
@ -2722,7 +2722,7 @@ trait_adaptations:
|
||||
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $3))
|
||||
|
||||
// save comments
|
||||
$1.Meta.SetTokenName(meta.OpenCurlyBracesToken).AppendTo($$.GetMeta())
|
||||
$1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
|
||||
$3.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta())
|
||||
|
||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||
@ -2910,8 +2910,8 @@ method_body:
|
||||
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
|
||||
|
||||
// save comments
|
||||
$1.Meta.SetTokenName(meta.SemiColonToken).AppendTo($$.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken($$, $1, meta.SemiColonToken)
|
||||
$1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken($$, $1, meta.NodeStart)
|
||||
|
||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||
}
|
||||
|
16
php7/php7.go
16
php7/php7.go
@ -3593,8 +3593,8 @@ yydefault:
|
||||
yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token))
|
||||
|
||||
// save comments
|
||||
yyDollar[1].token.Meta.SetTokenName(meta.SemiColonToken).AppendTo(yyVAL.node.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken(yyVAL.node, yyDollar[1].token, meta.SemiColonToken)
|
||||
yyDollar[1].token.Meta.SetTokenName(meta.NodeStart).AppendTo(yyVAL.node.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken(yyVAL.node, yyDollar[1].token, meta.NodeStart)
|
||||
|
||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||
}
|
||||
@ -4918,8 +4918,8 @@ yydefault:
|
||||
yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token))
|
||||
|
||||
// save comments
|
||||
yyDollar[1].token.Meta.SetTokenName(meta.SemiColonToken).AppendTo(yyVAL.node.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken(yyVAL.node, yyDollar[1].token, meta.SemiColonToken)
|
||||
yyDollar[1].token.Meta.SetTokenName(meta.NodeStart).AppendTo(yyVAL.node.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken(yyVAL.node, yyDollar[1].token, meta.NodeStart)
|
||||
|
||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||
}
|
||||
@ -4932,7 +4932,7 @@ yydefault:
|
||||
yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition(yyDollar[1].token, yyDollar[2].token))
|
||||
|
||||
// save comments
|
||||
yyDollar[1].token.Meta.SetTokenName(meta.OpenCurlyBracesToken).AppendTo(yyVAL.node.GetMeta())
|
||||
yyDollar[1].token.Meta.SetTokenName(meta.NodeStart).AppendTo(yyVAL.node.GetMeta())
|
||||
yyDollar[2].token.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo(yyVAL.node.GetMeta())
|
||||
|
||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||
@ -4946,7 +4946,7 @@ yydefault:
|
||||
yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token))
|
||||
|
||||
// save comments
|
||||
yyDollar[1].token.Meta.SetTokenName(meta.OpenCurlyBracesToken).AppendTo(yyVAL.node.GetMeta())
|
||||
yyDollar[1].token.Meta.SetTokenName(meta.NodeStart).AppendTo(yyVAL.node.GetMeta())
|
||||
yyDollar[3].token.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo(yyVAL.node.GetMeta())
|
||||
|
||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||
@ -5121,8 +5121,8 @@ yydefault:
|
||||
yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token))
|
||||
|
||||
// save comments
|
||||
yyDollar[1].token.Meta.SetTokenName(meta.SemiColonToken).AppendTo(yyVAL.node.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken(yyVAL.node, yyDollar[1].token, meta.SemiColonToken)
|
||||
yyDollar[1].token.Meta.SetTokenName(meta.NodeStart).AppendTo(yyVAL.node.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken(yyVAL.node, yyDollar[1].token, meta.NodeStart)
|
||||
|
||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||
}
|
||||
|
16
php7/php7.y
16
php7/php7.y
@ -1253,8 +1253,8 @@ statement:
|
||||
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
|
||||
|
||||
// save comments
|
||||
$1.Meta.SetTokenName(meta.SemiColonToken).AppendTo($$.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken($$, $1, meta.SemiColonToken)
|
||||
$1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken($$, $1, meta.NodeStart)
|
||||
|
||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||
}
|
||||
@ -2519,8 +2519,8 @@ trait_adaptations:
|
||||
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
|
||||
|
||||
// save comments
|
||||
$1.Meta.SetTokenName(meta.SemiColonToken).AppendTo($$.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken($$, $1, meta.SemiColonToken)
|
||||
$1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken($$, $1, meta.NodeStart)
|
||||
|
||||
|
||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||
@ -2532,7 +2532,7 @@ trait_adaptations:
|
||||
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $2))
|
||||
|
||||
// save comments
|
||||
$1.Meta.SetTokenName(meta.OpenCurlyBracesToken).AppendTo($$.GetMeta())
|
||||
$1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
|
||||
$2.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta())
|
||||
|
||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||
@ -2544,7 +2544,7 @@ trait_adaptations:
|
||||
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $3))
|
||||
|
||||
// save comments
|
||||
$1.Meta.SetTokenName(meta.OpenCurlyBracesToken).AppendTo($$.GetMeta())
|
||||
$1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
|
||||
$3.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta())
|
||||
|
||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||
@ -2714,8 +2714,8 @@ method_body:
|
||||
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
|
||||
|
||||
// save comments
|
||||
$1.Meta.SetTokenName(meta.SemiColonToken).AppendTo($$.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken($$, $1, meta.SemiColonToken)
|
||||
$1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
|
||||
yylex.(*Parser).appendMetaToken($$, $1, meta.NodeStart)
|
||||
|
||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||
}
|
||||
|
@ -393,6 +393,8 @@ func (p *Printer) printNode(n node.Node) {
|
||||
p.printStmtSwitch(n)
|
||||
case *stmt.Throw:
|
||||
p.printStmtThrow(n)
|
||||
case *stmt.TraitAdaptationList:
|
||||
p.printStmtTraitAdaptationList(n)
|
||||
case *stmt.TraitMethodRef:
|
||||
p.printStmtTraitMethodRef(n)
|
||||
case *stmt.TraitUseAlias:
|
||||
@ -2414,7 +2416,6 @@ func (p *Printer) printStmtNamespace(n node.Node) {
|
||||
|
||||
func (p *Printer) printStmtNop(n node.Node) {
|
||||
p.printMeta(n, meta.NodeStart)
|
||||
p.printMeta(n, meta.SemiColonToken)
|
||||
p.printMeta(n, meta.NodeEnd)
|
||||
}
|
||||
|
||||
@ -2526,6 +2527,18 @@ func (p *Printer) printStmtThrow(n node.Node) {
|
||||
p.printMeta(nn, meta.NodeEnd)
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtTraitAdaptationList(n node.Node) {
|
||||
nn := n.(*stmt.TraitAdaptationList)
|
||||
p.printMeta(nn, meta.NodeStart)
|
||||
|
||||
io.WriteString(p.w, "{")
|
||||
p.printNodes(nn.Adaptations)
|
||||
p.printMeta(nn, meta.CloseCurlyBracesToken)
|
||||
io.WriteString(p.w, "}")
|
||||
|
||||
p.printMeta(nn, meta.NodeEnd)
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtTraitMethodRef(n node.Node) {
|
||||
nn := n.(*stmt.TraitMethodRef)
|
||||
p.printMeta(nn, meta.NodeStart)
|
||||
@ -2582,15 +2595,7 @@ func (p *Printer) printStmtTraitUse(n node.Node) {
|
||||
io.WriteString(p.w, "use")
|
||||
p.joinPrint(",", nn.Traits)
|
||||
|
||||
if adaptationList, ok := nn.TraitAdaptationList.(*stmt.TraitAdaptationList); ok {
|
||||
p.printMeta(adaptationList, meta.OpenCurlyBracesToken)
|
||||
io.WriteString(p.w, "{")
|
||||
p.printNodes(adaptationList.Adaptations)
|
||||
p.printMeta(adaptationList, meta.CloseCurlyBracesToken)
|
||||
io.WriteString(p.w, "}")
|
||||
} else {
|
||||
p.printMeta(nn.TraitAdaptationList, meta.SemiColonToken)
|
||||
}
|
||||
p.Print(nn.TraitAdaptationList)
|
||||
|
||||
p.printMeta(nn, meta.NodeEnd)
|
||||
}
|
||||
|
@ -7604,10 +7604,15 @@ func TestPrinterPrintNop(t *testing.T) {
|
||||
Value: " ",
|
||||
TokenName: meta.NodeStart,
|
||||
},
|
||||
&meta.Data{
|
||||
Type: meta.TokenType,
|
||||
Value: ";",
|
||||
TokenName: meta.NodeStart,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expected := ` `
|
||||
expected := ` ;`
|
||||
actual := o.String()
|
||||
|
||||
if expected != actual {
|
||||
@ -8075,6 +8080,42 @@ func TestPrinterPrintStmtThrow(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrinterPrintStmtTraitAdaptationList(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
p := printer.NewPrinter(o)
|
||||
p.Print(&stmt.TraitAdaptationList{
|
||||
Meta: meta.Collection{
|
||||
&meta.Data{
|
||||
Type: meta.WhiteSpaceType,
|
||||
Value: " ",
|
||||
TokenName: meta.NodeStart,
|
||||
},
|
||||
&meta.Data{
|
||||
Type: meta.WhiteSpaceType,
|
||||
Value: " ",
|
||||
TokenName: meta.CloseCurlyBracesToken,
|
||||
},
|
||||
},
|
||||
Adaptations: []node.Node{
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Trait: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
|
||||
Method: &node.Identifier{Value: "a"},
|
||||
},
|
||||
Alias: &node.Identifier{Value: "b"},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expected := ` {Foo::aasb }`
|
||||
actual := o.String()
|
||||
|
||||
if expected != actual {
|
||||
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrinterPrintStmtTraitMethodRef(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
@ -8214,12 +8255,12 @@ func TestPrinterPrintStmtTraitUse(t *testing.T) {
|
||||
&meta.Data{
|
||||
Type: meta.WhiteSpaceType,
|
||||
Value: " ",
|
||||
TokenName: meta.SemiColonToken,
|
||||
TokenName: meta.NodeStart,
|
||||
},
|
||||
&meta.Data{
|
||||
Type: meta.TokenType,
|
||||
Value: "",
|
||||
TokenName: meta.SemiColonToken,
|
||||
TokenName: meta.NodeStart,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -8254,7 +8295,7 @@ func TestPrinterPrintStmtTraitAdaptations(t *testing.T) {
|
||||
&meta.Data{
|
||||
Type: meta.WhiteSpaceType,
|
||||
Value: " ",
|
||||
TokenName: meta.OpenCurlyBracesToken,
|
||||
TokenName: meta.NodeStart,
|
||||
},
|
||||
&meta.Data{
|
||||
Type: meta.WhiteSpaceType,
|
||||
|
@ -474,12 +474,12 @@ func ExamplePrettyJsonDumper() {
|
||||
// {
|
||||
// "type": "*meta.WhiteSpaceType",
|
||||
// "value": "\n\t\t\t\t",
|
||||
// "tokenName": "SemiColonToken"
|
||||
// "tokenName": "NodeStart"
|
||||
// },
|
||||
// {
|
||||
// "type": "*meta.TokenType",
|
||||
// "value": ";",
|
||||
// "tokenName": "SemiColonToken"
|
||||
// "tokenName": "NodeStart"
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
|
Loading…
Reference in New Issue
Block a user