#13: the printer prints nodes with meta(comments and whitespaces) saved by the parser

This commit is contained in:
z7zmey 2018-07-02 20:48:55 +03:00
parent c4c0934c51
commit 15a1a81924
30 changed files with 14110 additions and 4465 deletions

View File

@ -6,6 +6,7 @@ fmt:
find . -type f -iregex '.*\.go' -exec gofmt -l -s -w '{}' +
build:
go generate ./...
go build
run:

163
meta/tokenName.go Normal file
View File

@ -0,0 +1,163 @@
package meta
// TokenName is used to specify a comment position
type TokenName int
//go:generate stringer -type=TokenName -output ./tokenName_string.go
const (
UnknownToken TokenName = iota
NodeStart
NodeEnd
MagicConstantToken
IncludeToken
IncludeOnceToken
ExitToken
IfToken
LnumberToken
DnumberToken
StringToken
StringVarnameToken
VariableToken
NumStringToken
InlineHTMLToken
EncapsedAndWhitespaceToken
ConstantEncapsedStringToken
EchoToken
DoToken
WhileToken
EndwhileToken
ForInitSemicolonToken
ForCondSemicolonToken
ForToken
EndforToken
ForeachToken
EndforeachToken
DeclareToken
EnddeclareToken
AsToken
SwitchToken
SwitchSemicolonToken
EndswitchToken
CaseToken
DefaultToken
BreakToken
ContinueToken
GotoToken
FunctionToken
ConstToken
ReturnToken
TryToken
CatchToken
FinallyToken
ThrowToken
UseToken
InsteadofToken
GlobalToken
VarToken
UnsetToken
IssetToken
EmptyToken
ClassToken
TraitToken
InterfaceToken
ExtendsToken
ImplementsToken
DoubleArrowToken
ListToken
ArrayToken
CallableToken
StartHeredocToken
DollarOpenCurlyBracesToken
CurlyOpenToken
PaamayimNekudotayimToken
NamespaceToken
NsSeparatorToken
EllipsisToken
EvalToken
RequireToken
RequireOnceToken
LogicalOrToken
LogicalXorToken
LogicalAndToken
InstanceofToken
NewToken
CloneToken
ElseifToken
ElseToken
EndifToken
PrintToken
YieldToken
StaticToken
AbstractToken
FinalToken
PrivateToken
ProtectedToken
PublicToken
IncToken
DecToken
YieldFromToken
ObjectOperatorToken
IntCastToken
DoubleCastToken
StringCastToken
ArrayCastToken
ObjectCastToken
BoolCastToken
UnsetCastToken
CoalesceToken
SpaceshipToken
PlusEqualToken
MinusEqualToken
MulEqualToken
PowEqualToken
DivEqualToken
ConcatEqualToken
ModEqualToken
AndEqualToken
OrEqualToken
XorEqualToken
SlEqualToken
SrEqualToken
BooleanOrToken
BooleanAndToken
PowToken
SlToken
SrToken
IsIdenticalToken
IsNotIdenticalToken
IsEqualToken
IsNotEqualToken
IsSmallerOrEqualToken
IsGreaterOrEqualToken
HaltCompilerToken
IdentifierToken
CaseSeparatorToken // ';' or ':'
DoubleQuoteToken // '"'
BackquoteToken // '`'
OpenCurlyBracesToken // '{'
CloseCurlyBracesToken // '}'
SemiColonToken // ';'
ColonToken // ':'
OpenParenthesisToken // '('
CloseParenthesisToken // ')'
OpenSquareBracket // '['
CloseSquareBracket // ']'
QuestionMarkToken // '?'
AmpersandToken // '&'
MinusToken // '-'
PlusToken // '+'
ExclamationMarkToken // '!'
TildeToken // '~'
AtToken // '@'
DollarToken // '$'
CommaToken // ','
VerticalBarToken // '|'
EqualToken // '='
CaretToken // '^'
AsteriskToken // '*'
SlashToken // '/'
PercentToken // '%'
LessToken // '<'
GreaterToken // '>'
DotToken // '.'
)

16
meta/tokenName_string.go Normal file
View File

