#70: [php5] inherit meta.Data at stmt.Use

This commit is contained in:
z7zmey 2019-01-02 23:22:28 +02:00
parent b5ff3ac2f7
commit 28e5540108
3 changed files with 575 additions and 527 deletions

View File

@ -113,6 +113,18 @@ func isDollar(r rune) bool {
return r == '$'
}
func newInheritMetaFilter() meta.Filter {
return meta.StopOnFailureFilter(
meta.AndFilter(
meta.TokenNameFilter(meta.NodeStart),
meta.OrFilter(
meta.TypeFilter(meta.CommentType, meta.WhiteSpaceType),
meta.ValueFilter("<?php", "<?"),
),
),
)
}
func (l *Parser) appendMetaToken(n node.Node, t *scanner.Token, tn meta.TokenName) {
if !l.Lexer.WithMeta {
return

File diff suppressed because it is too large Load Diff

View File

@ -518,6 +518,9 @@ use_declaration:
name.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($1))
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($1))
// save comments
$1[0].GetMeta().Cut(newInheritMetaFilter()).PrependTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
| namespace_name T_AS T_STRING
@ -535,6 +538,8 @@ use_declaration:
$2.Meta.SetTokenName(meta.AsToken).AppendTo($$.GetMeta())
$3.Meta.SetTokenName(meta.NodeStart).AppendTo(alias.GetMeta())
$1[0].GetMeta().Cut(newInheritMetaFilter()).PrependTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
| T_NS_SEPARATOR namespace_name
@ -547,8 +552,9 @@ use_declaration:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($2))
// save comments
$1.Meta.SetTokenName(meta.UseLeadingNsSeparatorToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $1, meta.UseLeadingNsSeparatorToken)
$1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $1, meta.NodeStart)
$2[0].GetMeta().Cut(newInheritMetaFilter()).AppendTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -564,8 +570,9 @@ use_declaration:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListTokenPosition($2, $4))
// save comments
$1.Meta.SetTokenName(meta.UseLeadingNsSeparatorToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $1, meta.UseLeadingNsSeparatorToken)
$1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $1, meta.NodeStart)
$2[0].GetMeta().Cut(newInheritMetaFilter()).AppendTo($$.GetMeta())
$3.Meta.SetTokenName(meta.AsToken).AppendTo($$.GetMeta())
$4.Meta.SetTokenName(meta.NodeStart).AppendTo(alias.GetMeta())
@ -601,6 +608,9 @@ use_function_declaration:
name.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($1))
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($1))
// save comments
$1[0].GetMeta().Cut(newInheritMetaFilter()).PrependTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
| namespace_name T_AS T_STRING
@ -615,6 +625,7 @@ use_function_declaration:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListTokenPosition($1, $3))
// save comments
$1[0].GetMeta().Cut(newInheritMetaFilter()).AppendTo($$.GetMeta())
$2.Meta.SetTokenName(meta.AsToken).AppendTo($$.GetMeta())
$3.Meta.SetTokenName(meta.NodeStart).AppendTo(alias.GetMeta())
@ -630,8 +641,9 @@ use_function_declaration:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($2))
// save comments
$1.Meta.SetTokenName(meta.UseLeadingNsSeparatorToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $1, meta.UseLeadingNsSeparatorToken)
$1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $1, meta.NodeStart)
$2[0].GetMeta().Cut(newInheritMetaFilter()).AppendTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -647,8 +659,9 @@ use_function_declaration:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListTokenPosition($2, $4))
// save comments
$1.Meta.SetTokenName(meta.UseLeadingNsSeparatorToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $1, meta.UseLeadingNsSeparatorToken)
$1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $1, meta.NodeStart)
$2[0].GetMeta().Cut(newInheritMetaFilter()).AppendTo($$.GetMeta())
$3.Meta.SetTokenName(meta.AsToken).AppendTo($$.GetMeta())
$4.Meta.SetTokenName(meta.NodeStart).AppendTo(alias.GetMeta())
@ -684,6 +697,9 @@ use_const_declaration:
name.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($1))
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($1))
// save comments
$1[0].GetMeta().Cut(newInheritMetaFilter()).PrependTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
| namespace_name T_AS T_STRING
@ -698,6 +714,7 @@ use_const_declaration:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListTokenPosition($1, $3))
// save comments
$1[0].GetMeta().Cut(newInheritMetaFilter()).AppendTo($$.GetMeta())
$2.Meta.SetTokenName(meta.AsToken).AppendTo($$.GetMeta())
$3.Meta.SetTokenName(meta.NodeStart).AppendTo(alias.GetMeta())
@ -713,8 +730,9 @@ use_const_declaration:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($2))
// save comments
$1.Meta.SetTokenName(meta.UseLeadingNsSeparatorToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $1, meta.UseLeadingNsSeparatorToken)
$1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $1, meta.NodeStart)
$2[0].GetMeta().Cut(newInheritMetaFilter()).AppendTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -730,8 +748,9 @@ use_const_declaration:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListTokenPosition($2, $4))
// save comments
$1.Meta.SetTokenName(meta.UseLeadingNsSeparatorToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $1, meta.UseLeadingNsSeparatorToken)
$1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $1, meta.NodeStart)
$2[0].GetMeta().Cut(newInheritMetaFilter()).AppendTo($$.GetMeta())
$3.Meta.SetTokenName(meta.AsToken).AppendTo($$.GetMeta())
$4.Meta.SetTokenName(meta.NodeStart).AppendTo(alias.GetMeta())