@ -0,0 +1,16 @@
// Code generated by "stringer -type=TokenName -output ./tokenName_string.go"; DO NOT EDIT.
package meta
import "strconv"
const _TokenName_name = "UnknownTokenNodeStartNodeEndMagicConstantTokenIncludeTokenIncludeOnceTokenExitTokenIfTokenLnumberTokenDnumberTokenStringTokenStringVarnameTokenVariableTokenNumStringTokenInlineHTMLTokenEncapsedAndWhitespaceTokenConstantEncapsedStringTokenEchoTokenDoTokenWhileTokenEndwhileTokenForInitSemicolonTokenForCondSemicolonTokenForTokenEndforTokenForeachTokenEndforeachTokenDeclareTokenEnddeclareTokenAsTokenSwitchTokenSwitchSemicolonTokenEndswitchTokenCaseTokenDefaultTokenBreakTokenContinueTokenGotoTokenFunctionTokenConstTokenReturnTokenTryTokenCatchTokenFinallyTokenThrowTokenUseTokenInsteadofTokenGlobalTokenVarTokenUnsetTokenIssetTokenEmptyTokenClassTokenTraitTokenInterfaceTokenExtendsTokenImplementsTokenDoubleArrowTokenListTokenArrayTokenCallableTokenStartHeredocTokenDollarOpenCurlyBracesTokenCurlyOpenTokenPaamayimNekudotayimTokenNamespaceTokenNsSeparatorTokenEllipsisTokenEvalTokenRequireTokenRequireOnceTokenLogicalOrTokenLogicalXorTokenLogicalAndTokenInstanceofTokenNewTokenCloneTokenElseifTokenElseTokenEndifTokenPrintTokenYieldTokenStaticTokenAbstractTokenFinalTokenPrivateTokenProtectedTokenPublicTokenIncTokenDecTokenYieldFromTokenObjectOperatorTokenIntCastTokenDoubleCastTokenStringCastTokenArrayCastTokenObjectCastTokenBoolCastTokenUnsetCastTokenCoalesceTokenSpaceshipTokenPlusEqualTokenMinusEqualTokenMulEqualTokenPowEqualTokenDivEqualTokenConcatEqualTokenModEqualTokenAndEqualTokenOrEqualTokenXorEqualTokenSlEqualTokenSrEqualTokenBooleanOrTokenBooleanAndTokenPowTokenSlTokenSrTokenIsIdenticalTokenIsNotIdenticalTokenIsEqualTokenIsNotEqualTokenIsSmallerOrEqualTokenIsGreaterOrEqualTokenHaltCompilerTokenIdentifierTokenCaseSeparatorTokenDoubleQuoteTokenBackquoteTokenOpenCurlyBracesTokenCloseCurlyBracesTokenSemiColonTokenColonTokenOpenParenthesisTokenCloseParenthesisTokenOpenSquareBracketCloseSquareBracketQuestionMarkTokenAmpersandTokenMinusTokenPlusTokenExclamationMarkTokenTildeTokenAtTokenDollarTokenCommaTokenVerticalBarTokenEqualTokenCaretTokenAsteriskTokenSlashTokenPercentTokenLessTokenGreaterTokenDotToken"
var _TokenName_index = [...]uint16{0, 12, 21, 28, 46, 58, 74, 83, 90, 102, 114, 125, 143, 156, 170, 185, 211, 238, 247, 254, 264, 277, 298, 319, 327, 338, 350, 365, 377, 392, 399, 410, 430, 444, 453, 465, 475, 488, 497, 510, 520, 531, 539, 549, 561, 571, 579, 593, 604, 612, 622, 632, 642, 652, 662, 676, 688, 703, 719, 728, 738, 751, 768, 794, 808, 832, 846, 862, 875, 884, 896, 912, 926, 941, 956, 971, 979, 989, 1000, 1009, 1019, 1029, 1039, 1050, 1063, 1073, 1085, 1099, 1110, 1118, 1126, 1140, 1159, 1171, 1186, 1201, 1215, 1230, 1243, 1257, 1270, 1284, 1298, 1313, 1326, 1339, 1352, 1368, 1381, 1394, 1406, 1419, 1431, 1443, 1457, 1472, 1480, 1487, 1494, 1510, 1529, 1541, 1556, 1577, 1598, 1615, 1630, 1648, 1664, 1678, 1698, 1719, 1733, 1743, 1763, 1784, 1801, 1819, 1836, 1850, 1860, 1869, 1889, 1899, 1906, 1917, 1927, 1943, 1953, 1963, 1976, 1986, 1998, 2007, 2019, 2027}
func (i TokenName) String() string {
if i < 0 || i >= TokenName(len(_TokenName_index)-1) {
return "TokenName(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _TokenName_name[_TokenName_index[i]:_TokenName_index[i+1]]
}

29
meta/tokenName_test.go Normal file
View File

@ -0,0 +1,29 @@
package meta_test
import (
"testing"
"github.com/z7zmey/php-parser/meta"
)
func TestTokenNameString(t *testing.T) {
c := meta.NsSeparatorToken
expected := "NsSeparatorToken"
actual := c.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestWrongTokenNameString(t *testing.T) {
c := meta.TokenName(-1)
expected := "TokenName(-1)"
actual := c.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}

View File

@ -1,328 +0,0 @@
package meta
// TokenName is used to specify a comment position
type TokenName int
const (
UnknownToken TokenName = iota
IncludeToken
IncludeOnceToken
ExitToken
IfToken
LnumberToken
DnumberToken
StringToken
StringVarnameToken
VariableToken
NumStringToken
InlineHTMLToken
EncapsedAndWhitespaceToken
ConstantEncapsedStringToken
EchoToken
DoToken
WhileToken
EndwhileToken
ForInitSemicolonToken
ForCondSemicolonToken
ForToken
EndforToken
ForeachToken
EndforeachToken
DeclareToken
EnddeclareToken
AsToken
SwitchToken
EndswitchToken
CaseToken
DefaultToken
BreakToken
ContinueToken
GotoToken
FunctionToken
ConstToken
ReturnToken
TryToken
CatchToken
FinallyToken
ThrowToken
UseToken
InsteadofToken
GlobalToken
VarToken
UnsetToken
IssetToken
EmptyToken
ClassToken
TraitToken
InterfaceToken
ExtendsToken
ImplementsToken
DoubleArrowToken
ListToken
ArrayToken
CallableToken
ClassCToken
TraitCToken
MethodCToken
FuncCToken
LineToken
FileToken
StartHeredocToken
DollarOpenCurlyBracesToken
CurlyOpenToken
PaamayimNekudotayimToken
NamespaceToken
NsCToken
DirToken
NsSeparatorToken
EllipsisToken
EvalToken
RequireToken
RequireOnceToken
LogicalOrToken
LogicalXorToken
LogicalAndToken
InstanceofToken
NewToken
CloneToken
ElseifToken
ElseToken
EndifToken
PrintToken
YieldToken
StaticToken
AbstractToken
FinalToken
PrivateToken
ProtectedToken
PublicToken
IncToken
DecToken
YieldFromToken
ObjectOperatorToken
IntCastToken
DoubleCastToken
StringCastToken
ArrayCastToken
ObjectCastToken
BoolCastToken
UnsetCastToken
CoalesceToken
SpaceshipToken
PlusEqualToken
MinusEqualToken
MulEqualToken
PowEqualToken
DivEqualToken
ConcatEqualToken
ModEqualToken
AndEqualToken
OrEqualToken
XorEqualToken
SlEqualToken
SrEqualToken
BooleanOrToken
BooleanAndToken
PowToken
SlToken
SrToken
IsIdenticalToken
IsNotIdenticalToken
IsEqualToken
IsNotEqualToken
IsSmallerOrEqualToken
IsGreaterOrEqualToken
HaltCompilerToken
IdentifierToken
CaseSeparatorToken // ';' or ':'
DoubleQuoteToken // '"'
BackquoteToken // '`'
OpenCurlyBracesToken // '{'
CloseCurlyBracesToken // '}'
SemiColonToken // ';'
ColonToken // ':'
OpenParenthesisToken // '('
CloseParenthesisToken // ')'
OpenSquareBracket // '['
CloseSquareBracket // ']'
QuestionMarkToken // '?'
AmpersandToken // '&'
MinusToken // '-'
PlusToken // '+'
ExclamationMarkToken // '!'
TildeToken // '~'
AtToken // '@'
DollarToken // '$'
CommaToken // ','
VerticalBarToken // '|'
EqualToken // '='
CaretToken // '^'
AsteriskToken // '*'
SlashToken // '/'
PercentToken // '%'
LessToken // '<'
GreaterToken // '>'
DotToken // '.'
)
var TokenNames = map[TokenName]string{
UnknownToken: "UnknownToken",
IncludeToken: "IncludeToken",
IncludeOnceToken: "IncludeOnceToken",
ExitToken: "ExitToken",
IfToken: "IfToken",
LnumberToken: "LnumberToken",
DnumberToken: "DnumberToken",
StringToken: "StringToken",
StringVarnameToken: "StringVarnameToken",
VariableToken: "VariableToken",
NumStringToken: "NumStringToken",
InlineHTMLToken: "InlineHTMLToken",
EncapsedAndWhitespaceToken: "EncapsedAndWhitespaceToken",
ConstantEncapsedStringToken: "ConstantEncapsedStringToken",
EchoToken: "EchoToken",
DoToken: "DoToken",
WhileToken: "WhileToken",
EndwhileToken: "EndwhileToken",
ForInitSemicolonToken: "ForInitSemicolonToken",
ForCondSemicolonToken: "ForCondSemicolonToken",
ForToken: "ForToken",
EndforToken: "EndforToken",
ForeachToken: "ForeachToken",
EndforeachToken: "EndforeachToken",
DeclareToken: "DeclareToken",
EnddeclareToken: "EnddeclareToken",
AsToken: "AsToken",
SwitchToken: "SwitchToken",
EndswitchToken: "EndswitchToken",
CaseToken: "CaseToken",
DefaultToken: "DefaultToken",
BreakToken: "BreakToken",
ContinueToken: "ContinueToken",
GotoToken: "GotoToken",
FunctionToken: "FunctionToken",
ConstToken: "ConstToken",
ReturnToken: "ReturnToken",
TryToken: "TryToken",
CatchToken: "CatchToken",
FinallyToken: "FinallyToken",
ThrowToken: "ThrowToken",
UseToken: "UseToken",
InsteadofToken: "InsteadofToken",
GlobalToken: "GlobalToken",
VarToken: "VarToken",
UnsetToken: "UnsetToken",
IssetToken: "IssetToken",
EmptyToken: "EmptyToken",
ClassToken: "ClassToken",
TraitToken: "TraitToken",
InterfaceToken: "InterfaceToken",
ExtendsToken: "ExtendsToken",
ImplementsToken: "ImplementsToken",
DoubleArrowToken: "DoubleArrowToken",
ListToken: "ListToken",
ArrayToken: "ArrayToken",
CallableToken: "CallableToken",
ClassCToken: "ClassCToken",
TraitCToken: "TraitCToken",
MethodCToken: "MethodCToken",
FuncCToken: "FuncCToken",
LineToken: "LineToken",
FileToken: "FileToken",
StartHeredocToken: "StartHeredocToken",
DollarOpenCurlyBracesToken: "DollarOpenCurlyBracesToken",
CurlyOpenToken: "CurlyOpenToken",
PaamayimNekudotayimToken: "PaamayimNekudotayimToken",
NamespaceToken: "NamespaceToken",
NsCToken: "NsCToken",
DirToken: "DirToken",
NsSeparatorToken: "NsSeparatorToken",
EllipsisToken: "EllipsisToken",
EvalToken: "EvalToken",
RequireToken: "RequireToken",
RequireOnceToken: "RequireOnceToken",
LogicalOrToken: "LogicalOrToken",
LogicalXorToken: "LogicalXorToken",
LogicalAndToken: "LogicalAndToken",
InstanceofToken: "InstanceofToken",
NewToken: "NewToken",
CloneToken: "CloneToken",
ElseifToken: "ElseifToken",
ElseToken: "ElseToken",
EndifToken: "EndifToken",
PrintToken: "PrintToken",
YieldToken: "YieldToken",
StaticToken: "StaticToken",
AbstractToken: "AbstractToken",
FinalToken: "FinalToken",
PrivateToken: "PrivateToken",
ProtectedToken: "ProtectedToken",
PublicToken: "PublicToken",
IncToken: "IncToken",
DecToken: "DecToken",
YieldFromToken: "YieldFromToken",
ObjectOperatorToken: "ObjectOperatorToken",
IntCastToken: "IntCastToken",
DoubleCastToken: "DoubleCastToken",
StringCastToken: "StringCastToken",
ArrayCastToken: "ArrayCastToken",
ObjectCastToken: "ObjectCastToken",
BoolCastToken: "BoolCastToken",
UnsetCastToken: "UnsetCastToken",
CoalesceToken: "CoalesceToken",
SpaceshipToken: "SpaceshipToken",
PlusEqualToken: "PlusEqualToken",
MinusEqualToken: "MinusEqualToken",
MulEqualToken: "MulEqualToken",
PowEqualToken: "PowEqualToken",
DivEqualToken: "DivEqualToken",
ConcatEqualToken: "ConcatEqualToken",
ModEqualToken: "ModEqualToken",
AndEqualToken: "AndEqualToken",
OrEqualToken: "OrEqualToken",
XorEqualToken: "XorEqualToken",
SlEqualToken: "SlEqualToken",
SrEqualToken: "SrEqualToken",
BooleanOrToken: "BooleanOrToken",
BooleanAndToken: "BooleanAndToken",
PowToken: "PowToken",
SlToken: "SlToken",
SrToken: "SrToken",
IsIdenticalToken: "IsIdenticalToken",
IsNotIdenticalToken: "IsNotIdenticalToken",
IsEqualToken: "IsEqualToken",
IsNotEqualToken: "IsNotEqualToken",
IsSmallerOrEqualToken: "IsSmallerOrEqualToken",
IsGreaterOrEqualToken: "IsGreaterOrEqualToken",
HaltCompilerToken: "HaltCompilerToken",
IdentifierToken: "IdentifierToken",
CaseSeparatorToken: "CaseSeparatorToken",
DoubleQuoteToken: "DoubleQuoteToken",
BackquoteToken: "BackquoteToken",
OpenCurlyBracesToken: "OpenCurlyBracesToken",
CloseCurlyBracesToken: "CloseCurlyBracesToken",
SemiColonToken: "SemiColonToken",
ColonToken: "ColonToken",
OpenParenthesisToken: "OpenParenthesisToken",
CloseParenthesisToken: "CloseParenthesisToken",
OpenSquareBracket: "OpenSquareBracket",
CloseSquareBracket: "CloseSquareBracket",
QuestionMarkToken: "QuestionMarkToken",
AmpersandToken: "AmpersandToken",
MinusToken: "MinusToken",
PlusToken: "PlusToken",
ExclamationMarkToken: "ExclamationMarkToken",
TildeToken: "TildeToken",
AtToken: "AtToken",
DollarToken: "DollarToken",
CommaToken: "CommaToken",
VerticalBarToken: "VerticalBarToken",
EqualToken: "EqualToken",
CaretToken: "CaretToken",
AsteriskToken: "AsteriskToken",
SlashToken: "SlashToken",
PercentToken: "PercentToken",
LessToken: "LessToken",
GreaterToken: "GreaterToken",
DotToken: "DotToken",
}

View File

@ -12,11 +12,11 @@ type TraitUse struct {
Meta []meta.Meta
Position *position.Position
Traits []node.Node
TraitAdaptationList *TraitAdaptationList
TraitAdaptationList node.Node
}
// NewTraitUse node constructor
func NewTraitUse(Traits []node.Node, InnerAdaptationList *TraitAdaptationList) *TraitUse {
func NewTraitUse(Traits []node.Node, InnerAdaptationList node.Node) *TraitUse {
return &TraitUse{
Traits: Traits,
TraitAdaptationList: InnerAdaptationList,

View File

@ -70,6 +70,14 @@ func TestTraitUse(t *testing.T) {
},
},
},
TraitAdaptationList: &stmt.Nop{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
EndPos: 23,
},
},
},
},
},
@ -163,6 +171,14 @@ func TestTraitsUse(t *testing.T) {
},
},
},
TraitAdaptationList: &stmt.Nop{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
EndPos: 28,
},
},
},
},
},

File diff suppressed because it is too large Load Diff

View File

@ -283,6 +283,10 @@ start:
yylex.(*Parser).rootNode.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($1))
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
if yylex.(*Parser).currentToken.Value == "\xff" {
addMeta(yylex.(*Parser).rootNode, yylex.(*Parser).currentToken.Meta, meta.NodeEnd)
}
}
;
@ -443,7 +447,7 @@ top_statement:
// save comments
addMeta($$, $1.Meta, meta.UseToken)
addMeta(useType, $2.Meta, meta.UseToken)
addMeta(useType, $2.Meta, meta.IdentifierToken)
addMeta($$, $4.Meta, meta.SemiColonToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -459,7 +463,7 @@ top_statement:
// save comments
addMeta($$, $1.Meta, meta.UseToken)
addMeta(useType, $2.Meta, meta.UseToken)
addMeta(useType, $2.Meta, meta.IdentifierToken)
addMeta($$, $4.Meta, meta.SemiColonToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -484,7 +488,7 @@ use_declarations:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -521,7 +525,7 @@ use_declaration:
// save comments
addMeta($$, $2.Meta, meta.AsToken)
addMeta(alias, $3.Meta, meta.StringToken)
addMeta(alias, $3.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -553,7 +557,7 @@ use_declaration:
// save comments
addMeta($$, $1.Meta, meta.NsSeparatorToken)
addMeta($$, $3.Meta, meta.AsToken)
addMeta($$, $4.Meta, meta.StringToken)
addMeta(alias, $4.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -565,7 +569,7 @@ use_function_declarations:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -602,7 +606,7 @@ use_function_declaration:
// save comments
addMeta($$, $2.Meta, meta.AsToken)
addMeta(alias, $3.Meta, meta.StringToken)
addMeta(alias, $3.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -634,7 +638,7 @@ use_function_declaration:
// save comments
addMeta($$, $1.Meta, meta.NsSeparatorToken)
addMeta($$, $3.Meta, meta.AsToken)
addMeta($$, $4.Meta, meta.StringToken)
addMeta(alias, $4.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -646,7 +650,7 @@ use_const_declarations:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -683,7 +687,7 @@ use_const_declaration:
// save comments
addMeta($$, $2.Meta, meta.AsToken)
addMeta(alias, $3.Meta, meta.StringToken)
addMeta(alias, $3.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -715,7 +719,7 @@ use_const_declaration:
// save comments
addMeta($$, $1.Meta, meta.NsSeparatorToken)
addMeta($$, $3.Meta, meta.AsToken)
addMeta($$, $4.Meta, meta.StringToken)
addMeta(alias, $4.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -737,7 +741,7 @@ constant_declaration:
// save comments
addMeta(lastNode(constList.Consts), $2.Meta, meta.CommaToken)
addMeta(name, $3.Meta, meta.StringToken)
addMeta(name, $3.Meta, meta.IdentifierToken)
addMeta(constant, $4.Meta, meta.EqualToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -756,7 +760,7 @@ constant_declaration:
// save comments
addMeta($$, $1.Meta, meta.ConstToken)
addMeta(name, $2.Meta, meta.StringToken)
addMeta(name, $2.Meta, meta.IdentifierToken)
addMeta(constant, $3.Meta, meta.EqualToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -842,7 +846,7 @@ statement:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $2))
// save comments
addMeta(label, $1.Meta, meta.StringToken)
addMeta(label, $1.Meta, meta.IdentifierToken)
addMeta($$, $2.Meta, meta.ColonToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -1302,7 +1306,7 @@ unticked_statement:
// save comments
addMeta($$, $1.Meta, meta.GotoToken)
addMeta(label, $2.Meta, meta.StringToken)
addMeta(label, $2.Meta, meta.IdentifierToken)
addMeta($$, $3.Meta, meta.SemiColonToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -1331,7 +1335,7 @@ catch_statement:
// save comments
addMeta(catch, $1.Meta, meta.CatchToken)
addMeta(catch, $2.Meta, meta.OpenParenthesisToken)
addMeta(variable, $4.Meta, meta.StringToken)
addMeta(variable, $4.Meta, meta.VariableToken)
addMeta(catch, $5.Meta, meta.CloseParenthesisToken)
addMeta(catch, $6.Meta, meta.OpenCurlyBracesToken)
addMeta(catch, $8.Meta, meta.CloseCurlyBracesToken)
@ -1408,7 +1412,7 @@ additional_catch:
// save comments
addMeta($$, $1.Meta, meta.CatchToken)
addMeta($$, $2.Meta, meta.OpenParenthesisToken)
addMeta(variable, $4.Meta, meta.StringToken)
addMeta(variable, $4.Meta, meta.VariableToken)
addMeta($$, $5.Meta, meta.CloseParenthesisToken)
addMeta($$, $6.Meta, meta.OpenCurlyBracesToken)
addMeta($$, $8.Meta, meta.CloseCurlyBracesToken)
@ -1429,7 +1433,7 @@ unset_variables:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -1499,7 +1503,7 @@ unticked_function_declaration_statement:
if $2 != nil {
addMeta($$, $2.Meta, meta.AmpersandToken)
}
addMeta(name, $3.Meta, meta.StringToken)
addMeta(name, $3.Meta, meta.IdentifierToken)
addMeta($$, $4.Meta, meta.OpenParenthesisToken)
addMeta($$, $6.Meta, meta.CloseParenthesisToken)
addMeta($$, $7.Meta, meta.OpenCurlyBracesToken)
@ -1532,7 +1536,7 @@ unticked_class_declaration_statement:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeTokenPosition($1, $7))
// save comments
addMeta(name, $2.Meta, meta.StringToken)
addMeta(name, $2.Meta, meta.IdentifierToken)
addMeta($$, $5.Meta, meta.OpenCurlyBracesToken)
addMeta($$, $7.Meta, meta.CloseCurlyBracesToken)
@ -1548,7 +1552,7 @@ unticked_class_declaration_statement:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $6))
// save comments
addMeta(name, $2.Meta, meta.StringToken)
addMeta(name, $2.Meta, meta.IdentifierToken)
addMeta($$, $4.Meta, meta.OpenCurlyBracesToken)
addMeta($$, $6.Meta, meta.CloseCurlyBracesToken)
@ -1580,7 +1584,7 @@ class_entry_type:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $2))
// save comments
addMeta(classModifier, $1.Meta, meta.AbstractToken)
addMeta(classModifier, $1.Meta, meta.IdentifierToken)
addMeta($$, $2.Meta, meta.ClassToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -1607,7 +1611,7 @@ class_entry_type:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $2))
// save comments
addMeta(classModifier, $1.Meta, meta.FinalToken)
addMeta(classModifier, $1.Meta, meta.IdentifierToken)
addMeta($$, $2.Meta, meta.ClassToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -1696,7 +1700,7 @@ interface_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -1848,7 +1852,7 @@ declare_list:
constant.SetPosition(yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $3))
// save comments
addMeta(name, $1.Meta, meta.StringToken)
addMeta(name, $1.Meta, meta.IdentifierToken)
addMeta(constant, $2.Meta, meta.EqualToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -1865,7 +1869,7 @@ declare_list:
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(name, $3.Meta, meta.StringToken)
addMeta(name, $3.Meta, meta.IdentifierToken)
addMeta(constant, $4.Meta, meta.EqualToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -1915,8 +1919,8 @@ switch_case_list:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4))
// save comments
addMeta(caseList, $1.Meta, meta.ColonToken)
addMeta(caseList, $3.Meta, meta.EndswitchToken)
addMeta($$, $1.Meta, meta.ColonToken)
addMeta($$, $3.Meta, meta.EndswitchToken)
addMeta($$, $4.Meta, meta.SemiColonToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -1932,9 +1936,9 @@ switch_case_list:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $5))
// save comments
addMeta(caseList, $1.Meta, meta.ColonToken)
addMeta(caseList, $2.Meta, meta.SemiColonToken)
addMeta(caseList, $4.Meta, meta.EndswitchToken)
addMeta($$, $1.Meta, meta.ColonToken)
addMeta($$, $2.Meta, meta.SwitchSemicolonToken)
addMeta($$, $4.Meta, meta.EndswitchToken)
addMeta($$, $5.Meta, meta.SemiColonToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -2145,7 +2149,7 @@ non_empty_parameter_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2231,7 +2235,7 @@ optional_class_type:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.ArrayToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2243,7 +2247,7 @@ optional_class_type:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.CallableToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2313,7 +2317,7 @@ non_empty_function_call_parameter_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2370,7 +2374,7 @@ global_var_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2579,14 +2583,7 @@ class_statement:
trait_use_statement:
T_USE trait_list trait_adaptations
{
var adaptationList *stmt.TraitAdaptationList
switch n := $3.(type) {
case *stmt.TraitAdaptationList:
adaptationList = n
default:
adaptationList = nil
}
$$ = stmt.NewTraitUse($2, adaptationList)
$$ = stmt.NewTraitUse($2, $3)
// save position
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $3))
@ -2610,7 +2607,7 @@ trait_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2721,7 +2718,7 @@ trait_reference_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2857,7 +2854,7 @@ variable_modifiers:
modifier.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta(modifier, $1.Meta, meta.VarToken)
addMeta(modifier, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2902,7 +2899,7 @@ member_modifier:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.PublicToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2914,7 +2911,7 @@ member_modifier:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.ProtectedToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2926,7 +2923,7 @@ member_modifier:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.PrivateToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2938,7 +2935,7 @@ member_modifier:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.StaticToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2950,7 +2947,7 @@ member_modifier:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.AbstractToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2962,7 +2959,7 @@ member_modifier:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.FinalToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -3090,7 +3087,7 @@ echo_expr_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -3124,7 +3121,7 @@ non_empty_for_expr:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4507,7 +4504,7 @@ class_name:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.StaticToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4786,7 +4783,7 @@ common_scalar:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.LineToken)
addMeta($$, $1.Meta, meta.MagicConstantToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4798,7 +4795,7 @@ common_scalar:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.FileToken)
addMeta($$, $1.Meta, meta.MagicConstantToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4810,7 +4807,7 @@ common_scalar:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.DirToken)
addMeta($$, $1.Meta, meta.MagicConstantToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4822,7 +4819,7 @@ common_scalar:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.TraitCToken)
addMeta($$, $1.Meta, meta.MagicConstantToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4834,7 +4831,7 @@ common_scalar:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.MethodCToken)
addMeta($$, $1.Meta, meta.MagicConstantToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4846,7 +4843,7 @@ common_scalar:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.FuncCToken)
addMeta($$, $1.Meta, meta.MagicConstantToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4858,7 +4855,7 @@ common_scalar:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.NsCToken)
addMeta($$, $1.Meta, meta.MagicConstantToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4951,8 +4948,8 @@ static_scalar_value:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenNodeListPosition($1, $3))
// save comments
addMeta($$, $1.Meta, meta.NamespaceToken)
addMeta($$, $2.Meta, meta.NsSeparatorToken)
addMeta(name, $1.Meta, meta.NamespaceToken)
addMeta(name, $2.Meta, meta.NsSeparatorToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4966,7 +4963,7 @@ static_scalar_value:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenNodeListPosition($1, $2))
// save comments
addMeta($$, $1.Meta, meta.NsSeparatorToken)
addMeta(name, $1.Meta, meta.NsSeparatorToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -5011,7 +5008,7 @@ static_scalar_value:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.ClassCToken)
addMeta($$, $1.Meta, meta.MagicConstantToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -5449,8 +5446,8 @@ general_constant:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodePosition(name))
// save comments
addMeta($$, $1.Meta, meta.NamespaceToken)
addMeta($$, $2.Meta, meta.NsSeparatorToken)
addMeta(name, $1.Meta, meta.NamespaceToken)
addMeta(name, $2.Meta, meta.NsSeparatorToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -5464,7 +5461,7 @@ general_constant:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodePosition(name))
// save comments
addMeta($$, $1.Meta, meta.NsSeparatorToken)
addMeta(name, $1.Meta, meta.NsSeparatorToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -5481,7 +5478,7 @@ scalar:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta(name, $1.Meta, meta.StringVarnameToken)
addMeta(name, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -5535,7 +5532,7 @@ scalar:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.ClassCToken)
addMeta($$, $1.Meta, meta.MagicConstantToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -5645,12 +5642,20 @@ parenthesis_expr:
{
$$ = $2
// save comments
addMeta($$, $1.Meta, meta.OpenParenthesisToken)
addMeta($$, $3.Meta, meta.CloseParenthesisToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
| '(' yield_expr ')'
{
$$ = $2
// save comments
addMeta($$, $1.Meta, meta.OpenParenthesisToken)
addMeta($$, $3.Meta, meta.CloseParenthesisToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
;
@ -6129,7 +6134,7 @@ variable_name:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.StringToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -6191,7 +6196,7 @@ assignment_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -6474,7 +6479,7 @@ encaps_var:
// save comments
addMeta(variable, $1.Meta, meta.VariableToken)
addMeta($$, $2.Meta, meta.ObjectOperatorToken)
addMeta(fetch, $3.Meta, meta.StringToken)
addMeta(fetch, $3.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -6502,7 +6507,7 @@ encaps_var:
// save comments
addMeta($$, $1.Meta, meta.DollarOpenCurlyBracesToken)
addMeta(name, $2.Meta, meta.StringVarnameToken)
addMeta(name, $2.Meta, meta.IdentifierToken)
addMeta($$, $3.Meta, meta.CloseCurlyBracesToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -6700,7 +6705,7 @@ isset_variables:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -6733,6 +6738,7 @@ class_constant:
// save comments
addMeta($$, $2.Meta, meta.PaamayimNekudotayimToken)
addMeta(target, $3.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -6747,6 +6753,7 @@ class_constant:
// save comments
addMeta($$, $2.Meta, meta.PaamayimNekudotayimToken)
addMeta(target, $3.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -6764,6 +6771,7 @@ static_class_name_scalar:
// save comments
addMeta($$, $2.Meta, meta.PaamayimNekudotayimToken)
addMeta(target, $3.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -6781,6 +6789,7 @@ class_name_scalar:
// save comments
addMeta($$, $2.Meta, meta.PaamayimNekudotayimToken)
addMeta(target, $3.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}

View File

@ -470,8 +470,8 @@ func TestPhp5(t *testing.T) {
StartPos: 10,
EndPos: 11,
},
IsReference: false,
Variadic: false,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 2,
@ -497,8 +497,8 @@ func TestPhp5(t *testing.T) {
StartPos: 14,
EndPos: 18,
},
IsReference: false,
Variadic: true,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 2,
@ -567,8 +567,8 @@ func TestPhp5(t *testing.T) {
StartPos: 29,
EndPos: 30,
},
Variadic: false,
IsReference: false,
Variadic: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 3,
@ -700,8 +700,8 @@ func TestPhp5(t *testing.T) {
StartPos: 57,
EndPos: 61,
},
Variadic: true,
IsReference: false,
Variadic: true,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 4,
@ -887,8 +887,8 @@ func TestPhp5(t *testing.T) {
StartPos: 100,
EndPos: 101,
},
IsReference: false,
Variadic: false,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 6,
@ -914,8 +914,8 @@ func TestPhp5(t *testing.T) {
StartPos: 104,
EndPos: 108,
},
Variadic: true,
IsReference: false,
Variadic: true,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 6,
@ -1044,8 +1044,8 @@ func TestPhp5(t *testing.T) {
StartPos: 137,
EndPos: 180,
},
ReturnsRef: false,
PhpDocComment: "",
ReturnsRef: false,
FunctionName: &node.Identifier{
Position: &position.Position{
StartLine: 9,
@ -1383,8 +1383,8 @@ func TestPhp5(t *testing.T) {
StartPos: 259,
EndPos: 271,
},
ByRef: false,
Variadic: false,
ByRef: false,
VariableType: &name.Name{
Position: &position.Position{
StartLine: 11,
@ -1513,9 +1513,9 @@ func TestPhp5(t *testing.T) {
StartPos: 294,
EndPos: 340,
},
ReturnsRef: false,
Static: true,
PhpDocComment: "",
ReturnsRef: false,
Params: []node.Node{
&node.Parameter{
Position: &position.Position{
@ -4624,8 +4624,8 @@ func TestPhp5(t *testing.T) {
StartPos: 2104,
EndPos: 2120,
},
PhpDocComment: "",
ReturnsRef: false,
PhpDocComment: "",
FunctionName: &node.Identifier{
Position: &position.Position{
StartLine: 90,
@ -6441,6 +6441,14 @@ func TestPhp5(t *testing.T) {
},
},
},
TraitAdaptationList: &stmt.Nop{
Position: &position.Position{
StartLine: 142,
EndLine: 142,
StartPos: 3077,
EndPos: 3077,
},
},
},
},
},
@ -8626,9 +8634,9 @@ func TestPhp5(t *testing.T) {
StartPos: 3963,
EndPos: 3995,
},
ReturnsRef: false,
Static: false,
PhpDocComment: "",
ReturnsRef: false,
Params: []node.Node{
&node.Parameter{
Position: &position.Position{

File diff suppressed because it is too large Load Diff

View File

@ -15,6 +15,8 @@ import (
"github.com/z7zmey/php-parser/node/expr/assign"
"github.com/z7zmey/php-parser/node/expr/binary"
"github.com/z7zmey/php-parser/node/expr/cast"
"github.com/davecgh/go-spew/spew"
)
%}
@ -304,6 +306,10 @@ start:
yylex.(*Parser).rootNode.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($1))
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
if yylex.(*Parser).currentToken.Value == "\xff" {
addMeta(yylex.(*Parser).rootNode, yylex.(*Parser).currentToken.Meta, meta.NodeEnd)
}
}
;
@ -594,7 +600,7 @@ use_type:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.FunctionToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -606,7 +612,7 @@ use_type:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.ConstToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -713,7 +719,7 @@ inline_use_declarations:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -731,7 +737,7 @@ unprefixed_use_declarations:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -749,7 +755,7 @@ use_declarations:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -801,7 +807,7 @@ unprefixed_use_declaration:
// save comments
addMeta($$, $2.Meta, meta.AsToken)
addMeta(alias, $3.Meta, meta.StringToken)
addMeta(alias, $3.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -831,7 +837,7 @@ const_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -1265,7 +1271,7 @@ statement:
// save comments
addMeta($$, $1.Meta, meta.GotoToken)
addMeta(label, $2.Meta, meta.StringToken)
addMeta(label, $2.Meta, meta.IdentifierToken)
addMeta($$, $3.Meta, meta.SemiColonToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -1280,7 +1286,7 @@ statement:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $2))
// save comments
addMeta(label, $1.Meta, meta.StringToken)
addMeta(label, $1.Meta, meta.IdentifierToken)
addMeta($$, $2.Meta, meta.ColonToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -1308,7 +1314,7 @@ catch_list:
// save comments
addMeta(catch, $2.Meta, meta.CatchToken)
addMeta(catch, $3.Meta, meta.OpenParenthesisToken)
addMeta(variable, $5.Meta, meta.StringToken)
addMeta(variable, $5.Meta, meta.VariableToken)
addMeta(catch, $6.Meta, meta.CloseParenthesisToken)
addMeta(catch, $7.Meta, meta.OpenCurlyBracesToken)
addMeta(catch, $9.Meta, meta.CloseCurlyBracesToken)
@ -1328,7 +1334,7 @@ catch_name_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.VerticalBarToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -1369,7 +1375,7 @@ unset_variables:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -1400,7 +1406,7 @@ function_declaration_statement:
if $2 != nil {
addMeta($$, $2.Meta, meta.AmpersandToken)
}
addMeta(name, $3.Meta, meta.StringToken)
addMeta(name, $3.Meta, meta.IdentifierToken)
addMeta($$, $5.Meta, meta.OpenParenthesisToken)
addMeta($$, $7.Meta, meta.CloseParenthesisToken)
addMeta($$, $9.Meta, meta.OpenCurlyBracesToken)
@ -1444,7 +1450,7 @@ class_declaration_statement:
// save comments
addMeta($$, $2.Meta, meta.ClassToken)
addMeta(name, $3.Meta, meta.StringToken)
addMeta(name, $3.Meta, meta.IdentifierToken)
addMeta($$, $7.Meta, meta.OpenCurlyBracesToken)
addMeta($$, $9.Meta, meta.CloseCurlyBracesToken)
@ -1461,7 +1467,7 @@ class_declaration_statement:
// save comments
addMeta($$, $1.Meta, meta.ClassToken)
addMeta(name, $2.Meta, meta.StringToken)
addMeta(name, $2.Meta, meta.IdentifierToken)
addMeta($$, $6.Meta, meta.OpenCurlyBracesToken)
addMeta($$, $8.Meta, meta.CloseCurlyBracesToken)
@ -1493,7 +1499,7 @@ class_modifier:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.AbstractToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -1505,7 +1511,7 @@ class_modifier:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.FinalToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -1523,7 +1529,7 @@ trait_declaration_statement:
// save comments
addMeta($$, $1.Meta, meta.TraitToken)
addMeta(name, $2.Meta, meta.StringToken)
addMeta(name, $2.Meta, meta.IdentifierToken)
addMeta($$, $4.Meta, meta.OpenCurlyBracesToken)
addMeta($$, $6.Meta, meta.CloseCurlyBracesToken)
@ -1543,7 +1549,7 @@ interface_declaration_statement:
// save comments
addMeta($$, $1.Meta, meta.InterfaceToken)
addMeta(name, $2.Meta, meta.StringToken)
addMeta(name, $2.Meta, meta.IdentifierToken)
addMeta($$, $5.Meta, meta.OpenCurlyBracesToken)
addMeta($$, $7.Meta, meta.CloseCurlyBracesToken)
@ -1783,8 +1789,8 @@ switch_case_list:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4))
// save comments
addMeta(caseList, $1.Meta, meta.ColonToken)
addMeta(caseList, $3.Meta, meta.EndswitchToken)
addMeta($$, $1.Meta, meta.ColonToken)
addMeta($$, $3.Meta, meta.EndswitchToken)
addMeta($$, $4.Meta, meta.SemiColonToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -1800,9 +1806,9 @@ switch_case_list:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $5))
// save comments
addMeta(caseList, $1.Meta, meta.ColonToken)
addMeta(caseList, $2.Meta, meta.SemiColonToken)
addMeta(caseList, $4.Meta, meta.EndswitchToken)
addMeta($$, $1.Meta, meta.ColonToken)
addMeta($$, $2.Meta, meta.SwitchSemicolonToken)
addMeta($$, $4.Meta, meta.EndswitchToken)
addMeta($$, $5.Meta, meta.SemiColonToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -1935,7 +1941,7 @@ if_stmt:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodesPosition($1, $3))
// save comments
addMeta($$, $2.Meta, meta.ElseToken)
addMeta(_else, $2.Meta, meta.ElseToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2041,7 +2047,7 @@ non_empty_parameter_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2156,7 +2162,7 @@ type:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.ArrayToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2168,7 +2174,7 @@ type:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.CallableToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2242,7 +2248,7 @@ non_empty_argument_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2278,7 +2284,7 @@ global_var_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2305,7 +2311,7 @@ static_var_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2396,16 +2402,7 @@ class_statement:
}
| T_USE name_list trait_adaptations
{
var adaptationList *stmt.TraitAdaptationList
switch n := $3.(type) {
case *stmt.TraitAdaptationList:
adaptationList = n
default:
adaptationList = nil
}
$$ = stmt.NewTraitUse($2, adaptationList)
$$ = stmt.NewTraitUse($2, $3)
// save position
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $3))
@ -2453,7 +2450,7 @@ name_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2561,7 +2558,7 @@ trait_alias:
// save comments
addMeta($$, $2.Meta, meta.AsToken)
addMeta(alias, $3.Meta, meta.StringToken)
addMeta(alias, $3.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2576,7 +2573,7 @@ trait_alias:
// save comments
addMeta($$, $2.Meta, meta.AsToken)
addMeta(alias, $3.Meta, meta.StringToken)
addMeta(alias, $3.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2694,7 +2691,7 @@ variable_modifiers:
modifier.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta(modifier, $1.Meta, meta.VarToken)
addMeta(modifier, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2739,7 +2736,7 @@ member_modifier:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.PublicToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2751,7 +2748,7 @@ member_modifier:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.ProtectedToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2763,7 +2760,7 @@ member_modifier:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.PrivateToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2775,7 +2772,7 @@ member_modifier:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.StaticToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2787,7 +2784,7 @@ member_modifier:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.AbstractToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2799,7 +2796,7 @@ member_modifier:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.FinalToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2811,7 +2808,7 @@ property_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2865,7 +2862,7 @@ class_const_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2906,7 +2903,7 @@ const_decl:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $3))
// save comments
addMeta(name, $1.Meta, meta.StringToken)
addMeta(name, $1.Meta, meta.IdentifierToken)
addMeta($$, $2.Meta, meta.EqualToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -2919,7 +2916,7 @@ echo_expr_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2961,7 +2958,7 @@ non_empty_for_exprs:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4012,7 +4009,7 @@ lexical_var_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4112,7 +4109,7 @@ class_name:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.StaticToken)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4154,8 +4151,8 @@ exit_expr:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $3))
// save comments
addMeta($$, $1.Meta, meta.OpenParenthesisToken)
addMeta($$, $3.Meta, meta.CloseParenthesisToken)
addMeta($2, $1.Meta, meta.OpenParenthesisToken)
addMeta($2, $3.Meta, meta.CloseParenthesisToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4272,7 +4269,7 @@ scalar:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.LineToken)
addMeta($$, $1.Meta, meta.MagicConstantToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4284,7 +4281,7 @@ scalar:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.FileToken)
addMeta($$, $1.Meta, meta.MagicConstantToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4296,7 +4293,7 @@ scalar:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.DirToken)
addMeta($$, $1.Meta, meta.MagicConstantToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4308,7 +4305,7 @@ scalar:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.TraitCToken)
addMeta($$, $1.Meta, meta.MagicConstantToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4320,7 +4317,7 @@ scalar:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.MethodCToken)
addMeta($$, $1.Meta, meta.MagicConstantToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4332,7 +4329,7 @@ scalar:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.FuncCToken)
addMeta($$, $1.Meta, meta.MagicConstantToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4344,7 +4341,7 @@ scalar:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.NsCToken)
addMeta($$, $1.Meta, meta.MagicConstantToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4356,7 +4353,7 @@ scalar:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.ClassCToken)
addMeta($$, $1.Meta, meta.MagicConstantToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4829,7 +4826,8 @@ property_name:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
addMeta($$, $1.Meta, meta.StringToken)
spew.Dump($1.Meta)
addMeta($$, $1.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4885,7 +4883,7 @@ non_empty_array_pair_list:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -5079,7 +5077,7 @@ encaps_var:
// save comments
addMeta(variable, $1.Meta, meta.VariableToken)
addMeta($$, $2.Meta, meta.ObjectOperatorToken)
addMeta(fetch, $3.Meta, meta.StringToken)
addMeta(fetch, $3.Meta, meta.IdentifierToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -5107,7 +5105,7 @@ encaps_var:
// save comments
addMeta($$, $1.Meta, meta.DollarOpenCurlyBracesToken)
addMeta(name, $2.Meta, meta.StringVarnameToken)
addMeta(name, $2.Meta, meta.IdentifierToken)
addMeta($$, $3.Meta, meta.CloseCurlyBracesToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -5325,7 +5323,7 @@ isset_variables:
$$ = append($1, $3)
// save comments
addMeta(lastNode($1), $2.Meta, meta.CommaToken)
addMeta(lastNode($1), $2.Meta, meta.NodeEnd)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}

View File

@ -464,8 +464,8 @@ func TestPhp7(t *testing.T) {
StartPos: 14,
EndPos: 18,
},
IsReference: false,
Variadic: true,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 2,
@ -561,8 +561,8 @@ func TestPhp7(t *testing.T) {
StartPos: 33,
EndPos: 37,
},
Variadic: true,
IsReference: false,
Variadic: true,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 3,
@ -640,8 +640,8 @@ func TestPhp7(t *testing.T) {
StartPos: 53,
EndPos: 54,
},
IsReference: false,
Variadic: false,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 4,
@ -667,8 +667,8 @@ func TestPhp7(t *testing.T) {
StartPos: 57,
EndPos: 61,
},
Variadic: true,
IsReference: false,
Variadic: true,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 4,
@ -775,8 +775,8 @@ func TestPhp7(t *testing.T) {
StartPos: 80,
EndPos: 84,
},
Variadic: true,
IsReference: false,
Variadic: true,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 5,
@ -881,8 +881,8 @@ func TestPhp7(t *testing.T) {
StartPos: 104,
EndPos: 108,
},
Variadic: true,
IsReference: false,
Variadic: true,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 6,
@ -1862,8 +1862,8 @@ func TestPhp7(t *testing.T) {
StartPos: 446,
EndPos: 457,
},
ByRef: true,
Variadic: true,
ByRef: true,
VariableType: &name.Name{
Position: &position.Position{
StartLine: 20,
@ -2011,8 +2011,8 @@ func TestPhp7(t *testing.T) {
StartPos: 498,
EndPos: 509,
},
Variadic: true,
ByRef: true,
Variadic: true,
VariableType: &name.Name{
Position: &position.Position{
StartLine: 21,
@ -3743,8 +3743,8 @@ func TestPhp7(t *testing.T) {
StartPos: 1549,
EndPos: 1580,
},
PhpDocComment: "",
ReturnsRef: true,
PhpDocComment: "",
MethodName: &node.Identifier{
Position: &position.Position{
StartLine: 73,
@ -3811,8 +3811,8 @@ func TestPhp7(t *testing.T) {
StartPos: 1597,
EndPos: 1634,
},
ReturnsRef: true,
PhpDocComment: "",
ReturnsRef: true,
MethodName: &node.Identifier{
Position: &position.Position{
StartLine: 74,
@ -6749,6 +6749,14 @@ func TestPhp7(t *testing.T) {
},
},
},
TraitAdaptationList: &stmt.Nop{
Position: &position.Position{
StartLine: 147,
EndLine: 147,
StartPos: 3164,
EndPos: 3164,
},
},
},
},
},
@ -9277,9 +9285,9 @@ func TestPhp7(t *testing.T) {
StartPos: 4157,
EndPos: 4189,
},
PhpDocComment: "",
ReturnsRef: false,
Static: false,
PhpDocComment: "",
Params: []node.Node{
&node.Parameter{
Position: &position.Position{
@ -14978,8 +14986,8 @@ func TestPhp7(t *testing.T) {
StartPos: 5933,
EndPos: 5975,
},
PhpDocComment: "",
ReturnsRef: false,
PhpDocComment: "",
FunctionName: &node.Identifier{
Position: &position.Position{
StartLine: 329,
@ -15033,8 +15041,8 @@ func TestPhp7(t *testing.T) {
StartPos: 5955,
EndPos: 5963,
},
Variadic: true,
ByRef: false,
Variadic: true,
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 329,
@ -15108,8 +15116,8 @@ func TestPhp7(t *testing.T) {
StartPos: 5979,
EndPos: 6016,
},
ReturnsRef: false,
PhpDocComment: "",
ReturnsRef: false,
FunctionName: &node.Identifier{
Position: &position.Position{
StartLine: 330,

2182
printer/pretty_printer.go Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,955 @@
package printer_test
import (
"bytes"
"os"
"testing"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php7"
"github.com/z7zmey/php-parser/printer"
)
func ExamplePrinter() {
src := `<?php
namespace Foo;
abstract class Bar extends Baz
{
public function greet()
{
echo "Hello";
// some comment
}
}
`
// parse
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser.WithMeta()
php7parser.Parse()
rootNode := php7parser.GetRootNode()
// change
parts := &rootNode.(*node.Root).Stmts[0].(*stmt.Namespace).NamespaceName.(*name.Name).Parts
*parts = append(*parts, &name.NamePart{Value: "Quuz"})
// print
p := printer.NewPrinter(os.Stdout)
p.Print(rootNode)
// Output:
//<?php
//
// namespace Foo\Quuz;
//
// abstract class Bar extends Baz
// {
// public function greet()
// {
// echo "Hello";
// // some comment
// }
// }
}
func parse(src string) node.Node {
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser.WithMeta()
php7parser.Parse()
return php7parser.GetRootNode()
}
func print(n node.Node) string {
o := bytes.NewBufferString("")
p := printer.NewPrinter(o)
p.Print(n)
return o.String()
}
func TestParseAndPrintRoot(t *testing.T) {
src := `<?php
namespace Foo;
abstract class Bar extends Baz
{
public function greet()
{
echo "Hello World";
}
}`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintRootWithMeta(t *testing.T) {
src := `<?php
namespace Foo;
abstract class Bar extends Baz
{
public function greet()
{
echo "Hello World";
}
}
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintRootWithHtml(t *testing.T) {
src := `<div>Hello</div>
<?php
$a;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintFunctionAndParameter(t *testing.T) {
src := `<?php
function & foo (
? int $a , & $b = null
, \ Foo ...$c
) : namespac \ Bar {
;
}`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintFunctionCallAndArgument(t *testing.T) {
src := `<?php
foo ( $a , $b
, ... $c
) ; `
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintIncludeAndRequire(t *testing.T) {
src := `<?php
include 'foo' ;
include_once 'bar' ;
require __DIR__ . '/folder' ;
require_once $a ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintIfInstanceOfMethodCallIssetListEcho(t *testing.T) {
src := `<?php
if ( $a instanceof Foo ) {
$a -> bar ( ' ' ) ;
} elseif ( isset ( $b [ 2 ] ) )
list( , $c , ) = $b;
else if ( 1 );
else {
echo '' ;
}`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintNew(t *testing.T) {
src := `<?php
new Foo ;
new Foo ( $a, $b ) ;
new class ( $c ) extends Foo implements Bar , Baz {
} ; `
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintIncDec(t *testing.T) {
src := `<?php
++ $a ;
-- $a ;
$a ++ ;
$a -- ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintPropertyFetchPrint(t *testing.T) {
src := `<?php
$a -> b ;
print ( $a ) ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintForeachReferenceShellExec(t *testing.T) {
src := `<?php
foreach ( $a as $k => & $v ) {
` + "` $v cmd `" + ` ;
}`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintShortListShortArray(t *testing.T) {
src := `<?php
$a = [0, 1, 2] ;
[ , $b ,] = $a ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintStaticCallStaticPropertyFetch(t *testing.T) {
src := `<?php
Foo :: bar ( $a , $b ) ;
Foo :: $bar ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintTernary(t *testing.T) {
src := `<?php
$a ? $b : $c ;
$a ? : $c ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintUnaryPlusMinus(t *testing.T) {
src := `<?php
+ $a ;
- $a ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintYield(t *testing.T) {
src := `<?php
yield $a ;
yield $k => $v ;
yield from $a ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintAltIfExitDie(t *testing.T) {
src := `<?php
if ( 1 ) :
exit ( 1 ) ;
elseif ( 2 ) :
die ( 2 );
else :
;
endif ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintAltFor(t *testing.T) {
src := `<?php
for ( $a ; $b ; $c ) :
endfor ;
for ( ; ; ) :
endfor ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintAltForeach(t *testing.T) {
src := `<?php
foreach ( $a as $k => & $v ) :
echo $v ;
endforeach ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintAltSwitchCaseBreakContinueDefault(t *testing.T) {
src := `<?php
switch ( $a ) : ;
case 1 :
break ;
case 2 :
break ( 2 ) ;
case 3 :
continue ;
default :
continue ( 2 ) ;
endswitch ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintAltWhile(t *testing.T) {
src := `<?php
while ( $a ) :
;
endwhile ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintTryCatchFinally(t *testing.T) {
src := `<?php
try {
} catch ( \ Exception | \ Foo \ Bar $e) {
} finally {
}`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintClassMethodProperty(t *testing.T) {
src := `<?php
abstract final class Foo extends Bar implements Baz , Quuz {
public const FOO = 'f' , BAR = 'b' ;
var $a = '' , $b = null , $c ;
public static function & greet ( ? Foo $a ) : void ;
function greet ( string $a )
{
return 'hello';
}
}`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintDeclare(t *testing.T) {
src := `<?php
declare ( FOO = 'bar' ) {
;
}
declare ( FOO = 'bar' ) ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintEmpty(t *testing.T) {
src := `<?php
empty ( $a ) ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintIfElseIfElse(t *testing.T) {
src := `<?php
if ( 1 ) ;
elseif ( 2 ) {
;
}
else if ( 3 ) $a;
else { }`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintFor(t *testing.T) {
src := `<?php
for ( $i = 0 ; $i < 3 ; $i ++ )
echo $i . PHP_EOL;
for ( ; ; ) {
}`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintGlobal(t *testing.T) {
src := `<?php
global $a , $b ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintGotoLabel(t *testing.T) {
src := `<?php
Foo :
goto Foo ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintUseGroupUse(t *testing.T) {
src := `<?php
use const Foo as Bar, baz ;
use function Foo \ { Bar as Baz , Quuz } ;
use Foo \ { function Bar as Baz , const Quuz } ;
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintHaltCompiller(t *testing.T) {
src := `<?php
__halt_compiler ( ) ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintInlineHtml(t *testing.T) {
src := `<?php
$a;?>test<?php `
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintInterface(t *testing.T) {
src := `<?php
interface Foo extends Bar , Baz {
}`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintNamespace(t *testing.T) {
src := `<?php
namespace Foo \ Bar ;
namespace Baz {
}
namespace {
}
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintStaticVar(t *testing.T) {
src := `<?php
static $a , $b = foo ( ) ;
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintSwitchCaseDefault(t *testing.T) {
src := `<?php
switch ( $a ) {
case 1 : ;
default : ;
}`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintThrow(t *testing.T) {
src := `<?php
throw new \ Exception ( "msg" ) ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintTraitUse(t *testing.T) {
src := `<?php
class foo {
use foo , bar ;
use foo , bar { }
use foo , bar {
foo :: a as b ;
bar :: a insteadof foo ;
foo :: c as public ;
foo :: d as public e;
f as g ;
}
}`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintTrait(t *testing.T) {
src := `<?php
trait foo {
function bar ( ) { }
}`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintUnset(t *testing.T) {
src := `<?php
unset ( $a ) ;`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintWhile(t *testing.T) {
src := `<?php
while ( $a ) echo '' ;
while ( $a ) { }
while ( $a ) ;
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintDoWhile(t *testing.T) {
src := `<?php
do { ; } while ( $a ) ;
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintNames(t *testing.T) {
src := `<?php
new \ Exception ;
new namespace \ Exception ;
new Exception ;
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintScalar(t *testing.T) {
src := `<?php
1 ;
.2 ;
0.2 ;
'Hello' ;
"Hello $world";
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintHeredoc(t *testing.T) {
src := `<?php
foo(<<<EAP
test
EAP
, 'test'
);
<<<EAP
test
EAP;
<<<'EAP'
test
EAP;
<<<"EAP"
test
EAP;
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintMagicConstant(t *testing.T) {
src := `<?php
__CLASS__ ;
__DIR__ ;
__FILE__ ;
__FUNCTION__ ;
__LINE__ ;
__NAMESPACE__ ;
__METHOD__ ;
__TRAIT__ ;
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintAssign(t *testing.T) {
src := `<?php
$a = $b ;
$a = & $b ;
$a &= $b ;
$a |= $b ;
$a ^= $b ;
$a .= $b ;
$a /= $b ;
$a -= $b ;
$a %= $b ;
$a *= $b ;
$a += $b ;
$a **= $b ;
$a <<= $b ;
$a >>= $b ;
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintBinary(t *testing.T) {
src := `<?php
$a & $b ;
$a | $b ;
$a ^ $b ;
$a && $b ;
$a || $b ;
$a ?? $b ;
$a . $b ;
$a / $b ;
$a == $b ;
$a >= $b ;
$a > $b ;
$a === $b ;
$a and $b ;
$a or $b ;
$a xor $b ;
$a - $b ;
$a % $b ;
$a * $b ;
$a != $b ;
$a !== $b ;
$a + $b ;
$a ** $b ;
$a << $b ;
$a >> $b ;
$a <= $b ;
$a < $b ;
$a <=> $b ;
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintUnary(t *testing.T) {
src := `<?php
~ $var ;
! $var ;
+ $var ;
- $var ;
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintCast(t *testing.T) {
src := `<?php
(array) $a ;
(bool) $a ;
(float) $a ;
(int) $a ;
(object) $a ;
(string) $a ;
(unset) $a ;
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintArray(t *testing.T) {
src := `<?php
$a [ 0 ] ;
$a = [ 0 , 2 => 2 ] ;
$a = array( 0 , 2 => 2 ) ;
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintClassConstFetch(t *testing.T) {
src := `<?php
$var :: CONST ;
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintClone(t *testing.T) {
src := `<?php
clone $var ;
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintClosure(t *testing.T) {
src := `<?php
$a = static function & ( ) use ( $a , & $b ) : void { } ;
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintConstFetch(t *testing.T) {
src := `<?php
null ;
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintErrorSupress(t *testing.T) {
src := `<?php
@ foo ( ) ;
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintEval(t *testing.T) {
src := `<?php
eval ( " " ) ;
`
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}

File diff suppressed because it is too large Load Diff

View File

@ -38,6 +38,7 @@ type Lexer struct {
tokenBytesBuf *bytes.Buffer
TokenPool sync.Pool
WithMeta bool
lastToken *Token
}
// Rune2Class returns the rune integer id

File diff suppressed because it is too large Load Diff

View File

@ -191,7 +191,7 @@ NEW_LINE (\r|\n|\r\n)
<PHP>use lval.Token(l.createToken(l.Token())); return T_USE
<PHP>var lval.Token(l.createToken(l.Token())); return T_VAR
<PHP>while lval.Token(l.createToken(l.Token())); return T_WHILE
<PHP>yield[ \t\n\r]+from[^a-zA-Z0-9_\x80-\xff] lval.Token(l.createToken(l.Token())); return T_YIELD_FROM
<PHP>yield[ \t\n\r]+from lval.Token(l.createToken(l.Token())); return T_YIELD_FROM
<PHP>yield lval.Token(l.createToken(l.Token())); return T_YIELD
<PHP>include lval.Token(l.createToken(l.Token())); return T_INCLUDE
<PHP>include_once lval.Token(l.createToken(l.Token())); return T_INCLUDE_ONCE
@ -266,6 +266,7 @@ NEW_LINE (\r|\n|\r\n)
}
case '\n':
c = l.Next()
case '?':
c = l.Next()
@ -322,7 +323,7 @@ NEW_LINE (\r|\n|\r\n)
<PHP>{VAR_NAME} lval.Token(l.createToken(l.Token())); return T_STRING
<PHP>-> l.begin(PROPERTY);lval.Token(l.createToken(l.Token())); return T_OBJECT_OPERATOR;
<PROPERTY>[ \t\n\r]+
<PROPERTY>[ \t\n\r]+ l.addWhiteSpace(l.Token())
<PROPERTY>-> lval.Token(l.createToken(l.Token())); return T_OBJECT_OPERATOR;
<PROPERTY>{VAR_NAME} l.begin(PHP);lval.Token(l.createToken(l.Token())); return T_STRING;
<PROPERTY>. l.ungetChars(1);l.begin(PHP)
@ -650,6 +651,13 @@ NEW_LINE (\r|\n|\r\n)
<STRING_VAR_NAME>. l.ungetChars(1);l.popState();l.pushState(PHP)
%%
if c, ok := l.Abort(); ok { return int(c) }
if _, ok := l.Abort(); ok {
// always return same $end token
if l.lastToken == nil {
l.lastToken = l.createToken(l.Token())
}
lval.Token(l.lastToken);
return -1
}
goto yyAction
}

View File

@ -904,7 +904,6 @@ func TestCommentNewLine(t *testing.T) {
expected := []meta.Meta{
meta.NewWhiteSpace(" ", position.NewPosition(1, 1, 6, 6)),
meta.NewComment("//test\n", position.NewPosition(1, 1, 7, 13)),
meta.NewWhiteSpace("\n", position.NewPosition(1, 1, 13, 13)),
}
lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php")
@ -913,7 +912,7 @@ func TestCommentNewLine(t *testing.T) {
lexer.Lex(lv)
actual := lexer.Meta
actual := lv.Tkn.Meta
assertEqual(t, expected, actual)
}
@ -932,7 +931,7 @@ func TestCommentNewLine1(t *testing.T) {
lexer.Lex(lv)
actual := lexer.Meta
actual := lv.Tkn.Meta
assertEqual(t, expected, actual)
}
@ -943,7 +942,6 @@ func TestCommentNewLine2(t *testing.T) {
expected := []meta.Meta{
meta.NewWhiteSpace(" ", position.NewPosition(1, 1, 6, 6)),
meta.NewComment("#test\r\n", position.NewPosition(1, 1, 7, 13)),
meta.NewWhiteSpace("\n", position.NewPosition(1, 1, 13, 13)),
}
lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php")
@ -952,7 +950,7 @@ func TestCommentNewLine2(t *testing.T) {
lexer.Lex(lv)
actual := lexer.Meta
actual := lv.Tkn.Meta
assertEqual(t, expected, actual)
}
@ -972,7 +970,7 @@ func TestCommentWithPhpEndTag(t *testing.T) {
lexer.Lex(lv)
actual := lexer.Meta
actual := lv.Tkn.Meta
assertEqual(t, expected, actual)
}
@ -992,7 +990,7 @@ func TestInlineComment(t *testing.T) {
lexer.Lex(lv)
actual := lexer.Meta
actual := lv.Tkn.Meta
assertEqual(t, expected, actual)
}
@ -1032,7 +1030,88 @@ func TestEmptyInlineComment2(t *testing.T) {
lexer.Lex(lv)
actual := lexer.Meta
actual := lv.Tkn.Meta
assertEqual(t, expected, actual)
}
func TestMethodCallTokens(t *testing.T) {
src := `<?php
$a -> bar ( '' ) ;`
lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php")
lexer.WithMeta = true
lv := &lval{}
expected := []meta.Meta{
meta.NewWhiteSpace("\n\t", position.NewPosition(1, 2, 6, 7)),
}
lexer.Lex(lv)
actual := lv.Tkn.Meta
assertEqual(t, expected, actual)
expected = []meta.Meta{
meta.NewWhiteSpace(" ", position.NewPosition(2, 2, 10, 10)),
}
lexer.Lex(lv)
actual = lv.Tkn.Meta
assertEqual(t, expected, actual)
expected = []meta.Meta{
meta.NewWhiteSpace(" ", position.NewPosition(2, 2, 13, 13)),
}
lexer.Lex(lv)
actual = lv.Tkn.Meta
assertEqual(t, expected, actual)
expected = []meta.Meta{
meta.NewWhiteSpace(" ", position.NewPosition(2, 2, 17, 17)),
}
lexer.Lex(lv)
actual = lv.Tkn.Meta
assertEqual(t, expected, actual)
expected = []meta.Meta{
meta.NewWhiteSpace(" ", position.NewPosition(2, 2, 19, 19)),
}
lexer.Lex(lv)
actual = lv.Tkn.Meta
assertEqual(t, expected, actual)
expected = []meta.Meta{
meta.NewWhiteSpace(" ", position.NewPosition(2, 2, 22, 22)),
}
lexer.Lex(lv)
actual = lv.Tkn.Meta
assertEqual(t, expected, actual)
expected = []meta.Meta{
meta.NewWhiteSpace(" ", position.NewPosition(2, 2, 24, 24)),
}
lexer.Lex(lv)
actual = lv.Tkn.Meta
assertEqual(t, expected, actual)
}
func TestYieldFromTokens(t *testing.T) {
src := `<?php
yield from $a`
lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php")
lexer.WithMeta = true
lv := &lval{}
expected := []meta.Meta{
meta.NewWhiteSpace("\n\t", position.NewPosition(1, 2, 6, 7)),
}
lexer.Lex(lv)
actual := lv.Tkn.Meta
assertEqual(t, expected, actual)
expected = []meta.Meta{
meta.NewWhiteSpace(" ", position.NewPosition(2, 2, 18, 18)),
}
lexer.Lex(lv)
actual = lv.Tkn.Meta
assertEqual(t, expected, actual)
}

View File

@ -7,7 +7,6 @@ import (
"reflect"
"strings"
"github.com/z7zmey/php-parser/meta"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
@ -40,7 +39,7 @@ func (d *Dumper) EnterNode(w walker.Walkable) bool {
if mm := n.GetMeta(); len(mm) > 0 {
fmt.Fprintf(d.Writer, "%v\"Meta\":\n", d.Indent+" ")
for _, m := range mm {
fmt.Fprintf(d.Writer, "%v%q before %q\n", d.Indent+" ", m, meta.TokenNames[m.GetTokenName()])
fmt.Fprintf(d.Writer, "%v%q before %q\n", d.Indent+" ", m, m.GetTokenName().String())
}
}

View File

@ -68,7 +68,7 @@ func ExampleDumper() {
// | [*node.Identifier]
// | "Position": Pos{Line: 4-4 Pos: 35-37}
// | "Meta":
// | " " before "StringToken"
// | " " before "IdentifierToken"
// | "Value": "Bar"
// | "Stmts":
// | [*stmt.ClassMethod]
@ -87,15 +87,15 @@ func ExampleDumper() {
// | [*node.Identifier]
// | "Position": Pos{Line: 5-5 Pos: 45-50}
// | "Meta":
// | "\n\t\t\t\t" before "PublicToken"
// | "\n\t\t\t\t" before "IdentifierToken"
// | "Value": "public"
// | "Params":
// | [*node.Parameter]
// | "Position": Pos{Line: 5-5 Pos: 74-89}
// | "Meta":
// | " " before "EqualToken"
// | "Variadic": false
// | "ByRef": false
// | "Variadic": false
// | "VariableType":
// | [*name.Name]
// | "Position": Pos{Line: 5-5 Pos: 74-77}
@ -141,7 +141,7 @@ func ExampleDumper() {
// | "Meta":
// | "\n\t\t\t\t\t" before "VariableToken"
// | "// some comment\n" before "VariableToken"
// | "\n\t\t\t\t\t" before "VariableToken"
// | "\t\t\t\t\t" before "VariableToken"
// | "VarName":
// | [*node.Identifier]
// | "Position": Pos{Line: 8-8 Pos: 124-127}

View File

@ -35,417 +35,417 @@ func ExampleGoDumper() {
nodes.Walk(dumper)
// Unordered output:
//&node.Root{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 11,
// StartPos: 10,
// EndPos: 142,
// },
// Stmts: []node.Node{
// &stmt.Namespace{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 11,
// StartPos: 10,
// EndPos: 142,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 1,
// EndLine: 3,
// StartPos: 6,
// EndPos: 9,
// },
// Value: "\n\n\t\t",
// TokenName: 67,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 23,
// EndPos: 23,
// },
// Value: " ",
// TokenName: 133,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 10,
// EndLine: 11,
// StartPos: 139,
// EndPos: 141,
// },
// Value: "\n\t\t",
// TokenName: 134,
// },
// },
// NamespaceName: &name.Name{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 20,
// EndPos: 22,
// },
// Parts: []node.Node{
// &name.NamePart{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 20,
// EndPos: 22,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 19,
// EndPos: 19,
// },
// Value: " ",
// TokenName: 7,
// },
// },
// Value: "Foo",
// },
// },
// },
// Stmts: []node.Node{
// &stmt.Class{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 10,
// StartPos: 29,
// EndPos: 138,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 4,
// StartPos: 25,
// EndPos: 28,
// },
// Value: "\n\t\t\t",
// TokenName: 48,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 4,
// StartPos: 38,
// EndPos: 38,
// },
// Value: " ",
// TokenName: 133,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 9,
// EndLine: 10,
// StartPos: 134,
// EndPos: 137,
// },
// Value: "\n\t\t\t",
// TokenName: 134,
// },
// },
// PhpDocComment: "",
// ClassName: &node.Identifier{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 4,
// StartPos: 35,
// EndPos: 37,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 4,
// StartPos: 34,
// EndPos: 34,
// },
// Value: " ",
// TokenName: 7,
// },
// },
// Value: "Bar",
// },
// Stmts: []node.Node{
// &stmt.ClassMethod{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 9,
// StartPos: 45,
// EndPos: 133,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 51,
// EndPos: 51,
// },
// Value: " ",
// TokenName: 34,
// },
// },
// ReturnsRef: false,
// PhpDocComment: "",
// MethodName: &node.Identifier{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 61,
// EndPos: 72,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 60,
// EndPos: 60,
// },
// Value: " ",
// TokenName: 129,
// },
// },
// Value: "FunctionName",
// },
// Modifiers: []node.Node{
// &node.Identifier{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 45,
// EndPos: 50,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 5,
// StartPos: 40,
// EndPos: 44,
// },
// Value: "\n\t\t\t\t",
// TokenName: 91,
// },
// },
// Value: "public",
// },
// },
// Params: []node.Node{
// &node.Parameter{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 74,
// EndPos: 89,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 83,
// EndPos: 83,
// },
// Value: " ",
// TokenName: 151,
// },
// },
// Variadic: false,
// ByRef: false,
// VariableType: &name.Name{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 74,
// EndPos: 77,
// },
// Parts: []node.Node{
// &name.NamePart{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 74,
// EndPos: 77,
// },
// Value: "Type",
// },
// },
// },
// Variable: &expr.Variable{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 79,
// EndPos: 82,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 78,
// EndPos: 78,
// },
// Value: " ",
// TokenName: 9,
// },
// },
// VarName: &node.Identifier{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 79,
// EndPos: 82,
// },
// Value: "var",
// },
// },
// DefaultValue: &expr.ConstFetch{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 86,
// EndPos: 89,
// },
// Constant: &name.Name{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 86,
// EndPos: 89,
// },
// Parts: []node.Node{
// &name.NamePart{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 86,
// EndPos: 89,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 85,
// EndPos: 85,
// },
// Value: " ",
// TokenName: 7,
// },
// },
// Value: "null",
// },
// },
// },
// },
// },
// },
// Stmt: &stmt.StmtList{
// Position: &position.Position{
// StartLine: 6,
// EndLine: 9,
// StartPos: 96,
// EndPos: 133,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 6,
// StartPos: 91,
// EndPos: 95,
// },
// Value: "\n\t\t\t\t",
// TokenName: 133,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 9,
// StartPos: 128,
// EndPos: 132,
// },
// Value: "\n\t\t\t\t",
// TokenName: 134,
// },
// },
// Stmts: []node.Node{
// &stmt.Expression{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 123,
// EndPos: 127,
// },
// Expr: &expr.Variable{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 123,
// EndPos: 126,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 6,
// EndLine: 7,
// StartPos: 97,
// EndPos: 102,
// },
// Value: "\n\t\t\t\t\t",
// TokenName: 9,
// },
// &meta.Comment{
// Position: &position.Position{
// StartLine: 7,
// EndLine: 7,
// StartPos: 103,
// EndPos: 117,
// },
// Value: "//some comment\n",
// TokenName: 9,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 7,
// EndLine: 8,
// StartPos: 117,
// EndPos: 122,
// },
// Value: "\n\t\t\t\t\t",
// TokenName: 9,
// },
// },
// VarName: &node.Identifier{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 123,
// EndPos: 126,
// },
// Value: "var",
// },
// },
// },
// },
// },
// },
// },
// },
// },
// },
// },
//}
// &node.Root{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 11,
// StartPos: 10,
// EndPos: 142,
// },
// Stmts: []node.Node{
// &stmt.Namespace{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 11,
// StartPos: 10,
// EndPos: 142,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 1,
// EndLine: 3,
// StartPos: 6,
// EndPos: 9,
// },
// Value: "\n\n\t\t",
// TokenName: 65,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 23,
// EndPos: 23,
// },
// Value: " ",
// TokenName: 129,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 10,
// EndLine: 11,
// StartPos: 139,
// EndPos: 141,
// },
// Value: "\n\t\t",
// TokenName: 130,
// },
// },
// NamespaceName: &name.Name{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 20,
// EndPos: 22,
// },
// Parts: []node.Node{
// &name.NamePart{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 20,
// EndPos: 22,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 19,
// EndPos: 19,
// },
// Value: " ",
// TokenName: 10,
// },
// },
// Value: "Foo",
// },
// },
// },
// Stmts: []node.Node{
// &stmt.Class{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 10,
// StartPos: 29,
// EndPos: 138,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 4,
// StartPos: 25,
// EndPos: 28,
// },
// Value: "\n\t\t\t",
// TokenName: 52,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 4,
// StartPos: 38,
// EndPos: 38,
// },
// Value: " ",
// TokenName: 129,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 9,
// EndLine: 10,
// StartPos: 134,
// EndPos: 137,
// },
// Value: "\n\t\t\t",
// TokenName: 130,
// },
// },
// PhpDocComment: "",
// ClassName: &node.Identifier{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 4,
// StartPos: 35,
// EndPos: 37,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 4,
// StartPos: 34,
// EndPos: 34,
// },
// Value: " ",
// TokenName: 125,
// },
// },
// Value: "Bar",
// },
// Stmts: []node.Node{
// &stmt.ClassMethod{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 9,
// StartPos: 45,
// EndPos: 133,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 51,
// EndPos: 51,
// },
// Value: " ",
// TokenName: 38,
// },
// },
// ReturnsRef: false,
// PhpDocComment: "",
// MethodName: &node.Identifier{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 61,
// EndPos: 72,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 60,
// EndPos: 60,
// },
// Value: " ",
// TokenName: 125,
// },
// },
// Value: "FunctionName",
// },
// Modifiers: []node.Node{
// &node.Identifier{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 45,
// EndPos: 50,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 5,
// StartPos: 40,
// EndPos: 44,
// },
// Value: "\n\t\t\t\t",
// TokenName: 125,
// },
// },
// Value: "public",
// },
// },
// Params: []node.Node{
// &node.Parameter{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 74,
// EndPos: 89,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 83,
// EndPos: 83,
// },
// Value: " ",
// TokenName: 147,
// },
// },
// ByRef: false,
// Variadic: false,
// VariableType: &name.Name{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 74,
// EndPos: 77,
// },
// Parts: []node.Node{
// &name.NamePart{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 74,
// EndPos: 77,
// },
// Value: "Type",
// },
// },
// },
// Variable: &expr.Variable{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 79,
// EndPos: 82,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 78,
// EndPos: 78,
// },
// Value: " ",
// TokenName: 12,
// },
// },
// VarName: &node.Identifier{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 79,
// EndPos: 82,
// },
// Value: "var",
// },
// },
// DefaultValue: &expr.ConstFetch{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 86,
// EndPos: 89,
// },
// Constant: &name.Name{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 86,
// EndPos: 89,
// },
// Parts: []node.Node{
// &name.NamePart{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 86,
// EndPos: 89,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 85,
// EndPos: 85,
// },
// Value: " ",
// TokenName: 10,
// },
// },
// Value: "null",
// },
// },
// },
// },
// },
// },
// Stmt: &stmt.StmtList{
// Position: &position.Position{
// StartLine: 6,
// EndLine: 9,
// StartPos: 96,
// EndPos: 133,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 6,
// StartPos: 91,
// EndPos: 95,
// },
// Value: "\n\t\t\t\t",
// TokenName: 129,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 9,
// StartPos: 128,
// EndPos: 132,
// },
// Value: "\n\t\t\t\t",
// TokenName: 130,
// },
// },
// Stmts: []node.Node{
// &stmt.Expression{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 123,
// EndPos: 127,
// },
// Expr: &expr.Variable{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 123,
// EndPos: 126,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 6,
// EndLine: 7,
// StartPos: 97,
// EndPos: 102,
// },
// Value: "\n\t\t\t\t\t",
// TokenName: 12,
// },
// &meta.Comment{
// Position: &position.Position{
// StartLine: 7,
// EndLine: 7,
// StartPos: 103,
// EndPos: 117,
// },
// Value: "//some comment\n",
// TokenName: 12,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 118,
// EndPos: 122,
// },
// Value: "\t\t\t\t\t",
// TokenName: 12,
// },
// },
// VarName: &node.Identifier{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 123,
// EndPos: 126,
// },
// Value: "var",
// },
// },
// },
// },
// },
// },
// },
// },
// },
// },
// },
// }
}

View File

@ -53,9 +53,9 @@ func (d *JsonDumper) EnterNode(w walker.Walkable) bool {
switch m.(type) {
case *meta.Comment:
fmt.Fprintf(d.Writer, "{%q:%q,%q:%q,%q:%q}", "type", "*meta.Comment", "value", m.String(), "tokenName", meta.TokenNames[m.GetTokenName()])
fmt.Fprintf(d.Writer, "{%q:%q,%q:%q,%q:%q}", "type", "*meta.Comment", "value", m.String(), "tokenName", m.GetTokenName().String())
case *meta.WhiteSpace:
fmt.Fprintf(d.Writer, "{%q:%q,%q:%q,%q:%q}", "type", "*meta.WhiteSpace", "value", m.String(), "tokenName", meta.TokenNames[m.GetTokenName()])
fmt.Fprintf(d.Writer, "{%q:%q,%q:%q,%q:%q}", "type", "*meta.WhiteSpace", "value", m.String(), "tokenName", m.GetTokenName().String())
}
}

View File

@ -37,5 +37,5 @@ func ExampleJsonDumper() {
nodes.Walk(dumper)
// Output:
// {"type":"*node.Root","position":{"startPos":10,"endPos":166,"startLine":3,"endLine":12},"Stmts":[{"type":"*stmt.Namespace","position":{"startPos":10,"endPos":166,"startLine":3,"endLine":12},"meta":[{"type":"*meta.WhiteSpace","value":"\n\n\t\t","tokenName":"NamespaceToken"},{"type":"*meta.WhiteSpace","value":" ","tokenName":"OpenCurlyBracesToken"},{"type":"*meta.WhiteSpace","value":"\n\t\t","tokenName":"CloseCurlyBracesToken"}],"NamespaceName":{"type":"*name.Name","position":{"startPos":20,"endPos":22,"startLine":3,"endLine":3},"Parts":[{"type":"*name.NamePart","position":{"startPos":20,"endPos":22,"startLine":3,"endLine":3},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"StringToken"}],"Value":"Foo"}]},"Stmts":[{"type":"*stmt.Class","position":{"startPos":29,"endPos":162,"startLine":4,"endLine":11},"namespacedName":"Foo\\Bar","meta":[{"type":"*meta.WhiteSpace","value":"\n\t\t\t","tokenName":"ClassToken"},{"type":"*meta.WhiteSpace","value":" ","tokenName":"OpenCurlyBracesToken"},{"type":"*meta.WhiteSpace","value":"\n\t\t\t","tokenName":"CloseCurlyBracesToken"}],"PhpDocComment":"","ClassName":{"type":"*node.Identifier","position":{"startPos":35,"endPos":37,"startLine":4,"endLine":4},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"StringToken"}],"Value":"Bar"},"Stmts":[{"type":"*stmt.ClassMethod","position":{"startPos":45,"endPos":157,"startLine":5,"endLine":10},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"FunctionToken"}],"PhpDocComment":"","ReturnsRef":false,"MethodName":{"type":"*node.Identifier","position":{"startPos":61,"endPos":72,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"IdentifierToken"}],"Value":"FunctionName"},"Modifiers":[{"type":"*node.Identifier","position":{"startPos":45,"endPos":50,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t","tokenName":"PublicToken"}],"Value":"public"}],"Params":[{"type":"*node.Parameter","position":{"startPos":74,"endPos":89,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"EqualToken"}],"ByRef":false,"Variadic":false,"VariableType":{"type":"*name.Name","position":{"startPos":74,"endPos":77,"startLine":5,"endLine":5},"namespacedName":"Foo\\Type","Parts":[{"type":"*name.NamePart","position":{"startPos":74,"endPos":77,"startLine":5,"endLine":5},"Value":"Type"}]},"Variable":{"type":"*expr.Variable","position":{"startPos":79,"endPos":82,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"VariableToken"}],"VarName":{"type":"*node.Identifier","position":{"startPos":79,"endPos":82,"startLine":5,"endLine":5},"Value":"var"}},"DefaultValue":{"type":"*expr.ConstFetch","position":{"startPos":86,"endPos":89,"startLine":5,"endLine":5},"Constant":{"type":"*name.Name","position":{"startPos":86,"endPos":89,"startLine":5,"endLine":5},"namespacedName":"null","Parts":[{"type":"*name.NamePart","position":{"startPos":86,"endPos":89,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"StringToken"}],"Value":"null"}]}}}],"Stmt":{"type":"*stmt.StmtList","position":{"startPos":96,"endPos":157,"startLine":6,"endLine":10},"meta":[{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t","tokenName":"OpenCurlyBracesToken"},{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t","tokenName":"CloseCurlyBracesToken"}],"Stmts":[{"type":"*stmt.Expression","position":{"startPos":147,"endPos":151,"startLine":9,"endLine":9},"Expr":{"type":"*expr.Variable","position":{"startPos":147,"endPos":150,"startLine":9,"endLine":9},"meta":[{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t\t","tokenName":"VariableToken"},{"type":"*meta.Comment","value":"// some comment\n","tokenName":"VariableToken"},{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t\t","tokenName":"VariableToken"},{"type":"*meta.Comment","value":"// second comment\n","tokenName":"VariableToken"},{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t\t","tokenName":"VariableToken"}],"VarName":{"type":"*node.Identifier","position":{"startPos":147,"endPos":150,"startLine":9,"endLine":9},"Value":"var"}}}]}}]}]}]}
// {"type":"*node.Root","position":{"startPos":10,"endPos":166,"startLine":3,"endLine":12},"Stmts":[{"type":"*stmt.Namespace","position":{"startPos":10,"endPos":166,"startLine":3,"endLine":12},"meta":[{"type":"*meta.WhiteSpace","value":"\n\n\t\t","tokenName":"NamespaceToken"},{"type":"*meta.WhiteSpace","value":" ","tokenName":"OpenCurlyBracesToken"},{"type":"*meta.WhiteSpace","value":"\n\t\t","tokenName":"CloseCurlyBracesToken"}],"NamespaceName":{"type":"*name.Name","position":{"startPos":20,"endPos":22,"startLine":3,"endLine":3},"Parts":[{"type":"*name.NamePart","position":{"startPos":20,"endPos":22,"startLine":3,"endLine":3},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"StringToken"}],"Value":"Foo"}]},"Stmts":[{"type":"*stmt.Class","position":{"startPos":29,"endPos":162,"startLine":4,"endLine":11},"namespacedName":"Foo\\Bar","meta":[{"type":"*meta.WhiteSpace","value":"\n\t\t\t","tokenName":"ClassToken"},{"type":"*meta.WhiteSpace","value":" ","tokenName":"OpenCurlyBracesToken"},{"type":"*meta.WhiteSpace","value":"\n\t\t\t","tokenName":"CloseCurlyBracesToken"}],"PhpDocComment":"","ClassName":{"type":"*node.Identifier","position":{"startPos":35,"endPos":37,"startLine":4,"endLine":4},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"IdentifierToken"}],"Value":"Bar"},"Stmts":[{"type":"*stmt.ClassMethod","position":{"startPos":45,"endPos":157,"startLine":5,"endLine":10},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"FunctionToken"}],"PhpDocComment":"","ReturnsRef":false,"MethodName":{"type":"*node.Identifier","position":{"startPos":61,"endPos":72,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"IdentifierToken"}],"Value":"FunctionName"},"Modifiers":[{"type":"*node.Identifier","position":{"startPos":45,"endPos":50,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t","tokenName":"IdentifierToken"}],"Value":"public"}],"Params":[{"type":"*node.Parameter","position":{"startPos":74,"endPos":89,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"EqualToken"}],"ByRef":false,"Variadic":false,"VariableType":{"type":"*name.Name","position":{"startPos":74,"endPos":77,"startLine":5,"endLine":5},"namespacedName":"Foo\\Type","Parts":[{"type":"*name.NamePart","position":{"startPos":74,"endPos":77,"startLine":5,"endLine":5},"Value":"Type"}]},"Variable":{"type":"*expr.Variable","position":{"startPos":79,"endPos":82,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"VariableToken"}],"VarName":{"type":"*node.Identifier","position":{"startPos":79,"endPos":82,"startLine":5,"endLine":5},"Value":"var"}},"DefaultValue":{"type":"*expr.ConstFetch","position":{"startPos":86,"endPos":89,"startLine":5,"endLine":5},"Constant":{"type":"*name.Name","position":{"startPos":86,"endPos":89,"startLine":5,"endLine":5},"namespacedName":"null","Parts":[{"type":"*name.NamePart","position":{"startPos":86,"endPos":89,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"StringToken"}],"Value":"null"}]}}}],"Stmt":{"type":"*stmt.StmtList","position":{"startPos":96,"endPos":157,"startLine":6,"endLine":10},"meta":[{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t","tokenName":"OpenCurlyBracesToken"},{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t","tokenName":"CloseCurlyBracesToken"}],"Stmts":[{"type":"*stmt.Expression","position":{"startPos":147,"endPos":151,"startLine":9,"endLine":9},"Expr":{"type":"*expr.Variable","position":{"startPos":147,"endPos":150,"startLine":9,"endLine":9},"meta":[{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t\t","tokenName":"VariableToken"},{"type":"*meta.Comment","value":"// some comment\n","tokenName":"VariableToken"},{"type":"*meta.WhiteSpace","value":"\t\t\t\t\t","tokenName":"VariableToken"},{"type":"*meta.Comment","value":"// second comment\n","tokenName":"VariableToken"},{"type":"*meta.WhiteSpace","value":"\t\t\t\t\t","tokenName":"VariableToken"}],"VarName":{"type":"*node.Identifier","position":{"startPos":147,"endPos":150,"startLine":9,"endLine":9},"Value":"var"}}}]}}]}]}]}
}

View File

@ -156,8 +156,8 @@ func (nsr *NamespaceResolver) EnterNode(w walker.Walkable) bool {
nsr.ResolveName(t, "")
}
if n.TraitAdaptationList != nil {
for _, a := range n.TraitAdaptationList.Adaptations {
if adaptationList, ok := n.TraitAdaptationList.(*stmt.TraitAdaptationList); ok {
for _, a := range adaptationList.Adaptations {
switch aa := a.(type) {
case *stmt.TraitUsePrecedence:
refTrait := aa.Ref.(*stmt.TraitMethodRef).Trait

View File

@ -105,7 +105,7 @@ func (d *PrettyJsonDumper) EnterNode(w walker.Walkable) bool {
d.printIndent(d.Writer)
fmt.Fprintf(d.Writer, "%q: %q,\n", "value", m.String())
d.printIndent(d.Writer)
fmt.Fprintf(d.Writer, "%q: %q\n", "tokenName", meta.TokenNames[m.GetTokenName()])
fmt.Fprintf(d.Writer, "%q: %q\n", "tokenName", m.GetTokenName().String())
d.depth--
d.printIndent(d.Writer)
fmt.Fprint(d.Writer, "}")

View File

@ -45,6 +45,13 @@ func ExamplePrettyJsonDumper() {
// "startLine": 3,
// "endLine": 14
// },
// "meta": [
// {
// "type": "*meta.WhiteSpace",
// "value": "\n\t\t",
// "tokenName": "NodeEnd"
// }
// ],
// "Stmts": [
// {
// "type": "*stmt.Namespace",
@ -139,7 +146,7 @@ func ExamplePrettyJsonDumper() {
// {
// "type": "*meta.WhiteSpace",
// "value": " ",
// "tokenName": "StringToken"
// "tokenName": "IdentifierToken"
// }
// ],
// "Value": "Bar"
@ -192,7 +199,7 @@ func ExamplePrettyJsonDumper() {
// {
// "type": "*meta.WhiteSpace",
// "value": "\n\t\t\t\t",
// "tokenName": "PublicToken"
// "tokenName": "IdentifierToken"
// }
// ],
// "Value": "public"
@ -354,7 +361,7 @@ func ExamplePrettyJsonDumper() {
// },
// {
// "type": "*meta.WhiteSpace",
// "value": "\n\t\t\t\t\t",
// "value": "\t\t\t\t\t",
// "tokenName": "VariableToken"
// },
// {
@ -364,7 +371,7 @@ func ExamplePrettyJsonDumper() {
// },
// {
// "type": "*meta.WhiteSpace",
// "value": "\n\t\t\t\t\t",
// "value": "\t\t\t\t\t",
// "tokenName": "VariableToken"
// }
// ],
@ -420,7 +427,7 @@ func ExamplePrettyJsonDumper() {
// {
// "type": "*meta.WhiteSpace",
// "value": " ",
// "tokenName": "StringToken"
// "tokenName": "IdentifierToken"
// }
// ],
// "Value": "foo"