From 15a1a81924a473f478412a4aee04227c82851b6c Mon Sep 17 00:00:00 2001 From: z7zmey Date: Mon, 2 Jul 2018 20:48:55 +0300 Subject: [PATCH] #13: the printer prints nodes with meta(comments and whitespaces) saved by the parser --- Makefile | 1 + meta/tokenName.go | 163 + meta/tokenName_string.go | 16 + meta/tokenName_test.go | 29 + meta/tokenNames.go | 328 -- node/stmt/n_trait_use.go | 4 +- node/stmt/t_trait_use_test.go | 16 + php5/php5.go | 1203 ++++---- php5/php5.y | 167 +- php5/php5_test.go | 30 +- php7/php7.go | 1126 ++++--- php7/php7.y | 144 +- php7/php7_test.go | 36 +- printer/pretty_printer.go | 2182 ++++++++++++++ printer/pretty_printer_test.go | 4097 +++++++++++++++++++++++++ printer/printer.go | 1573 +++++++--- printer/printer_parsed_test.go | 955 ++++++ printer/printer_test.go | 4528 +++++++++++++++++++--------- scanner/lexer.go | 1 + scanner/scanner.go | 1001 +++--- scanner/scanner.l | 14 +- scanner/scanner_test.go | 95 +- visitor/dumper.go | 3 +- visitor/dumper_test.go | 8 +- visitor/go_dumper_test.go | 826 ++--- visitor/json_dumper.go | 4 +- visitor/json_dumper_test.go | 2 +- visitor/namespace_resolver.go | 4 +- visitor/pretty_json_dumper.go | 2 +- visitor/pretty_json_dumper_test.go | 17 +- 30 files changed, 14110 insertions(+), 4465 deletions(-) create mode 100644 meta/tokenName.go create mode 100644 meta/tokenName_string.go create mode 100644 meta/tokenName_test.go delete mode 100644 meta/tokenNames.go create mode 100644 printer/pretty_printer.go create mode 100644 printer/pretty_printer_test.go create mode 100644 printer/printer_parsed_test.go diff --git a/Makefile b/Makefile index 568b883..460cda5 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ fmt: find . -type f -iregex '.*\.go' -exec gofmt -l -s -w '{}' + build: + go generate ./... go build run: diff --git a/meta/tokenName.go b/meta/tokenName.go new file mode 100644 index 0000000..f3ad33d --- /dev/null +++ b/meta/tokenName.go @@ -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 // '.' +) diff --git a/meta/tokenName_string.go b/meta/tokenName_string.go new file mode 100644 index 0000000..a906696 --- /dev/null +++ b/meta/tokenName_string.go @@ -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]] +} diff --git a/meta/tokenName_test.go b/meta/tokenName_test.go new file mode 100644 index 0000000..ab3c706 --- /dev/null +++ b/meta/tokenName_test.go @@ -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) + } +} diff --git a/meta/tokenNames.go b/meta/tokenNames.go deleted file mode 100644 index 87ab28f..0000000 --- a/meta/tokenNames.go +++ /dev/null @@ -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", -} diff --git a/node/stmt/n_trait_use.go b/node/stmt/n_trait_use.go index 18316df..b8c454f 100644 --- a/node/stmt/n_trait_use.go +++ b/node/stmt/n_trait_use.go @@ -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, diff --git a/node/stmt/t_trait_use_test.go b/node/stmt/t_trait_use_test.go index 6fc5cf0..c3ea79b 100644 --- a/node/stmt/t_trait_use_test.go +++ b/node/stmt/t_trait_use_test.go @@ -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, + }, + }, }, }, }, diff --git a/php5/php5.go b/php5/php5.go index 7b87967..5267eee 100644 --- a/php5/php5.go +++ b/php5/php5.go @@ -346,7 +346,7 @@ const yyEofCode = 1 const yyErrCode = 2 const yyInitialStackSize = 16 -//line php5/php5.y:6789 +//line php5/php5.y:6798 type simpleIndirectReference struct { all []*expr.Variable last *expr.Variable @@ -2331,10 +2331,14 @@ yydefault: yylex.(*Parser).rootNode.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition(yyDollar[1].list)) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) + + if yylex.(*Parser).currentToken.Value == "\xff" { + addMeta(yylex.(*Parser).rootNode, yylex.(*Parser).currentToken.Meta, meta.NodeEnd) + } } case 2: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:291 + //line php5/php5.y:295 { if yyDollar[2].node != nil { yyVAL.list = append(yyDollar[1].list, yyDollar[2].node) @@ -2344,7 +2348,7 @@ yydefault: } case 3: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:299 + //line php5/php5.y:303 { yyVAL.list = []node.Node{} @@ -2352,7 +2356,7 @@ yydefault: } case 4: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:308 + //line php5/php5.y:312 { namePart := name.NewNamePart(yyDollar[1].token.Value) yyVAL.list = []node.Node{namePart} @@ -2367,7 +2371,7 @@ yydefault: } case 5: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:321 + //line php5/php5.y:325 { namePart := name.NewNamePart(yyDollar[3].token.Value) yyVAL.list = append(yyDollar[1].list, namePart) @@ -2383,7 +2387,7 @@ yydefault: } case 6: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:338 + //line php5/php5.y:342 { // error yyVAL.node = nil @@ -2392,7 +2396,7 @@ yydefault: } case 7: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:345 + //line php5/php5.y:349 { yyVAL.node = yyDollar[1].node @@ -2400,7 +2404,7 @@ yydefault: } case 8: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:351 + //line php5/php5.y:355 { yyVAL.node = yyDollar[1].node @@ -2408,7 +2412,7 @@ yydefault: } case 9: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:357 + //line php5/php5.y:361 { yyVAL.node = yyDollar[1].node @@ -2416,7 +2420,7 @@ yydefault: } case 10: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:363 + //line php5/php5.y:367 { yyVAL.node = stmt.NewHaltCompiler() @@ -2433,7 +2437,7 @@ yydefault: } case 11: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:378 + //line php5/php5.y:382 { name := name.NewName(yyDollar[2].list) yyVAL.node = stmt.NewNamespace(name, nil) @@ -2450,7 +2454,7 @@ yydefault: } case 12: yyDollar = yyS[yypt-5 : yypt+1] - //line php5/php5.y:393 + //line php5/php5.y:397 { name := name.NewName(yyDollar[2].list) yyVAL.node = stmt.NewNamespace(name, yyDollar[4].list) @@ -2468,7 +2472,7 @@ yydefault: } case 13: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:409 + //line php5/php5.y:413 { yyVAL.node = stmt.NewNamespace(nil, yyDollar[3].list) @@ -2484,7 +2488,7 @@ yydefault: } case 14: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:423 + //line php5/php5.y:427 { yyVAL.node = stmt.NewUseList(nil, yyDollar[2].list) @@ -2499,7 +2503,7 @@ yydefault: } case 15: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:436 + //line php5/php5.y:440 { useType := node.NewIdentifier(yyDollar[2].token.Value) yyVAL.node = stmt.NewUseList(useType, yyDollar[3].list) @@ -2510,14 +2514,14 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.UseToken) - addMeta(useType, yyDollar[2].token.Meta, meta.UseToken) + addMeta(useType, yyDollar[2].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[4].token.Meta, meta.SemiColonToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 16: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:452 + //line php5/php5.y:456 { useType := node.NewIdentifier(yyDollar[2].token.Value) yyVAL.node = stmt.NewUseList(useType, yyDollar[3].list) @@ -2528,14 +2532,14 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.UseToken) - addMeta(useType, yyDollar[2].token.Meta, meta.UseToken) + addMeta(useType, yyDollar[2].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[4].token.Meta, meta.SemiColonToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 17: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:468 + //line php5/php5.y:472 { yyVAL.node = yyDollar[1].node @@ -2549,18 +2553,18 @@ yydefault: } case 18: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:483 + //line php5/php5.y:487 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 19: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:492 + //line php5/php5.y:496 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -2568,7 +2572,7 @@ yydefault: } case 20: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:501 + //line php5/php5.y:505 { name := name.NewName(yyDollar[1].list) yyVAL.node = stmt.NewUse(nil, name, nil) @@ -2581,7 +2585,7 @@ yydefault: } case 21: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:512 + //line php5/php5.y:516 { name := name.NewName(yyDollar[1].list) alias := node.NewIdentifier(yyDollar[3].token.Value) @@ -2594,13 +2598,13 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.AsToken) - addMeta(alias, yyDollar[3].token.Meta, meta.StringToken) + addMeta(alias, yyDollar[3].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 22: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:529 + //line php5/php5.y:533 { name := name.NewName(yyDollar[2].list) yyVAL.node = stmt.NewUse(nil, name, nil) @@ -2616,7 +2620,7 @@ yydefault: } case 23: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:543 + //line php5/php5.y:547 { name := name.NewName(yyDollar[2].list) alias := node.NewIdentifier(yyDollar[4].token.Value) @@ -2630,24 +2634,24 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.NsSeparatorToken) addMeta(yyVAL.node, yyDollar[3].token.Meta, meta.AsToken) - addMeta(yyVAL.node, yyDollar[4].token.Meta, meta.StringToken) + addMeta(alias, yyDollar[4].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 24: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:564 + //line php5/php5.y:568 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 25: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:573 + //line php5/php5.y:577 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -2655,7 +2659,7 @@ yydefault: } case 26: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:582 + //line php5/php5.y:586 { name := name.NewName(yyDollar[1].list) yyVAL.node = stmt.NewUse(nil, name, nil) @@ -2668,7 +2672,7 @@ yydefault: } case 27: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:593 + //line php5/php5.y:597 { name := name.NewName(yyDollar[1].list) alias := node.NewIdentifier(yyDollar[3].token.Value) @@ -2681,13 +2685,13 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.AsToken) - addMeta(alias, yyDollar[3].token.Meta, meta.StringToken) + addMeta(alias, yyDollar[3].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 28: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:610 + //line php5/php5.y:614 { name := name.NewName(yyDollar[2].list) yyVAL.node = stmt.NewUse(nil, name, nil) @@ -2703,7 +2707,7 @@ yydefault: } case 29: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:624 + //line php5/php5.y:628 { name := name.NewName(yyDollar[2].list) alias := node.NewIdentifier(yyDollar[4].token.Value) @@ -2717,24 +2721,24 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.NsSeparatorToken) addMeta(yyVAL.node, yyDollar[3].token.Meta, meta.AsToken) - addMeta(yyVAL.node, yyDollar[4].token.Meta, meta.StringToken) + addMeta(alias, yyDollar[4].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 30: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:645 + //line php5/php5.y:649 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 31: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:654 + //line php5/php5.y:658 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -2742,7 +2746,7 @@ yydefault: } case 32: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:663 + //line php5/php5.y:667 { name := name.NewName(yyDollar[1].list) yyVAL.node = stmt.NewUse(nil, name, nil) @@ -2755,7 +2759,7 @@ yydefault: } case 33: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:674 + //line php5/php5.y:678 { name := name.NewName(yyDollar[1].list) alias := node.NewIdentifier(yyDollar[3].token.Value) @@ -2768,13 +2772,13 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.AsToken) - addMeta(alias, yyDollar[3].token.Meta, meta.StringToken) + addMeta(alias, yyDollar[3].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 34: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:691 + //line php5/php5.y:695 { name := name.NewName(yyDollar[2].list) yyVAL.node = stmt.NewUse(nil, name, nil) @@ -2790,7 +2794,7 @@ yydefault: } case 35: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:705 + //line php5/php5.y:709 { name := name.NewName(yyDollar[2].list) alias := node.NewIdentifier(yyDollar[4].token.Value) @@ -2804,13 +2808,13 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.NsSeparatorToken) addMeta(yyVAL.node, yyDollar[3].token.Meta, meta.AsToken) - addMeta(yyVAL.node, yyDollar[4].token.Meta, meta.StringToken) + addMeta(alias, yyDollar[4].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 36: yyDollar = yyS[yypt-5 : yypt+1] - //line php5/php5.y:726 + //line php5/php5.y:730 { name := node.NewIdentifier(yyDollar[3].token.Value) constant := stmt.NewConstant(name, yyDollar[5].node, "") @@ -2825,14 +2829,14 @@ yydefault: // save comments addMeta(lastNode(constList.Consts), yyDollar[2].token.Meta, meta.CommaToken) - addMeta(name, yyDollar[3].token.Meta, meta.StringToken) + addMeta(name, yyDollar[3].token.Meta, meta.IdentifierToken) addMeta(constant, yyDollar[4].token.Meta, meta.EqualToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 37: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:746 + //line php5/php5.y:750 { name := node.NewIdentifier(yyDollar[2].token.Value) constant := stmt.NewConstant(name, yyDollar[4].node, "") @@ -2846,14 +2850,14 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.ConstToken) - addMeta(name, yyDollar[2].token.Meta, meta.StringToken) + addMeta(name, yyDollar[2].token.Meta, meta.IdentifierToken) addMeta(constant, yyDollar[3].token.Meta, meta.EqualToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 38: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:768 + //line php5/php5.y:772 { if yyDollar[2].node != nil { yyVAL.list = append(yyDollar[1].list, yyDollar[2].node) @@ -2863,7 +2867,7 @@ yydefault: } case 39: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:776 + //line php5/php5.y:780 { yyVAL.list = []node.Node{} @@ -2871,7 +2875,7 @@ yydefault: } case 40: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:786 + //line php5/php5.y:790 { // error yyVAL.node = nil @@ -2880,7 +2884,7 @@ yydefault: } case 41: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:793 + //line php5/php5.y:797 { yyVAL.node = yyDollar[1].node @@ -2888,7 +2892,7 @@ yydefault: } case 42: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:799 + //line php5/php5.y:803 { yyVAL.node = yyDollar[1].node @@ -2896,7 +2900,7 @@ yydefault: } case 43: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:805 + //line php5/php5.y:809 { yyVAL.node = yyDollar[1].node @@ -2904,7 +2908,7 @@ yydefault: } case 44: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:811 + //line php5/php5.y:815 { yyVAL.node = stmt.NewHaltCompiler() @@ -2921,7 +2925,7 @@ yydefault: } case 45: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:830 + //line php5/php5.y:834 { yyVAL.node = yyDollar[1].node @@ -2929,7 +2933,7 @@ yydefault: } case 46: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:836 + //line php5/php5.y:840 { label := node.NewIdentifier(yyDollar[1].token.Value) yyVAL.node = stmt.NewLabel(label) @@ -2939,14 +2943,14 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition(yyDollar[1].token, yyDollar[2].token)) // save comments - addMeta(label, yyDollar[1].token.Meta, meta.StringToken) + addMeta(label, yyDollar[1].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.ColonToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 47: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:854 + //line php5/php5.y:858 { yyVAL.node = stmt.NewStmtList(yyDollar[2].list) @@ -2961,7 +2965,7 @@ yydefault: } case 48: yyDollar = yyS[yypt-5 : yypt+1] - //line php5/php5.y:867 + //line php5/php5.y:871 { yyVAL.node = stmt.NewIf(yyDollar[2].node, yyDollar[3].node, yyDollar[4].list, yyDollar[5].node) @@ -2981,7 +2985,7 @@ yydefault: } case 49: yyDollar = yyS[yypt-8 : yypt+1] - //line php5/php5.y:885 + //line php5/php5.y:889 { stmts := stmt.NewStmtList(yyDollar[4].list) yyVAL.node = stmt.NewAltIf(yyDollar[2].node, stmts, yyDollar[5].list, yyDollar[6].node) @@ -3000,7 +3004,7 @@ yydefault: } case 50: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:902 + //line php5/php5.y:906 { switch n := yyDollar[3].node.(type) { case *stmt.While: @@ -3021,7 +3025,7 @@ yydefault: } case 51: yyDollar = yyS[yypt-5 : yypt+1] - //line php5/php5.y:921 + //line php5/php5.y:925 { yyVAL.node = stmt.NewDo(yyDollar[2].node, yyDollar[4].node) @@ -3037,7 +3041,7 @@ yydefault: } case 52: yyDollar = yyS[yypt-9 : yypt+1] - //line php5/php5.y:935 + //line php5/php5.y:939 { switch n := yyDollar[9].node.(type) { case *stmt.For: @@ -3066,7 +3070,7 @@ yydefault: } case 53: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:962 + //line php5/php5.y:966 { switch n := yyDollar[3].node.(type) { case *stmt.Switch: @@ -3089,7 +3093,7 @@ yydefault: } case 54: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:983 + //line php5/php5.y:987 { yyVAL.node = stmt.NewBreak(nil) @@ -3104,7 +3108,7 @@ yydefault: } case 55: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:996 + //line php5/php5.y:1000 { yyVAL.node = stmt.NewBreak(yyDollar[2].node) @@ -3119,7 +3123,7 @@ yydefault: } case 56: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:1009 + //line php5/php5.y:1013 { yyVAL.node = stmt.NewContinue(nil) @@ -3134,7 +3138,7 @@ yydefault: } case 57: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:1022 + //line php5/php5.y:1026 { yyVAL.node = stmt.NewContinue(yyDollar[2].node) @@ -3149,7 +3153,7 @@ yydefault: } case 58: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:1035 + //line php5/php5.y:1039 { yyVAL.node = stmt.NewReturn(nil) @@ -3164,7 +3168,7 @@ yydefault: } case 59: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:1048 + //line php5/php5.y:1052 { yyVAL.node = stmt.NewReturn(yyDollar[2].node) @@ -3179,7 +3183,7 @@ yydefault: } case 60: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:1061 + //line php5/php5.y:1065 { yyVAL.node = stmt.NewReturn(yyDollar[2].node) @@ -3194,7 +3198,7 @@ yydefault: } case 61: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:1074 + //line php5/php5.y:1078 { yyVAL.node = stmt.NewExpression(yyDollar[1].node) @@ -3208,7 +3212,7 @@ yydefault: } case 62: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:1086 + //line php5/php5.y:1090 { yyVAL.node = stmt.NewGlobal(yyDollar[2].list) @@ -3223,7 +3227,7 @@ yydefault: } case 63: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:1099 + //line php5/php5.y:1103 { yyVAL.node = stmt.NewStatic(yyDollar[2].list) @@ -3238,7 +3242,7 @@ yydefault: } case 64: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:1112 + //line php5/php5.y:1116 { yyVAL.node = stmt.NewEcho(yyDollar[2].list) @@ -3253,7 +3257,7 @@ yydefault: } case 65: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1125 + //line php5/php5.y:1129 { yyVAL.node = stmt.NewInlineHtml(yyDollar[1].token.Value) @@ -3267,7 +3271,7 @@ yydefault: } case 66: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:1137 + //line php5/php5.y:1141 { yyVAL.node = stmt.NewExpression(yyDollar[1].node) @@ -3281,7 +3285,7 @@ yydefault: } case 67: yyDollar = yyS[yypt-5 : yypt+1] - //line php5/php5.y:1149 + //line php5/php5.y:1153 { yyVAL.node = stmt.NewUnset(yyDollar[3].list) @@ -3298,7 +3302,7 @@ yydefault: } case 68: yyDollar = yyS[yypt-8 : yypt+1] - //line php5/php5.y:1164 + //line php5/php5.y:1168 { if yyDollar[6].node == nil { switch n := yyDollar[8].node.(type) { @@ -3337,7 +3341,7 @@ yydefault: } case 69: yyDollar = yyS[yypt-8 : yypt+1] - //line php5/php5.y:1201 + //line php5/php5.y:1205 { if yyDollar[6].node == nil { switch n := yyDollar[8].node.(type) { @@ -3376,7 +3380,7 @@ yydefault: } case 70: yyDollar = yyS[yypt-5 : yypt+1] - //line php5/php5.y:1238 + //line php5/php5.y:1242 { yyVAL.node = stmt.NewDeclare(yyDollar[3].list, yyDollar[5].node) @@ -3392,7 +3396,7 @@ yydefault: } case 71: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1252 + //line php5/php5.y:1256 { yyVAL.node = stmt.NewNop() @@ -3406,7 +3410,7 @@ yydefault: } case 72: yyDollar = yyS[yypt-6 : yypt+1] - //line php5/php5.y:1264 + //line php5/php5.y:1268 { yyVAL.node = stmt.NewTry(yyDollar[3].list, yyDollar[5].list, yyDollar[6].node) @@ -3426,7 +3430,7 @@ yydefault: } case 73: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:1282 + //line php5/php5.y:1286 { yyVAL.node = stmt.NewThrow(yyDollar[2].node) @@ -3441,7 +3445,7 @@ yydefault: } case 74: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:1295 + //line php5/php5.y:1299 { label := node.NewIdentifier(yyDollar[2].token.Value) yyVAL.node = stmt.NewGoto(label) @@ -3452,14 +3456,14 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.GotoToken) - addMeta(label, yyDollar[2].token.Meta, meta.StringToken) + addMeta(label, yyDollar[2].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[3].token.Meta, meta.SemiColonToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 75: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:1314 + //line php5/php5.y:1318 { yyVAL.list = []node.Node{} @@ -3467,7 +3471,7 @@ yydefault: } case 76: yyDollar = yyS[yypt-9 : yypt+1] - //line php5/php5.y:1320 + //line php5/php5.y:1324 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[4].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -3482,7 +3486,7 @@ yydefault: // save comments addMeta(catch, yyDollar[1].token.Meta, meta.CatchToken) addMeta(catch, yyDollar[2].token.Meta, meta.OpenParenthesisToken) - addMeta(variable, yyDollar[4].token.Meta, meta.StringToken) + addMeta(variable, yyDollar[4].token.Meta, meta.VariableToken) addMeta(catch, yyDollar[5].token.Meta, meta.CloseParenthesisToken) addMeta(catch, yyDollar[6].token.Meta, meta.OpenCurlyBracesToken) addMeta(catch, yyDollar[8].token.Meta, meta.CloseCurlyBracesToken) @@ -3491,7 +3495,7 @@ yydefault: } case 77: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:1345 + //line php5/php5.y:1349 { yyVAL.node = nil @@ -3499,7 +3503,7 @@ yydefault: } case 78: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:1351 + //line php5/php5.y:1355 { yyVAL.node = stmt.NewFinally(yyDollar[3].list) @@ -3515,7 +3519,7 @@ yydefault: } case 79: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1368 + //line php5/php5.y:1372 { yyVAL.list = yyDollar[1].list @@ -3523,7 +3527,7 @@ yydefault: } case 80: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:1374 + //line php5/php5.y:1378 { yyVAL.list = []node.Node{} @@ -3531,7 +3535,7 @@ yydefault: } case 81: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1383 + //line php5/php5.y:1387 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -3539,7 +3543,7 @@ yydefault: } case 82: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:1389 + //line php5/php5.y:1393 { yyVAL.list = append(yyDollar[1].list, yyDollar[2].node) @@ -3547,7 +3551,7 @@ yydefault: } case 83: yyDollar = yyS[yypt-8 : yypt+1] - //line php5/php5.y:1398 + //line php5/php5.y:1402 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[4].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -3561,7 +3565,7 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.CatchToken) addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.OpenParenthesisToken) - addMeta(variable, yyDollar[4].token.Meta, meta.StringToken) + addMeta(variable, yyDollar[4].token.Meta, meta.VariableToken) addMeta(yyVAL.node, yyDollar[5].token.Meta, meta.CloseParenthesisToken) addMeta(yyVAL.node, yyDollar[6].token.Meta, meta.OpenCurlyBracesToken) addMeta(yyVAL.node, yyDollar[8].token.Meta, meta.CloseCurlyBracesToken) @@ -3570,7 +3574,7 @@ yydefault: } case 84: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1422 + //line php5/php5.y:1426 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -3578,18 +3582,18 @@ yydefault: } case 85: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:1428 + //line php5/php5.y:1432 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 86: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1440 + //line php5/php5.y:1444 { yyVAL.node = yyDollar[1].node @@ -3597,7 +3601,7 @@ yydefault: } case 87: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1449 + //line php5/php5.y:1453 { yyVAL.node = yyDollar[1].node @@ -3605,7 +3609,7 @@ yydefault: } case 88: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1458 + //line php5/php5.y:1462 { yyVAL.node = yyDollar[1].node @@ -3613,31 +3617,31 @@ yydefault: } case 89: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:1467 + //line php5/php5.y:1471 { yyVAL.token = nil } case 90: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1471 + //line php5/php5.y:1475 { yyVAL.token = yyDollar[1].token } case 91: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:1478 + //line php5/php5.y:1482 { yyVAL.token = nil } case 92: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1482 + //line php5/php5.y:1486 { yyVAL.token = yyDollar[1].token } case 93: yyDollar = yyS[yypt-9 : yypt+1] - //line php5/php5.y:1489 + //line php5/php5.y:1493 { name := node.NewIdentifier(yyDollar[3].token.Value) yyVAL.node = stmt.NewFunction(name, yyDollar[2].token != nil, yyDollar[5].list, nil, yyDollar[8].list, "") @@ -3651,7 +3655,7 @@ yydefault: if yyDollar[2].token != nil { addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.AmpersandToken) } - addMeta(name, yyDollar[3].token.Meta, meta.StringToken) + addMeta(name, yyDollar[3].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[4].token.Meta, meta.OpenParenthesisToken) addMeta(yyVAL.node, yyDollar[6].token.Meta, meta.CloseParenthesisToken) addMeta(yyVAL.node, yyDollar[7].token.Meta, meta.OpenCurlyBracesToken) @@ -3661,7 +3665,7 @@ yydefault: } case 94: yyDollar = yyS[yypt-7 : yypt+1] - //line php5/php5.y:1514 + //line php5/php5.y:1518 { name := node.NewIdentifier(yyDollar[2].token.Value) switch n := yyDollar[1].node.(type) { @@ -3683,7 +3687,7 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewNodeTokenPosition(yyDollar[1].node, yyDollar[7].token)) // save comments - addMeta(name, yyDollar[2].token.Meta, meta.StringToken) + addMeta(name, yyDollar[2].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[5].token.Meta, meta.OpenCurlyBracesToken) addMeta(yyVAL.node, yyDollar[7].token.Meta, meta.CloseCurlyBracesToken) @@ -3691,7 +3695,7 @@ yydefault: } case 95: yyDollar = yyS[yypt-6 : yypt+1] - //line php5/php5.y:1542 + //line php5/php5.y:1546 { name := node.NewIdentifier(yyDollar[2].token.Value) yyVAL.node = stmt.NewInterface(name, yyDollar[3].InterfaceExtends, yyDollar[5].list, "") @@ -3701,7 +3705,7 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition(yyDollar[1].token, yyDollar[6].token)) // save comments - addMeta(name, yyDollar[2].token.Meta, meta.StringToken) + addMeta(name, yyDollar[2].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[4].token.Meta, meta.OpenCurlyBracesToken) addMeta(yyVAL.node, yyDollar[6].token.Meta, meta.CloseCurlyBracesToken) @@ -3709,7 +3713,7 @@ yydefault: } case 96: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1562 + //line php5/php5.y:1566 { yyVAL.node = stmt.NewClass(nil, nil, nil, nil, nil, nil, "") @@ -3723,7 +3727,7 @@ yydefault: } case 97: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:1574 + //line php5/php5.y:1578 { classModifier := node.NewIdentifier(yyDollar[1].token.Value) yyVAL.node = stmt.NewClass(nil, []node.Node{classModifier}, nil, nil, nil, nil, "") @@ -3733,14 +3737,14 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition(yyDollar[1].token, yyDollar[2].token)) // save comments - addMeta(classModifier, yyDollar[1].token.Meta, meta.AbstractToken) + addMeta(classModifier, yyDollar[1].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.ClassToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 98: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1589 + //line php5/php5.y:1593 { yyVAL.node = stmt.NewTrait(nil, nil, "") @@ -3754,7 +3758,7 @@ yydefault: } case 99: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:1601 + //line php5/php5.y:1605 { classModifier := node.NewIdentifier(yyDollar[1].token.Value) yyVAL.node = stmt.NewClass(nil, []node.Node{classModifier}, nil, nil, nil, nil, "") @@ -3764,14 +3768,14 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition(yyDollar[1].token, yyDollar[2].token)) // save comments - addMeta(classModifier, yyDollar[1].token.Meta, meta.FinalToken) + addMeta(classModifier, yyDollar[1].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.ClassToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 100: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:1619 + //line php5/php5.y:1623 { yyVAL.ClassExtends = nil @@ -3779,7 +3783,7 @@ yydefault: } case 101: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:1625 + //line php5/php5.y:1629 { yyVAL.ClassExtends = stmt.NewClassExtends(yyDollar[2].node) @@ -3793,13 +3797,13 @@ yydefault: } case 102: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1640 + //line php5/php5.y:1644 { yyVAL.token = yyDollar[1].token } case 103: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:1647 + //line php5/php5.y:1651 { yyVAL.InterfaceExtends = nil @@ -3807,7 +3811,7 @@ yydefault: } case 104: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:1653 + //line php5/php5.y:1657 { yyVAL.InterfaceExtends = stmt.NewInterfaceExtends(yyDollar[2].list) @@ -3821,7 +3825,7 @@ yydefault: } case 105: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:1668 + //line php5/php5.y:1672 { yyVAL.ClassImplements = nil @@ -3829,7 +3833,7 @@ yydefault: } case 106: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:1674 + //line php5/php5.y:1678 { yyVAL.ClassImplements = stmt.NewClassImplements(yyDollar[2].list) @@ -3843,7 +3847,7 @@ yydefault: } case 107: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1689 + //line php5/php5.y:1693 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -3851,18 +3855,18 @@ yydefault: } case 108: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:1695 + //line php5/php5.y:1699 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 109: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:1707 + //line php5/php5.y:1711 { yyVAL.node = nil @@ -3870,7 +3874,7 @@ yydefault: } case 110: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:1713 + //line php5/php5.y:1717 { yyVAL.node = yyDollar[2].node @@ -3881,7 +3885,7 @@ yydefault: } case 111: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1725 + //line php5/php5.y:1729 { yyVAL.node = yyDollar[1].node @@ -3889,7 +3893,7 @@ yydefault: } case 112: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:1731 + //line php5/php5.y:1735 { yyVAL.node = expr.NewReference(yyDollar[2].node) @@ -3903,7 +3907,7 @@ yydefault: } case 113: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:1743 + //line php5/php5.y:1747 { yyVAL.node = expr.NewList(yyDollar[3].list) @@ -3919,7 +3923,7 @@ yydefault: } case 114: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1760 + //line php5/php5.y:1764 { yyVAL.node = stmt.NewFor(nil, nil, nil, yyDollar[1].node) @@ -3930,7 +3934,7 @@ yydefault: } case 115: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:1769 + //line php5/php5.y:1773 { stmtList := stmt.NewStmtList(yyDollar[2].list) yyVAL.node = stmt.NewAltFor(nil, nil, nil, stmtList) @@ -3948,7 +3952,7 @@ yydefault: } case 116: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1788 + //line php5/php5.y:1792 { yyVAL.node = stmt.NewForeach(nil, nil, nil, yyDollar[1].node) @@ -3959,7 +3963,7 @@ yydefault: } case 117: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:1797 + //line php5/php5.y:1801 { stmtList := stmt.NewStmtList(yyDollar[2].list) yyVAL.node = stmt.NewAltForeach(nil, nil, nil, stmtList) @@ -3977,7 +3981,7 @@ yydefault: } case 118: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1817 + //line php5/php5.y:1821 { yyVAL.node = yyDollar[1].node @@ -3985,7 +3989,7 @@ yydefault: } case 119: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:1823 + //line php5/php5.y:1827 { yyVAL.node = stmt.NewStmtList(yyDollar[2].list) @@ -4001,7 +4005,7 @@ yydefault: } case 120: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:1841 + //line php5/php5.y:1845 { name := node.NewIdentifier(yyDollar[1].token.Value) constant := stmt.NewConstant(name, yyDollar[3].node, "") @@ -4012,14 +4016,14 @@ yydefault: constant.SetPosition(yylex.(*Parser).positionBuilder.NewTokenNodePosition(yyDollar[1].token, yyDollar[3].node)) // save comments - addMeta(name, yyDollar[1].token.Meta, meta.StringToken) + addMeta(name, yyDollar[1].token.Meta, meta.IdentifierToken) addMeta(constant, yyDollar[2].token.Meta, meta.EqualToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 121: yyDollar = yyS[yypt-5 : yypt+1] - //line php5/php5.y:1857 + //line php5/php5.y:1861 { name := node.NewIdentifier(yyDollar[3].token.Value) constant := stmt.NewConstant(name, yyDollar[5].node, "") @@ -4031,14 +4035,14 @@ yydefault: // save comments addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) - addMeta(name, yyDollar[3].token.Meta, meta.StringToken) + addMeta(name, yyDollar[3].token.Meta, meta.IdentifierToken) addMeta(constant, yyDollar[4].token.Meta, meta.EqualToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 122: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:1878 + //line php5/php5.y:1882 { caseList := stmt.NewCaseList(yyDollar[2].list) yyVAL.node = stmt.NewSwitch(nil, caseList) @@ -4055,7 +4059,7 @@ yydefault: } case 123: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:1893 + //line php5/php5.y:1897 { caseList := stmt.NewCaseList(yyDollar[3].list) yyVAL.node = stmt.NewSwitch(nil, caseList) @@ -4073,7 +4077,7 @@ yydefault: } case 124: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:1909 + //line php5/php5.y:1913 { caseList := stmt.NewCaseList(yyDollar[2].list) yyVAL.node = stmt.NewAltSwitch(nil, caseList) @@ -4083,15 +4087,15 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition(yyDollar[1].token, yyDollar[4].token)) // save comments - addMeta(caseList, yyDollar[1].token.Meta, meta.ColonToken) - addMeta(caseList, yyDollar[3].token.Meta, meta.EndswitchToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.ColonToken) + addMeta(yyVAL.node, yyDollar[3].token.Meta, meta.EndswitchToken) addMeta(yyVAL.node, yyDollar[4].token.Meta, meta.SemiColonToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 125: yyDollar = yyS[yypt-5 : yypt+1] - //line php5/php5.y:1925 + //line php5/php5.y:1929 { caseList := stmt.NewCaseList(yyDollar[3].list) @@ -4102,16 +4106,16 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition(yyDollar[1].token, yyDollar[5].token)) // save comments - addMeta(caseList, yyDollar[1].token.Meta, meta.ColonToken) - addMeta(caseList, yyDollar[2].token.Meta, meta.SemiColonToken) - addMeta(caseList, yyDollar[4].token.Meta, meta.EndswitchToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.ColonToken) + addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.SwitchSemicolonToken) + addMeta(yyVAL.node, yyDollar[4].token.Meta, meta.EndswitchToken) addMeta(yyVAL.node, yyDollar[5].token.Meta, meta.SemiColonToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 126: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:1947 + //line php5/php5.y:1951 { yyVAL.list = []node.Node{} @@ -4119,7 +4123,7 @@ yydefault: } case 127: yyDollar = yyS[yypt-5 : yypt+1] - //line php5/php5.y:1953 + //line php5/php5.y:1957 { _case := stmt.NewCase(yyDollar[3].node, yyDollar[5].list) yyVAL.list = append(yyDollar[1].list, _case) @@ -4135,7 +4139,7 @@ yydefault: } case 128: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:1967 + //line php5/php5.y:1971 { _default := stmt.NewDefault(yyDollar[4].list) yyVAL.list = append(yyDollar[1].list, _default) @@ -4151,19 +4155,19 @@ yydefault: } case 129: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1985 + //line php5/php5.y:1989 { yyVAL.token = yyDollar[1].token } case 130: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1989 + //line php5/php5.y:1993 { yyVAL.token = yyDollar[1].token } case 131: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:1997 + //line php5/php5.y:2001 { yyVAL.node = stmt.NewWhile(nil, yyDollar[1].node) @@ -4174,7 +4178,7 @@ yydefault: } case 132: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:2006 + //line php5/php5.y:2010 { stmtList := stmt.NewStmtList(yyDollar[2].list) yyVAL.node = stmt.NewAltWhile(nil, stmtList) @@ -4192,7 +4196,7 @@ yydefault: } case 133: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:2027 + //line php5/php5.y:2031 { yyVAL.list = nil @@ -4200,7 +4204,7 @@ yydefault: } case 134: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:2033 + //line php5/php5.y:2037 { _elseIf := stmt.NewElseIf(yyDollar[3].node, yyDollar[4].node) yyVAL.list = append(yyDollar[1].list, _elseIf) @@ -4215,7 +4219,7 @@ yydefault: } case 135: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:2050 + //line php5/php5.y:2054 { yyVAL.list = nil @@ -4223,7 +4227,7 @@ yydefault: } case 136: yyDollar = yyS[yypt-5 : yypt+1] - //line php5/php5.y:2056 + //line php5/php5.y:2060 { stmts := stmt.NewStmtList(yyDollar[5].list) _elseIf := stmt.NewAltElseIf(yyDollar[3].node, stmts) @@ -4241,7 +4245,7 @@ yydefault: } case 137: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:2076 + //line php5/php5.y:2080 { yyVAL.node = nil @@ -4249,7 +4253,7 @@ yydefault: } case 138: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:2082 + //line php5/php5.y:2086 { yyVAL.node = stmt.NewElse(yyDollar[2].node) @@ -4263,7 +4267,7 @@ yydefault: } case 139: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:2098 + //line php5/php5.y:2102 { yyVAL.node = nil @@ -4271,7 +4275,7 @@ yydefault: } case 140: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:2104 + //line php5/php5.y:2108 { stmts := stmt.NewStmtList(yyDollar[3].list) yyVAL.node = stmt.NewAltElse(stmts) @@ -4288,7 +4292,7 @@ yydefault: } case 141: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2123 + //line php5/php5.y:2127 { yyVAL.list = yyDollar[1].list @@ -4296,7 +4300,7 @@ yydefault: } case 142: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:2129 + //line php5/php5.y:2133 { yyVAL.list = nil @@ -4304,7 +4308,7 @@ yydefault: } case 143: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2138 + //line php5/php5.y:2142 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -4312,18 +4316,18 @@ yydefault: } case 144: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:2144 + //line php5/php5.y:2148 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 145: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:2156 + //line php5/php5.y:2160 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[4].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -4355,7 +4359,7 @@ yydefault: } case 146: yyDollar = yyS[yypt-6 : yypt+1] - //line php5/php5.y:2186 + //line php5/php5.y:2190 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[4].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -4388,7 +4392,7 @@ yydefault: } case 147: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:2221 + //line php5/php5.y:2225 { yyVAL.node = nil @@ -4396,7 +4400,7 @@ yydefault: } case 148: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2227 + //line php5/php5.y:2231 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -4404,13 +4408,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.ArrayToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 149: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2239 + //line php5/php5.y:2243 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -4418,13 +4422,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.CallableToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 150: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2251 + //line php5/php5.y:2255 { yyVAL.node = yyDollar[1].node @@ -4432,7 +4436,7 @@ yydefault: } case 151: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:2261 + //line php5/php5.y:2265 { yyVAL.node = node.NewArgumentList(nil) @@ -4447,7 +4451,7 @@ yydefault: } case 152: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:2274 + //line php5/php5.y:2278 { yyVAL.node = node.NewArgumentList(yyDollar[2].list) @@ -4462,7 +4466,7 @@ yydefault: } case 153: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:2287 + //line php5/php5.y:2291 { arg := node.NewArgument(yyDollar[2].node, false, false) yyVAL.node = node.NewArgumentList([]node.Node{arg}) @@ -4479,7 +4483,7 @@ yydefault: } case 154: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2306 + //line php5/php5.y:2310 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -4487,18 +4491,18 @@ yydefault: } case 155: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:2312 + //line php5/php5.y:2316 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 156: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2324 + //line php5/php5.y:2328 { yyVAL.node = node.NewArgument(yyDollar[1].node, false, false) @@ -4509,7 +4513,7 @@ yydefault: } case 157: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2333 + //line php5/php5.y:2337 { yyVAL.node = node.NewArgument(yyDollar[1].node, false, false) @@ -4520,7 +4524,7 @@ yydefault: } case 158: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:2342 + //line php5/php5.y:2346 { yyVAL.node = node.NewArgument(yyDollar[2].node, false, true) @@ -4534,7 +4538,7 @@ yydefault: } case 159: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:2354 + //line php5/php5.y:2358 { yyVAL.node = node.NewArgument(yyDollar[2].node, true, false) @@ -4548,18 +4552,18 @@ yydefault: } case 160: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:2369 + //line php5/php5.y:2373 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 161: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2378 + //line php5/php5.y:2382 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -4567,7 +4571,7 @@ yydefault: } case 162: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2388 + //line php5/php5.y:2392 { name := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) yyVAL.node = expr.NewVariable(name) @@ -4583,7 +4587,7 @@ yydefault: } case 163: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:2402 + //line php5/php5.y:2406 { yyVAL.node = expr.NewVariable(yyDollar[2].node) @@ -4597,7 +4601,7 @@ yydefault: } case 164: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:2414 + //line php5/php5.y:2418 { yyVAL.node = expr.NewVariable(yyDollar[3].node) @@ -4613,7 +4617,7 @@ yydefault: } case 165: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:2432 + //line php5/php5.y:2436 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[3].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -4633,7 +4637,7 @@ yydefault: } case 166: yyDollar = yyS[yypt-5 : yypt+1] - //line php5/php5.y:2450 + //line php5/php5.y:2454 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[3].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -4654,7 +4658,7 @@ yydefault: } case 167: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2469 + //line php5/php5.y:2473 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -4673,7 +4677,7 @@ yydefault: } case 168: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:2486 + //line php5/php5.y:2490 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -4693,7 +4697,7 @@ yydefault: } case 169: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:2508 + //line php5/php5.y:2512 { yyVAL.list = append(yyDollar[1].list, yyDollar[2].node) @@ -4701,7 +4705,7 @@ yydefault: } case 170: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:2514 + //line php5/php5.y:2518 { yyVAL.list = []node.Node{} @@ -4709,7 +4713,7 @@ yydefault: } case 171: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:2524 + //line php5/php5.y:2528 { yyVAL.node = stmt.NewPropertyList(yyDollar[1].list, yyDollar[2].list) @@ -4723,7 +4727,7 @@ yydefault: } case 172: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:2536 + //line php5/php5.y:2540 { yyVAL.node = yyDollar[1].node @@ -4737,7 +4741,7 @@ yydefault: } case 173: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2548 + //line php5/php5.y:2552 { yyVAL.node = yyDollar[1].node @@ -4745,7 +4749,7 @@ yydefault: } case 174: yyDollar = yyS[yypt-8 : yypt+1] - //line php5/php5.y:2554 + //line php5/php5.y:2558 { name := node.NewIdentifier(yyDollar[4].token.Value) yyVAL.node = stmt.NewClassMethod(name, yyDollar[1].list, yyDollar[3].token != nil, yyDollar[6].list, nil, yyDollar[8].node, "") @@ -4771,16 +4775,9 @@ yydefault: } case 175: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:2581 + //line php5/php5.y:2585 { - var adaptationList *stmt.TraitAdaptationList - switch n := yyDollar[3].node.(type) { - case *stmt.TraitAdaptationList: - adaptationList = n - default: - adaptationList = nil - } - yyVAL.node = stmt.NewTraitUse(yyDollar[2].list, adaptationList) + yyVAL.node = stmt.NewTraitUse(yyDollar[2].list, yyDollar[3].node) // save position yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenNodePosition(yyDollar[1].token, yyDollar[3].node)) @@ -4792,7 +4789,7 @@ yydefault: } case 176: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2603 + //line php5/php5.y:2600 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -4800,18 +4797,18 @@ yydefault: } case 177: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:2609 + //line php5/php5.y:2606 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 178: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2621 + //line php5/php5.y:2618 { yyVAL.node = stmt.NewNop() @@ -4824,7 +4821,7 @@ yydefault: } case 179: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:2633 + //line php5/php5.y:2630 { yyVAL.node = stmt.NewTraitAdaptationList(yyDollar[2].list) @@ -4838,7 +4835,7 @@ yydefault: } case 180: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:2648 + //line php5/php5.y:2645 { yyVAL.list = nil @@ -4846,7 +4843,7 @@ yydefault: } case 181: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2654 + //line php5/php5.y:2651 { yyVAL.list = yyDollar[1].list @@ -4854,7 +4851,7 @@ yydefault: } case 182: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2663 + //line php5/php5.y:2660 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -4862,7 +4859,7 @@ yydefault: } case 183: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:2669 + //line php5/php5.y:2666 { yyVAL.list = append(yyDollar[1].list, yyDollar[2].node) @@ -4870,7 +4867,7 @@ yydefault: } case 184: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:2678 + //line php5/php5.y:2675 { yyVAL.node = yyDollar[1].node @@ -4881,7 +4878,7 @@ yydefault: } case 185: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:2687 + //line php5/php5.y:2684 { yyVAL.node = yyDollar[1].node @@ -4892,7 +4889,7 @@ yydefault: } case 186: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:2699 + //line php5/php5.y:2696 { yyVAL.node = stmt.NewTraitUsePrecedence(yyDollar[1].node, yyDollar[3].list) @@ -4906,7 +4903,7 @@ yydefault: } case 187: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2714 + //line php5/php5.y:2711 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -4914,18 +4911,18 @@ yydefault: } case 188: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:2720 + //line php5/php5.y:2717 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 189: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2732 + //line php5/php5.y:2729 { name := node.NewIdentifier(yyDollar[1].token.Value) yyVAL.node = stmt.NewTraitMethodRef(nil, name) @@ -4941,7 +4938,7 @@ yydefault: } case 190: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2746 + //line php5/php5.y:2743 { yyVAL.node = yyDollar[1].node @@ -4949,7 +4946,7 @@ yydefault: } case 191: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:2755 + //line php5/php5.y:2752 { target := node.NewIdentifier(yyDollar[3].token.Value) yyVAL.node = stmt.NewTraitMethodRef(yyDollar[1].node, target) @@ -4966,7 +4963,7 @@ yydefault: } case 192: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:2773 + //line php5/php5.y:2770 { alias := node.NewIdentifier(yyDollar[4].token.Value) yyVAL.node = stmt.NewTraitUseAlias(yyDollar[1].node, yyDollar[3].node, alias) @@ -4983,7 +4980,7 @@ yydefault: } case 193: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:2788 + //line php5/php5.y:2785 { yyVAL.node = stmt.NewTraitUseAlias(yyDollar[1].node, yyDollar[3].node, nil) @@ -4997,7 +4994,7 @@ yydefault: } case 194: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:2803 + //line php5/php5.y:2800 { yyVAL.node = nil @@ -5005,7 +5002,7 @@ yydefault: } case 195: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2809 + //line php5/php5.y:2806 { yyVAL.node = yyDollar[1].node @@ -5013,7 +5010,7 @@ yydefault: } case 196: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2818 + //line php5/php5.y:2815 { yyVAL.node = stmt.NewNop() @@ -5027,7 +5024,7 @@ yydefault: } case 197: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:2830 + //line php5/php5.y:2827 { yyVAL.node = stmt.NewStmtList(yyDollar[2].list) @@ -5042,7 +5039,7 @@ yydefault: } case 198: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2846 + //line php5/php5.y:2843 { yyVAL.list = yyDollar[1].list @@ -5050,7 +5047,7 @@ yydefault: } case 199: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2852 + //line php5/php5.y:2849 { modifier := node.NewIdentifier(yyDollar[1].token.Value) yyVAL.list = []node.Node{modifier} @@ -5059,13 +5056,13 @@ yydefault: modifier.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(modifier, yyDollar[1].token.Meta, meta.VarToken) + addMeta(modifier, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 200: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:2868 + //line php5/php5.y:2865 { yyVAL.list = nil @@ -5073,7 +5070,7 @@ yydefault: } case 201: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2874 + //line php5/php5.y:2871 { yyVAL.list = yyDollar[1].list @@ -5081,7 +5078,7 @@ yydefault: } case 202: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2883 + //line php5/php5.y:2880 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -5089,7 +5086,7 @@ yydefault: } case 203: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:2889 + //line php5/php5.y:2886 { yyVAL.list = append(yyDollar[1].list, yyDollar[2].node) @@ -5097,7 +5094,7 @@ yydefault: } case 204: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2898 + //line php5/php5.y:2895 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -5105,13 +5102,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.PublicToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 205: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2910 + //line php5/php5.y:2907 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -5119,13 +5116,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.ProtectedToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 206: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2922 + //line php5/php5.y:2919 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -5133,13 +5130,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.PrivateToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 207: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2934 + //line php5/php5.y:2931 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -5147,13 +5144,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.StaticToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 208: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2946 + //line php5/php5.y:2943 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -5161,13 +5158,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.AbstractToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 209: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:2958 + //line php5/php5.y:2955 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -5175,13 +5172,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.FinalToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 210: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:2973 + //line php5/php5.y:2970 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[3].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -5201,7 +5198,7 @@ yydefault: } case 211: yyDollar = yyS[yypt-5 : yypt+1] - //line php5/php5.y:2991 + //line php5/php5.y:2988 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[3].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -5222,7 +5219,7 @@ yydefault: } case 212: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:3010 + //line php5/php5.y:3007 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -5241,7 +5238,7 @@ yydefault: } case 213: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3027 + //line php5/php5.y:3024 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -5261,7 +5258,7 @@ yydefault: } case 214: yyDollar = yyS[yypt-5 : yypt+1] - //line php5/php5.y:3048 + //line php5/php5.y:3045 { name := node.NewIdentifier(yyDollar[3].token.Value) constant := stmt.NewConstant(name, yyDollar[5].node, "") @@ -5283,7 +5280,7 @@ yydefault: } case 215: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:3068 + //line php5/php5.y:3065 { name := node.NewIdentifier(yyDollar[2].token.Value) constant := stmt.NewConstant(name, yyDollar[4].node, "") @@ -5303,18 +5300,18 @@ yydefault: } case 216: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3089 + //line php5/php5.y:3086 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 217: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:3098 + //line php5/php5.y:3095 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -5322,7 +5319,7 @@ yydefault: } case 218: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:3108 + //line php5/php5.y:3105 { yyVAL.list = nil @@ -5330,7 +5327,7 @@ yydefault: } case 219: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:3114 + //line php5/php5.y:3111 { yyVAL.list = yyDollar[1].list @@ -5338,18 +5335,18 @@ yydefault: } case 220: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3123 + //line php5/php5.y:3120 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 221: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:3132 + //line php5/php5.y:3129 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -5357,7 +5354,7 @@ yydefault: } case 222: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:3141 + //line php5/php5.y:3138 { yyVAL.list = append(yyDollar[1].list, yyDollar[2].list...) @@ -5365,7 +5362,7 @@ yydefault: } case 223: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:3147 + //line php5/php5.y:3144 { yyVAL.list = yyDollar[1].list @@ -5373,7 +5370,7 @@ yydefault: } case 224: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:3156 + //line php5/php5.y:3153 { fetch := expr.NewArrayDimFetch(nil, yyDollar[3].node) yyVAL.list = append(yyDollar[1].list, fetch) @@ -5389,7 +5386,7 @@ yydefault: } case 225: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3170 + //line php5/php5.y:3167 { fetch := expr.NewArrayDimFetch(nil, yyDollar[2].node) yyVAL.list = []node.Node{fetch} @@ -5405,7 +5402,7 @@ yydefault: } case 226: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:3187 + //line php5/php5.y:3184 { yyVAL.list = append(yyDollar[1].list, yyDollar[2].list...) @@ -5413,7 +5410,7 @@ yydefault: } case 227: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:3193 + //line php5/php5.y:3190 { yyVAL.list = yyDollar[1].list @@ -5421,7 +5418,7 @@ yydefault: } case 228: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:3199 + //line php5/php5.y:3196 { yyVAL.list = yyDollar[1].list @@ -5429,7 +5426,7 @@ yydefault: } case 229: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:3208 + //line php5/php5.y:3205 { yyVAL.list = nil @@ -5437,7 +5434,7 @@ yydefault: } case 230: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:3214 + //line php5/php5.y:3211 { yyVAL.list = yyDollar[1].list @@ -5445,7 +5442,7 @@ yydefault: } case 231: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3223 + //line php5/php5.y:3220 { if yyDollar[3].node != nil { @@ -5463,7 +5460,7 @@ yydefault: } case 232: yyDollar = yyS[yypt-6 : yypt+1] - //line php5/php5.y:3242 + //line php5/php5.y:3239 { list := expr.NewList(yyDollar[3].list) yyVAL.node = assign.NewAssign(list, yyDollar[6].node) @@ -5482,7 +5479,7 @@ yydefault: } case 233: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3259 + //line php5/php5.y:3256 { yyVAL.node = assign.NewAssign(yyDollar[1].node, yyDollar[3].node) @@ -5496,7 +5493,7 @@ yydefault: } case 234: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:3271 + //line php5/php5.y:3268 { yyVAL.node = assign.NewReference(yyDollar[1].node, yyDollar[4].node) @@ -5511,7 +5508,7 @@ yydefault: } case 235: yyDollar = yyS[yypt-6 : yypt+1] - //line php5/php5.y:3284 + //line php5/php5.y:3281 { var _new *expr.New @@ -5539,7 +5536,7 @@ yydefault: } case 236: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:3310 + //line php5/php5.y:3307 { yyVAL.node = expr.NewClone(yyDollar[2].node) @@ -5553,7 +5550,7 @@ yydefault: } case 237: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3322 + //line php5/php5.y:3319 { yyVAL.node = assign.NewPlus(yyDollar[1].node, yyDollar[3].node) @@ -5567,7 +5564,7 @@ yydefault: } case 238: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3334 + //line php5/php5.y:3331 { yyVAL.node = assign.NewMinus(yyDollar[1].node, yyDollar[3].node) @@ -5581,7 +5578,7 @@ yydefault: } case 239: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3346 + //line php5/php5.y:3343 { yyVAL.node = assign.NewMul(yyDollar[1].node, yyDollar[3].node) @@ -5595,7 +5592,7 @@ yydefault: } case 240: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3358 + //line php5/php5.y:3355 { yyVAL.node = assign.NewPow(yyDollar[1].node, yyDollar[3].node) @@ -5609,7 +5606,7 @@ yydefault: } case 241: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3370 + //line php5/php5.y:3367 { yyVAL.node = assign.NewDiv(yyDollar[1].node, yyDollar[3].node) @@ -5623,7 +5620,7 @@ yydefault: } case 242: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3382 + //line php5/php5.y:3379 { yyVAL.node = assign.NewConcat(yyDollar[1].node, yyDollar[3].node) @@ -5637,7 +5634,7 @@ yydefault: } case 243: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3394 + //line php5/php5.y:3391 { yyVAL.node = assign.NewMod(yyDollar[1].node, yyDollar[3].node) @@ -5651,7 +5648,7 @@ yydefault: } case 244: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3406 + //line php5/php5.y:3403 { yyVAL.node = assign.NewBitwiseAnd(yyDollar[1].node, yyDollar[3].node) @@ -5665,7 +5662,7 @@ yydefault: } case 245: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3418 + //line php5/php5.y:3415 { yyVAL.node = assign.NewBitwiseOr(yyDollar[1].node, yyDollar[3].node) @@ -5679,7 +5676,7 @@ yydefault: } case 246: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3430 + //line php5/php5.y:3427 { yyVAL.node = assign.NewBitwiseXor(yyDollar[1].node, yyDollar[3].node) @@ -5693,7 +5690,7 @@ yydefault: } case 247: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3442 + //line php5/php5.y:3439 { yyVAL.node = assign.NewShiftLeft(yyDollar[1].node, yyDollar[3].node) @@ -5707,7 +5704,7 @@ yydefault: } case 248: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3454 + //line php5/php5.y:3451 { yyVAL.node = assign.NewShiftRight(yyDollar[1].node, yyDollar[3].node) @@ -5721,7 +5718,7 @@ yydefault: } case 249: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:3466 + //line php5/php5.y:3463 { yyVAL.node = expr.NewPostInc(yyDollar[1].node) @@ -5735,7 +5732,7 @@ yydefault: } case 250: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:3478 + //line php5/php5.y:3475 { yyVAL.node = expr.NewPreInc(yyDollar[2].node) @@ -5749,7 +5746,7 @@ yydefault: } case 251: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:3490 + //line php5/php5.y:3487 { yyVAL.node = expr.NewPostDec(yyDollar[1].node) @@ -5763,7 +5760,7 @@ yydefault: } case 252: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:3502 + //line php5/php5.y:3499 { yyVAL.node = expr.NewPreDec(yyDollar[2].node) @@ -5777,7 +5774,7 @@ yydefault: } case 253: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3514 + //line php5/php5.y:3511 { yyVAL.node = binary.NewBooleanOr(yyDollar[1].node, yyDollar[3].node) @@ -5791,7 +5788,7 @@ yydefault: } case 254: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3526 + //line php5/php5.y:3523 { yyVAL.node = binary.NewBooleanAnd(yyDollar[1].node, yyDollar[3].node) @@ -5805,7 +5802,7 @@ yydefault: } case 255: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3538 + //line php5/php5.y:3535 { yyVAL.node = binary.NewLogicalOr(yyDollar[1].node, yyDollar[3].node) @@ -5819,7 +5816,7 @@ yydefault: } case 256: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3550 + //line php5/php5.y:3547 { yyVAL.node = binary.NewLogicalAnd(yyDollar[1].node, yyDollar[3].node) @@ -5833,7 +5830,7 @@ yydefault: } case 257: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3562 + //line php5/php5.y:3559 { yyVAL.node = binary.NewLogicalXor(yyDollar[1].node, yyDollar[3].node) @@ -5847,7 +5844,7 @@ yydefault: } case 258: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3574 + //line php5/php5.y:3571 { yyVAL.node = binary.NewBitwiseOr(yyDollar[1].node, yyDollar[3].node) @@ -5861,7 +5858,7 @@ yydefault: } case 259: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3586 + //line php5/php5.y:3583 { yyVAL.node = binary.NewBitwiseAnd(yyDollar[1].node, yyDollar[3].node) @@ -5875,7 +5872,7 @@ yydefault: } case 260: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3598 + //line php5/php5.y:3595 { yyVAL.node = binary.NewBitwiseXor(yyDollar[1].node, yyDollar[3].node) @@ -5889,7 +5886,7 @@ yydefault: } case 261: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3610 + //line php5/php5.y:3607 { yyVAL.node = binary.NewConcat(yyDollar[1].node, yyDollar[3].node) @@ -5903,7 +5900,7 @@ yydefault: } case 262: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3622 + //line php5/php5.y:3619 { yyVAL.node = binary.NewPlus(yyDollar[1].node, yyDollar[3].node) @@ -5917,7 +5914,7 @@ yydefault: } case 263: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3634 + //line php5/php5.y:3631 { yyVAL.node = binary.NewMinus(yyDollar[1].node, yyDollar[3].node) @@ -5931,7 +5928,7 @@ yydefault: } case 264: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3646 + //line php5/php5.y:3643 { yyVAL.node = binary.NewMul(yyDollar[1].node, yyDollar[3].node) @@ -5945,7 +5942,7 @@ yydefault: } case 265: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3658 + //line php5/php5.y:3655 { yyVAL.node = binary.NewPow(yyDollar[1].node, yyDollar[3].node) @@ -5959,7 +5956,7 @@ yydefault: } case 266: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3670 + //line php5/php5.y:3667 { yyVAL.node = binary.NewDiv(yyDollar[1].node, yyDollar[3].node) @@ -5973,7 +5970,7 @@ yydefault: } case 267: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3682 + //line php5/php5.y:3679 { yyVAL.node = binary.NewMod(yyDollar[1].node, yyDollar[3].node) @@ -5987,7 +5984,7 @@ yydefault: } case 268: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3694 + //line php5/php5.y:3691 { yyVAL.node = binary.NewShiftLeft(yyDollar[1].node, yyDollar[3].node) @@ -6001,7 +5998,7 @@ yydefault: } case 269: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3706 + //line php5/php5.y:3703 { yyVAL.node = binary.NewShiftRight(yyDollar[1].node, yyDollar[3].node) @@ -6015,7 +6012,7 @@ yydefault: } case 270: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:3718 + //line php5/php5.y:3715 { yyVAL.node = expr.NewUnaryPlus(yyDollar[2].node) @@ -6029,7 +6026,7 @@ yydefault: } case 271: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:3730 + //line php5/php5.y:3727 { yyVAL.node = expr.NewUnaryMinus(yyDollar[2].node) @@ -6043,7 +6040,7 @@ yydefault: } case 272: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:3742 + //line php5/php5.y:3739 { yyVAL.node = expr.NewBooleanNot(yyDollar[2].node) @@ -6057,7 +6054,7 @@ yydefault: } case 273: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:3754 + //line php5/php5.y:3751 { yyVAL.node = expr.NewBitwiseNot(yyDollar[2].node) @@ -6071,7 +6068,7 @@ yydefault: } case 274: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3766 + //line php5/php5.y:3763 { yyVAL.node = binary.NewIdentical(yyDollar[1].node, yyDollar[3].node) @@ -6085,7 +6082,7 @@ yydefault: } case 275: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3778 + //line php5/php5.y:3775 { yyVAL.node = binary.NewNotIdentical(yyDollar[1].node, yyDollar[3].node) @@ -6099,7 +6096,7 @@ yydefault: } case 276: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3790 + //line php5/php5.y:3787 { yyVAL.node = binary.NewEqual(yyDollar[1].node, yyDollar[3].node) @@ -6113,7 +6110,7 @@ yydefault: } case 277: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3802 + //line php5/php5.y:3799 { yyVAL.node = binary.NewNotEqual(yyDollar[1].node, yyDollar[3].node) @@ -6127,7 +6124,7 @@ yydefault: } case 278: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3814 + //line php5/php5.y:3811 { yyVAL.node = binary.NewSmaller(yyDollar[1].node, yyDollar[3].node) @@ -6141,7 +6138,7 @@ yydefault: } case 279: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3826 + //line php5/php5.y:3823 { yyVAL.node = binary.NewSmallerOrEqual(yyDollar[1].node, yyDollar[3].node) @@ -6155,7 +6152,7 @@ yydefault: } case 280: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3838 + //line php5/php5.y:3835 { yyVAL.node = binary.NewGreater(yyDollar[1].node, yyDollar[3].node) @@ -6169,7 +6166,7 @@ yydefault: } case 281: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3850 + //line php5/php5.y:3847 { yyVAL.node = binary.NewGreaterOrEqual(yyDollar[1].node, yyDollar[3].node) @@ -6183,7 +6180,7 @@ yydefault: } case 282: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:3862 + //line php5/php5.y:3859 { yyVAL.node = expr.NewInstanceOf(yyDollar[1].node, yyDollar[3].node) @@ -6197,7 +6194,7 @@ yydefault: } case 283: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:3874 + //line php5/php5.y:3871 { yyVAL.node = yyDollar[1].node @@ -6205,7 +6202,7 @@ yydefault: } case 284: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:3880 + //line php5/php5.y:3877 { yyVAL.node = yyDollar[1].node @@ -6213,7 +6210,7 @@ yydefault: } case 285: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:3886 + //line php5/php5.y:3883 { yyVAL.node = yyDollar[2].node @@ -6244,7 +6241,7 @@ yydefault: } case 286: yyDollar = yyS[yypt-5 : yypt+1] - //line php5/php5.y:3915 + //line php5/php5.y:3912 { yyVAL.node = expr.NewTernary(yyDollar[1].node, yyDollar[3].node, yyDollar[5].node) @@ -6259,7 +6256,7 @@ yydefault: } case 287: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:3928 + //line php5/php5.y:3925 { yyVAL.node = expr.NewTernary(yyDollar[1].node, nil, yyDollar[4].node) @@ -6274,7 +6271,7 @@ yydefault: } case 288: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:3941 + //line php5/php5.y:3938 { yyVAL.node = yyDollar[1].node @@ -6282,7 +6279,7 @@ yydefault: } case 289: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:3947 + //line php5/php5.y:3944 { yyVAL.node = cast.NewInt(yyDollar[2].node) @@ -6296,7 +6293,7 @@ yydefault: } case 290: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:3959 + //line php5/php5.y:3956 { yyVAL.node = cast.NewDouble(yyDollar[2].node) @@ -6310,7 +6307,7 @@ yydefault: } case 291: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:3971 + //line php5/php5.y:3968 { yyVAL.node = cast.NewString(yyDollar[2].node) @@ -6324,7 +6321,7 @@ yydefault: } case 292: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:3983 + //line php5/php5.y:3980 { yyVAL.node = cast.NewArray(yyDollar[2].node) @@ -6338,7 +6335,7 @@ yydefault: } case 293: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:3995 + //line php5/php5.y:3992 { yyVAL.node = cast.NewObject(yyDollar[2].node) @@ -6352,7 +6349,7 @@ yydefault: } case 294: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:4007 + //line php5/php5.y:4004 { yyVAL.node = cast.NewBool(yyDollar[2].node) @@ -6366,7 +6363,7 @@ yydefault: } case 295: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:4019 + //line php5/php5.y:4016 { yyVAL.node = cast.NewUnset(yyDollar[2].node) @@ -6380,7 +6377,7 @@ yydefault: } case 296: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:4031 + //line php5/php5.y:4028 { if strings.EqualFold(yyDollar[1].token.Value, "die") { yyVAL.node = expr.NewDie(nil) @@ -6410,7 +6407,7 @@ yydefault: } case 297: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:4059 + //line php5/php5.y:4056 { yyVAL.node = expr.NewErrorSuppress(yyDollar[2].node) @@ -6424,7 +6421,7 @@ yydefault: } case 298: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4071 + //line php5/php5.y:4068 { yyVAL.node = yyDollar[1].node @@ -6432,7 +6429,7 @@ yydefault: } case 299: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4077 + //line php5/php5.y:4074 { yyVAL.node = yyDollar[1].node @@ -6440,7 +6437,7 @@ yydefault: } case 300: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4083 + //line php5/php5.y:4080 { yyVAL.node = yyDollar[1].node @@ -6448,7 +6445,7 @@ yydefault: } case 301: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:4089 + //line php5/php5.y:4086 { yyVAL.node = expr.NewShellExec(yyDollar[2].list) @@ -6463,7 +6460,7 @@ yydefault: } case 302: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:4102 + //line php5/php5.y:4099 { yyVAL.node = expr.NewPrint(yyDollar[2].node) @@ -6477,7 +6474,7 @@ yydefault: } case 303: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4114 + //line php5/php5.y:4111 { yyVAL.node = expr.NewYield(nil, nil) @@ -6491,7 +6488,7 @@ yydefault: } case 304: yyDollar = yyS[yypt-9 : yypt+1] - //line php5/php5.y:4126 + //line php5/php5.y:4123 { yyVAL.node = expr.NewClosure(yyDollar[4].list, yyDollar[6].ClosureUse, nil, yyDollar[8].list, false, yyDollar[2].token != nil, "") @@ -6512,7 +6509,7 @@ yydefault: } case 305: yyDollar = yyS[yypt-10 : yypt+1] - //line php5/php5.y:4145 + //line php5/php5.y:4142 { yyVAL.node = expr.NewClosure(yyDollar[5].list, yyDollar[7].ClosureUse, nil, yyDollar[9].list, true, yyDollar[3].token != nil, "") @@ -6534,7 +6531,7 @@ yydefault: } case 306: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:4168 + //line php5/php5.y:4165 { yyVAL.node = expr.NewYield(nil, yyDollar[2].node) @@ -6548,7 +6545,7 @@ yydefault: } case 307: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:4180 + //line php5/php5.y:4177 { yyVAL.node = expr.NewYield(nil, yyDollar[2].node) @@ -6562,7 +6559,7 @@ yydefault: } case 308: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:4192 + //line php5/php5.y:4189 { yyVAL.node = expr.NewYield(yyDollar[2].node, yyDollar[4].node) @@ -6577,7 +6574,7 @@ yydefault: } case 309: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:4205 + //line php5/php5.y:4202 { yyVAL.node = expr.NewYield(yyDollar[2].node, yyDollar[4].node) @@ -6592,7 +6589,7 @@ yydefault: } case 310: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:4221 + //line php5/php5.y:4218 { yyVAL.node = expr.NewArrayDimFetch(yyDollar[1].node, yyDollar[3].node) @@ -6607,7 +6604,7 @@ yydefault: } case 311: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:4234 + //line php5/php5.y:4231 { yyVAL.node = expr.NewArrayDimFetch(yyDollar[1].node, yyDollar[3].node) @@ -6622,7 +6619,7 @@ yydefault: } case 312: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:4247 + //line php5/php5.y:4244 { str := scalar.NewString(yyDollar[1].token.Value) yyVAL.node = expr.NewArrayDimFetch(str, yyDollar[3].node) @@ -6639,7 +6636,7 @@ yydefault: } case 313: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:4262 + //line php5/php5.y:4259 { yyVAL.node = expr.NewArrayDimFetch(yyDollar[1].node, yyDollar[3].node) @@ -6654,7 +6651,7 @@ yydefault: } case 314: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:4278 + //line php5/php5.y:4275 { yyVAL.node = expr.NewArray(yyDollar[3].list) @@ -6670,7 +6667,7 @@ yydefault: } case 315: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:4292 + //line php5/php5.y:4289 { yyVAL.node = expr.NewShortArray(yyDollar[2].list) @@ -6685,13 +6682,13 @@ yydefault: } case 316: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4308 + //line php5/php5.y:4305 { yyVAL.token = yyDollar[1].token } case 317: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:4315 + //line php5/php5.y:4312 { yyVAL.ClosureUse = nil @@ -6699,7 +6696,7 @@ yydefault: } case 318: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:4321 + //line php5/php5.y:4318 { yyVAL.ClosureUse = expr.NewClosureUse(yyDollar[3].list) @@ -6709,7 +6706,7 @@ yydefault: } case 319: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:4332 + //line php5/php5.y:4329 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[3].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -6727,7 +6724,7 @@ yydefault: } case 320: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:4348 + //line php5/php5.y:4345 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[4].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -6748,7 +6745,7 @@ yydefault: } case 321: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4367 + //line php5/php5.y:4364 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -6765,7 +6762,7 @@ yydefault: } case 322: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:4382 + //line php5/php5.y:4379 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[2].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -6785,7 +6782,7 @@ yydefault: } case 323: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:4403 + //line php5/php5.y:4400 { name := name.NewName(yyDollar[1].list) yyVAL.node = expr.NewFunctionCall(name, yyDollar[2].node.(*node.ArgumentList)) @@ -6798,7 +6795,7 @@ yydefault: } case 324: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:4414 + //line php5/php5.y:4411 { funcName := name.NewRelative(yyDollar[3].list) yyVAL.node = expr.NewFunctionCall(funcName, yyDollar[4].node.(*node.ArgumentList)) @@ -6815,7 +6812,7 @@ yydefault: } case 325: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:4429 + //line php5/php5.y:4426 { funcName := name.NewFullyQualified(yyDollar[2].list) yyVAL.node = expr.NewFunctionCall(funcName, yyDollar[3].node.(*node.ArgumentList)) @@ -6831,7 +6828,7 @@ yydefault: } case 326: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:4443 + //line php5/php5.y:4440 { yyVAL.node = expr.NewStaticCall(yyDollar[1].node, yyDollar[3].node, yyDollar[4].node.(*node.ArgumentList)) @@ -6845,7 +6842,7 @@ yydefault: } case 327: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:4455 + //line php5/php5.y:4452 { yyVAL.node = expr.NewStaticCall(yyDollar[1].node, yyDollar[3].node, yyDollar[4].node.(*node.ArgumentList)) @@ -6859,7 +6856,7 @@ yydefault: } case 328: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:4467 + //line php5/php5.y:4464 { yyVAL.node = expr.NewStaticCall(yyDollar[1].node, yyDollar[3].node, yyDollar[4].node.(*node.ArgumentList)) @@ -6873,7 +6870,7 @@ yydefault: } case 329: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:4479 + //line php5/php5.y:4476 { yyVAL.node = expr.NewStaticCall(yyDollar[1].node, yyDollar[3].node, yyDollar[4].node.(*node.ArgumentList)) @@ -6887,7 +6884,7 @@ yydefault: } case 330: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:4491 + //line php5/php5.y:4488 { yyVAL.node = expr.NewFunctionCall(yyDollar[1].node, yyDollar[2].node.(*node.ArgumentList)) @@ -6898,7 +6895,7 @@ yydefault: } case 331: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4503 + //line php5/php5.y:4500 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -6906,13 +6903,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.StaticToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 332: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4515 + //line php5/php5.y:4512 { yyVAL.node = name.NewName(yyDollar[1].list) @@ -6923,7 +6920,7 @@ yydefault: } case 333: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:4524 + //line php5/php5.y:4521 { yyVAL.node = name.NewRelative(yyDollar[3].list) @@ -6938,7 +6935,7 @@ yydefault: } case 334: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:4537 + //line php5/php5.y:4534 { yyVAL.node = name.NewFullyQualified(yyDollar[2].list) @@ -6952,7 +6949,7 @@ yydefault: } case 335: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4552 + //line php5/php5.y:4549 { yyVAL.node = name.NewName(yyDollar[1].list) @@ -6963,7 +6960,7 @@ yydefault: } case 336: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:4561 + //line php5/php5.y:4558 { yyVAL.node = name.NewRelative(yyDollar[3].list) @@ -6978,7 +6975,7 @@ yydefault: } case 337: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:4574 + //line php5/php5.y:4571 { yyVAL.node = name.NewFullyQualified(yyDollar[2].list) @@ -6992,7 +6989,7 @@ yydefault: } case 338: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4589 + //line php5/php5.y:4586 { yyVAL.node = yyDollar[1].node @@ -7000,7 +6997,7 @@ yydefault: } case 339: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4595 + //line php5/php5.y:4592 { yyVAL.node = yyDollar[1].node @@ -7008,7 +7005,7 @@ yydefault: } case 340: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:4604 + //line php5/php5.y:4601 { yyVAL.node = yyDollar[1].node @@ -7047,7 +7044,7 @@ yydefault: } case 341: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4641 + //line php5/php5.y:4638 { yyVAL.node = yyDollar[1].node @@ -7055,7 +7052,7 @@ yydefault: } case 342: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:4651 + //line php5/php5.y:4648 { yyVAL.list = append(yyDollar[1].list, yyDollar[2].list...) @@ -7063,7 +7060,7 @@ yydefault: } case 343: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:4657 + //line php5/php5.y:4654 { yyVAL.list = []node.Node{} @@ -7071,7 +7068,7 @@ yydefault: } case 344: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:4667 + //line php5/php5.y:4664 { yyVAL.list = yyDollar[2].list @@ -7082,7 +7079,7 @@ yydefault: } case 345: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:4679 + //line php5/php5.y:4676 { yyVAL.node = nil @@ -7090,7 +7087,7 @@ yydefault: } case 346: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:4685 + //line php5/php5.y:4682 { yyVAL.node = expr.NewExit(nil) @@ -7105,7 +7102,7 @@ yydefault: } case 347: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4698 + //line php5/php5.y:4695 { yyVAL.node = expr.NewExit(yyDollar[1].node) @@ -7116,7 +7113,7 @@ yydefault: } case 348: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:4710 + //line php5/php5.y:4707 { yyVAL.list = []node.Node{} @@ -7124,7 +7121,7 @@ yydefault: } case 349: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4716 + //line php5/php5.y:4713 { yyVAL.list = []node.Node{scalar.NewEncapsedStringPart(yyDollar[1].token.Value)} @@ -7132,7 +7129,7 @@ yydefault: } case 350: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4722 + //line php5/php5.y:4719 { yyVAL.list = yyDollar[1].list @@ -7140,7 +7137,7 @@ yydefault: } case 351: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:4731 + //line php5/php5.y:4728 { yyVAL.node = nil @@ -7148,7 +7145,7 @@ yydefault: } case 352: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4737 + //line php5/php5.y:4734 { yyVAL.node = yyDollar[1].node @@ -7156,7 +7153,7 @@ yydefault: } case 353: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4746 + //line php5/php5.y:4743 { yyVAL.node = scalar.NewLnumber(yyDollar[1].token.Value) @@ -7170,7 +7167,7 @@ yydefault: } case 354: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4758 + //line php5/php5.y:4755 { yyVAL.node = scalar.NewDnumber(yyDollar[1].token.Value) @@ -7184,7 +7181,7 @@ yydefault: } case 355: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4770 + //line php5/php5.y:4767 { yyVAL.node = scalar.NewString(yyDollar[1].token.Value) @@ -7198,7 +7195,7 @@ yydefault: } case 356: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4782 + //line php5/php5.y:4779 { yyVAL.node = scalar.NewMagicConstant(yyDollar[1].token.Value) @@ -7206,13 +7203,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.LineToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MagicConstantToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 357: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4794 + //line php5/php5.y:4791 { yyVAL.node = scalar.NewMagicConstant(yyDollar[1].token.Value) @@ -7220,13 +7217,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.FileToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MagicConstantToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 358: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4806 + //line php5/php5.y:4803 { yyVAL.node = scalar.NewMagicConstant(yyDollar[1].token.Value) @@ -7234,13 +7231,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.DirToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MagicConstantToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 359: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4818 + //line php5/php5.y:4815 { yyVAL.node = scalar.NewMagicConstant(yyDollar[1].token.Value) @@ -7248,13 +7245,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.TraitCToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MagicConstantToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 360: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4830 + //line php5/php5.y:4827 { yyVAL.node = scalar.NewMagicConstant(yyDollar[1].token.Value) @@ -7262,13 +7259,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MethodCToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MagicConstantToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 361: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4842 + //line php5/php5.y:4839 { yyVAL.node = scalar.NewMagicConstant(yyDollar[1].token.Value) @@ -7276,13 +7273,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.FuncCToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MagicConstantToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 362: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4854 + //line php5/php5.y:4851 { yyVAL.node = scalar.NewMagicConstant(yyDollar[1].token.Value) @@ -7290,13 +7287,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.NsCToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MagicConstantToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 363: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:4866 + //line php5/php5.y:4863 { encapsed := scalar.NewEncapsedStringPart(yyDollar[2].token.Value) yyVAL.node = scalar.NewHeredoc(yyDollar[1].token.Value, []node.Node{encapsed}) @@ -7312,7 +7309,7 @@ yydefault: } case 364: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:4880 + //line php5/php5.y:4877 { yyVAL.node = scalar.NewHeredoc(yyDollar[1].token.Value, nil) @@ -7326,7 +7323,7 @@ yydefault: } case 365: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:4895 + //line php5/php5.y:4892 { target := node.NewIdentifier(yyDollar[3].token.Value) yyVAL.node = expr.NewClassConstFetch(yyDollar[1].node, target) @@ -7343,7 +7340,7 @@ yydefault: } case 366: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4913 + //line php5/php5.y:4910 { yyVAL.node = yyDollar[1].node @@ -7351,7 +7348,7 @@ yydefault: } case 367: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4922 + //line php5/php5.y:4919 { yyVAL.node = yyDollar[1].node @@ -7359,7 +7356,7 @@ yydefault: } case 368: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4928 + //line php5/php5.y:4925 { yyVAL.node = yyDollar[1].node @@ -7367,7 +7364,7 @@ yydefault: } case 369: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:4934 + //line php5/php5.y:4931 { name := name.NewName(yyDollar[1].list) yyVAL.node = expr.NewConstFetch(name) @@ -7380,7 +7377,7 @@ yydefault: } case 370: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:4945 + //line php5/php5.y:4942 { name := name.NewRelative(yyDollar[3].list) yyVAL.node = expr.NewConstFetch(name) @@ -7390,14 +7387,14 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenNodeListPosition(yyDollar[1].token, yyDollar[3].list)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.NamespaceToken) - addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.NsSeparatorToken) + addMeta(name, yyDollar[1].token.Meta, meta.NamespaceToken) + addMeta(name, yyDollar[2].token.Meta, meta.NsSeparatorToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 371: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:4960 + //line php5/php5.y:4957 { name := name.NewFullyQualified(yyDollar[2].list) yyVAL.node = expr.NewConstFetch(name) @@ -7407,13 +7404,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenNodeListPosition(yyDollar[1].token, yyDollar[2].list)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.NsSeparatorToken) + addMeta(name, yyDollar[1].token.Meta, meta.NsSeparatorToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 372: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:4974 + //line php5/php5.y:4971 { yyVAL.node = expr.NewArray(yyDollar[3].list) @@ -7429,7 +7426,7 @@ yydefault: } case 373: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:4988 + //line php5/php5.y:4985 { yyVAL.node = expr.NewShortArray(yyDollar[2].list) @@ -7444,7 +7441,7 @@ yydefault: } case 374: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5001 + //line php5/php5.y:4998 { yyVAL.node = yyDollar[1].node @@ -7452,7 +7449,7 @@ yydefault: } case 375: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5007 + //line php5/php5.y:5004 { yyVAL.node = scalar.NewMagicConstant(yyDollar[1].token.Value) @@ -7460,13 +7457,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.ClassCToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MagicConstantToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 376: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5019 + //line php5/php5.y:5016 { yyVAL.node = yyDollar[1].node @@ -7474,7 +7471,7 @@ yydefault: } case 377: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:5028 + //line php5/php5.y:5025 { yyVAL.node = expr.NewArrayDimFetch(yyDollar[1].node, yyDollar[3].node) @@ -7489,7 +7486,7 @@ yydefault: } case 378: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5041 + //line php5/php5.y:5038 { yyVAL.node = binary.NewPlus(yyDollar[1].node, yyDollar[3].node) @@ -7503,7 +7500,7 @@ yydefault: } case 379: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5053 + //line php5/php5.y:5050 { yyVAL.node = binary.NewMinus(yyDollar[1].node, yyDollar[3].node) @@ -7517,7 +7514,7 @@ yydefault: } case 380: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5065 + //line php5/php5.y:5062 { yyVAL.node = binary.NewMul(yyDollar[1].node, yyDollar[3].node) @@ -7531,7 +7528,7 @@ yydefault: } case 381: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5077 + //line php5/php5.y:5074 { yyVAL.node = binary.NewPow(yyDollar[1].node, yyDollar[3].node) @@ -7545,7 +7542,7 @@ yydefault: } case 382: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5089 + //line php5/php5.y:5086 { yyVAL.node = binary.NewDiv(yyDollar[1].node, yyDollar[3].node) @@ -7559,7 +7556,7 @@ yydefault: } case 383: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5101 + //line php5/php5.y:5098 { yyVAL.node = binary.NewMod(yyDollar[1].node, yyDollar[3].node) @@ -7573,7 +7570,7 @@ yydefault: } case 384: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:5113 + //line php5/php5.y:5110 { yyVAL.node = expr.NewBooleanNot(yyDollar[2].node) @@ -7587,7 +7584,7 @@ yydefault: } case 385: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:5125 + //line php5/php5.y:5122 { yyVAL.node = expr.NewBitwiseNot(yyDollar[2].node) @@ -7601,7 +7598,7 @@ yydefault: } case 386: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5137 + //line php5/php5.y:5134 { yyVAL.node = binary.NewBitwiseOr(yyDollar[1].node, yyDollar[3].node) @@ -7615,7 +7612,7 @@ yydefault: } case 387: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5149 + //line php5/php5.y:5146 { yyVAL.node = binary.NewBitwiseAnd(yyDollar[1].node, yyDollar[3].node) @@ -7629,7 +7626,7 @@ yydefault: } case 388: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5161 + //line php5/php5.y:5158 { yyVAL.node = binary.NewBitwiseXor(yyDollar[1].node, yyDollar[3].node) @@ -7643,7 +7640,7 @@ yydefault: } case 389: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5173 + //line php5/php5.y:5170 { yyVAL.node = binary.NewShiftLeft(yyDollar[1].node, yyDollar[3].node) @@ -7657,7 +7654,7 @@ yydefault: } case 390: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5185 + //line php5/php5.y:5182 { yyVAL.node = binary.NewShiftRight(yyDollar[1].node, yyDollar[3].node) @@ -7671,7 +7668,7 @@ yydefault: } case 391: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5197 + //line php5/php5.y:5194 { yyVAL.node = binary.NewConcat(yyDollar[1].node, yyDollar[3].node) @@ -7685,7 +7682,7 @@ yydefault: } case 392: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5209 + //line php5/php5.y:5206 { yyVAL.node = binary.NewLogicalXor(yyDollar[1].node, yyDollar[3].node) @@ -7699,7 +7696,7 @@ yydefault: } case 393: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5221 + //line php5/php5.y:5218 { yyVAL.node = binary.NewLogicalAnd(yyDollar[1].node, yyDollar[3].node) @@ -7713,7 +7710,7 @@ yydefault: } case 394: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5233 + //line php5/php5.y:5230 { yyVAL.node = binary.NewLogicalOr(yyDollar[1].node, yyDollar[3].node) @@ -7727,7 +7724,7 @@ yydefault: } case 395: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5245 + //line php5/php5.y:5242 { yyVAL.node = binary.NewBooleanAnd(yyDollar[1].node, yyDollar[3].node) @@ -7741,7 +7738,7 @@ yydefault: } case 396: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5257 + //line php5/php5.y:5254 { yyVAL.node = binary.NewBooleanOr(yyDollar[1].node, yyDollar[3].node) @@ -7755,7 +7752,7 @@ yydefault: } case 397: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5269 + //line php5/php5.y:5266 { yyVAL.node = binary.NewIdentical(yyDollar[1].node, yyDollar[3].node) @@ -7769,7 +7766,7 @@ yydefault: } case 398: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5281 + //line php5/php5.y:5278 { yyVAL.node = binary.NewNotIdentical(yyDollar[1].node, yyDollar[3].node) @@ -7783,7 +7780,7 @@ yydefault: } case 399: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5293 + //line php5/php5.y:5290 { yyVAL.node = binary.NewEqual(yyDollar[1].node, yyDollar[3].node) @@ -7797,7 +7794,7 @@ yydefault: } case 400: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5305 + //line php5/php5.y:5302 { yyVAL.node = binary.NewNotEqual(yyDollar[1].node, yyDollar[3].node) @@ -7811,7 +7808,7 @@ yydefault: } case 401: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5317 + //line php5/php5.y:5314 { yyVAL.node = binary.NewSmaller(yyDollar[1].node, yyDollar[3].node) @@ -7825,7 +7822,7 @@ yydefault: } case 402: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5329 + //line php5/php5.y:5326 { yyVAL.node = binary.NewGreater(yyDollar[1].node, yyDollar[3].node) @@ -7839,7 +7836,7 @@ yydefault: } case 403: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5341 + //line php5/php5.y:5338 { yyVAL.node = binary.NewSmallerOrEqual(yyDollar[1].node, yyDollar[3].node) @@ -7853,7 +7850,7 @@ yydefault: } case 404: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5353 + //line php5/php5.y:5350 { yyVAL.node = binary.NewGreaterOrEqual(yyDollar[1].node, yyDollar[3].node) @@ -7867,7 +7864,7 @@ yydefault: } case 405: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:5365 + //line php5/php5.y:5362 { yyVAL.node = expr.NewTernary(yyDollar[1].node, nil, yyDollar[4].node) @@ -7882,7 +7879,7 @@ yydefault: } case 406: yyDollar = yyS[yypt-5 : yypt+1] - //line php5/php5.y:5378 + //line php5/php5.y:5375 { yyVAL.node = expr.NewTernary(yyDollar[1].node, yyDollar[3].node, yyDollar[5].node) @@ -7897,7 +7894,7 @@ yydefault: } case 407: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:5391 + //line php5/php5.y:5388 { yyVAL.node = expr.NewUnaryPlus(yyDollar[2].node) @@ -7911,7 +7908,7 @@ yydefault: } case 408: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:5403 + //line php5/php5.y:5400 { yyVAL.node = expr.NewUnaryMinus(yyDollar[2].node) @@ -7925,7 +7922,7 @@ yydefault: } case 409: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5415 + //line php5/php5.y:5412 { yyVAL.node = yyDollar[2].node @@ -7937,7 +7934,7 @@ yydefault: } case 410: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5428 + //line php5/php5.y:5425 { yyVAL.node = yyDollar[1].node @@ -7945,7 +7942,7 @@ yydefault: } case 411: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5434 + //line php5/php5.y:5431 { name := name.NewName(yyDollar[1].list) yyVAL.node = expr.NewConstFetch(name) @@ -7958,7 +7955,7 @@ yydefault: } case 412: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5445 + //line php5/php5.y:5442 { name := name.NewRelative(yyDollar[3].list) yyVAL.node = expr.NewConstFetch(name) @@ -7966,14 +7963,14 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewNodePosition(name)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.NamespaceToken) - addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.NsSeparatorToken) + addMeta(name, yyDollar[1].token.Meta, meta.NamespaceToken) + addMeta(name, yyDollar[2].token.Meta, meta.NsSeparatorToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 413: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:5458 + //line php5/php5.y:5455 { name := name.NewFullyQualified(yyDollar[2].list) yyVAL.node = expr.NewConstFetch(name) @@ -7983,13 +7980,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewNodePosition(name)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.NsSeparatorToken) + addMeta(name, yyDollar[1].token.Meta, meta.NsSeparatorToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 414: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5475 + //line php5/php5.y:5472 { name := node.NewIdentifier(yyDollar[1].token.Value) yyVAL.node = expr.NewVariable(name) @@ -7999,13 +7996,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(name, yyDollar[1].token.Meta, meta.StringVarnameToken) + addMeta(name, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 415: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5489 + //line php5/php5.y:5486 { yyVAL.node = yyDollar[1].node @@ -8013,7 +8010,7 @@ yydefault: } case 416: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5495 + //line php5/php5.y:5492 { yyVAL.node = yyDollar[1].node @@ -8021,7 +8018,7 @@ yydefault: } case 417: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5501 + //line php5/php5.y:5498 { yyVAL.node = yyDollar[1].node @@ -8029,7 +8026,7 @@ yydefault: } case 418: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5507 + //line php5/php5.y:5504 { yyVAL.node = scalar.NewEncapsed(yyDollar[2].list) @@ -8043,7 +8040,7 @@ yydefault: } case 419: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5519 + //line php5/php5.y:5516 { yyVAL.node = scalar.NewHeredoc(yyDollar[1].token.Value, yyDollar[2].list) @@ -8057,7 +8054,7 @@ yydefault: } case 420: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5531 + //line php5/php5.y:5528 { yyVAL.node = scalar.NewMagicConstant(yyDollar[1].token.Value) @@ -8065,13 +8062,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.ClassCToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MagicConstantToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 421: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:5546 + //line php5/php5.y:5543 { yyVAL.list = nil @@ -8079,7 +8076,7 @@ yydefault: } case 422: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:5552 + //line php5/php5.y:5549 { yyVAL.list = yyDollar[1].list @@ -8092,19 +8089,19 @@ yydefault: } case 423: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:5566 + //line php5/php5.y:5563 { yyVAL.token = nil } case 424: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5570 + //line php5/php5.y:5567 { yyVAL.token = yyDollar[1].token } case 425: yyDollar = yyS[yypt-5 : yypt+1] - //line php5/php5.y:5577 + //line php5/php5.y:5574 { arrayItem := expr.NewArrayItem(yyDollar[3].node, yyDollar[5].node) yyVAL.list = append(yyDollar[1].list, arrayItem) @@ -8120,7 +8117,7 @@ yydefault: } case 426: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5591 + //line php5/php5.y:5588 { arrayItem := expr.NewArrayItem(nil, yyDollar[3].node) yyVAL.list = append(yyDollar[1].list, arrayItem) @@ -8135,7 +8132,7 @@ yydefault: } case 427: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5604 + //line php5/php5.y:5601 { arrayItem := expr.NewArrayItem(yyDollar[1].node, yyDollar[3].node) yyVAL.list = []node.Node{arrayItem} @@ -8150,7 +8147,7 @@ yydefault: } case 428: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5617 + //line php5/php5.y:5614 { arrayItem := expr.NewArrayItem(nil, yyDollar[1].node) yyVAL.list = []node.Node{arrayItem} @@ -8162,7 +8159,7 @@ yydefault: } case 429: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5630 + //line php5/php5.y:5627 { yyVAL.node = yyDollar[1].node @@ -8170,7 +8167,7 @@ yydefault: } case 430: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5636 + //line php5/php5.y:5633 { yyVAL.node = yyDollar[1].node @@ -8178,23 +8175,31 @@ yydefault: } case 431: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5645 + //line php5/php5.y:5642 { yyVAL.node = yyDollar[2].node + // save comments + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.OpenParenthesisToken) + addMeta(yyVAL.node, yyDollar[3].token.Meta, meta.CloseParenthesisToken) + yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 432: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5651 + //line php5/php5.y:5652 { yyVAL.node = yyDollar[2].node + // save comments + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.OpenParenthesisToken) + addMeta(yyVAL.node, yyDollar[3].token.Meta, meta.CloseParenthesisToken) + yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 433: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5661 + //line php5/php5.y:5666 { yyVAL.node = yyDollar[1].node @@ -8202,7 +8207,7 @@ yydefault: } case 434: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5671 + //line php5/php5.y:5676 { yyVAL.node = yyDollar[1].node @@ -8210,7 +8215,7 @@ yydefault: } case 435: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5680 + //line php5/php5.y:5685 { yyVAL.node = yyDollar[1].node @@ -8218,7 +8223,7 @@ yydefault: } case 436: yyDollar = yyS[yypt-5 : yypt+1] - //line php5/php5.y:5689 + //line php5/php5.y:5694 { yyVAL.node = yyDollar[1].node @@ -8272,7 +8277,7 @@ yydefault: } case 437: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5741 + //line php5/php5.y:5746 { yyVAL.node = yyDollar[1].node @@ -8280,7 +8285,7 @@ yydefault: } case 438: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:5750 + //line php5/php5.y:5755 { yyVAL.list = append(yyDollar[1].list, yyDollar[2].list...) @@ -8288,7 +8293,7 @@ yydefault: } case 439: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:5756 + //line php5/php5.y:5761 { yyVAL.list = []node.Node{} @@ -8296,7 +8301,7 @@ yydefault: } case 440: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5766 + //line php5/php5.y:5771 { if yyDollar[3].list != nil { yyDollar[3].list[0].(*expr.MethodCall).Method = yyDollar[2].list[len(yyDollar[2].list)-1].(*expr.PropertyFetch).Property @@ -8312,7 +8317,7 @@ yydefault: } case 441: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:5783 + //line php5/php5.y:5788 { fetch := expr.NewArrayDimFetch(nil, yyDollar[3].node) yyVAL.list = append(yyDollar[1].list, fetch) @@ -8328,7 +8333,7 @@ yydefault: } case 442: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:5797 + //line php5/php5.y:5802 { fetch := expr.NewArrayDimFetch(nil, yyDollar[3].node) yyVAL.list = []node.Node{yyDollar[1].node, fetch} @@ -8344,7 +8349,7 @@ yydefault: } case 443: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5814 + //line php5/php5.y:5819 { yyVAL.node = expr.NewMethodCall(nil, nil, yyDollar[1].node.(*node.ArgumentList)) @@ -8355,7 +8360,7 @@ yydefault: } case 444: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5826 + //line php5/php5.y:5831 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -8363,7 +8368,7 @@ yydefault: } case 445: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5832 + //line php5/php5.y:5837 { yyVAL.list = yyDollar[1].list @@ -8371,7 +8376,7 @@ yydefault: } case 446: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:5838 + //line php5/php5.y:5843 { yyVAL.list = nil @@ -8379,7 +8384,7 @@ yydefault: } case 447: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5847 + //line php5/php5.y:5852 { yyVAL.node = yyDollar[1].node @@ -8387,7 +8392,7 @@ yydefault: } case 448: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:5853 + //line php5/php5.y:5858 { yyDollar[1].simpleIndirectReference.last.SetVarName(yyDollar[2].node) @@ -8401,7 +8406,7 @@ yydefault: } case 449: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5868 + //line php5/php5.y:5873 { yyVAL.node = expr.NewStaticPropertyFetch(yyDollar[1].node, yyDollar[3].node) @@ -8415,7 +8420,7 @@ yydefault: } case 450: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:5880 + //line php5/php5.y:5885 { yyVAL.node = expr.NewStaticPropertyFetch(yyDollar[1].node, yyDollar[3].node) @@ -8429,7 +8434,7 @@ yydefault: } case 451: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5895 + //line php5/php5.y:5900 { yyVAL.node = yyDollar[1].node @@ -8437,7 +8442,7 @@ yydefault: } case 452: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:5904 + //line php5/php5.y:5909 { yyVAL.node = expr.NewArrayDimFetch(yyDollar[1].node, yyDollar[3].node) @@ -8452,7 +8457,7 @@ yydefault: } case 453: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:5917 + //line php5/php5.y:5922 { yyVAL.node = expr.NewArrayDimFetch(yyDollar[1].node, yyDollar[3].node) @@ -8467,7 +8472,7 @@ yydefault: } case 454: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5933 + //line php5/php5.y:5938 { yyVAL.node = yyDollar[1].node @@ -8475,7 +8480,7 @@ yydefault: } case 455: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5939 + //line php5/php5.y:5944 { yyVAL.node = yyDollar[1].node @@ -8483,7 +8488,7 @@ yydefault: } case 456: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5945 + //line php5/php5.y:5950 { yyVAL.node = yyDollar[1].node @@ -8491,7 +8496,7 @@ yydefault: } case 457: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5955 + //line php5/php5.y:5960 { yyVAL.node = yyDollar[1].node @@ -8499,7 +8504,7 @@ yydefault: } case 458: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:5961 + //line php5/php5.y:5966 { yyDollar[1].simpleIndirectReference.last.SetVarName(yyDollar[2].node) @@ -8513,7 +8518,7 @@ yydefault: } case 459: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:5973 + //line php5/php5.y:5978 { yyVAL.node = yyDollar[1].node @@ -8521,7 +8526,7 @@ yydefault: } case 460: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:5982 + //line php5/php5.y:5987 { yyVAL.node = expr.NewArrayDimFetch(yyDollar[1].node, yyDollar[3].node) @@ -8536,7 +8541,7 @@ yydefault: } case 461: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:5995 + //line php5/php5.y:6000 { yyVAL.node = expr.NewArrayDimFetch(yyDollar[1].node, yyDollar[3].node) @@ -8551,7 +8556,7 @@ yydefault: } case 462: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6008 + //line php5/php5.y:6013 { yyVAL.node = yyDollar[1].node @@ -8559,7 +8564,7 @@ yydefault: } case 463: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6018 + //line php5/php5.y:6023 { name := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) yyVAL.node = expr.NewVariable(name) @@ -8575,7 +8580,7 @@ yydefault: } case 464: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:6032 + //line php5/php5.y:6037 { yyVAL.node = expr.NewVariable(yyDollar[3].node) @@ -8591,7 +8596,7 @@ yydefault: } case 465: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:6049 + //line php5/php5.y:6054 { yyVAL.node = nil @@ -8599,7 +8604,7 @@ yydefault: } case 466: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6055 + //line php5/php5.y:6060 { yyVAL.node = yyDollar[1].node @@ -8607,7 +8612,7 @@ yydefault: } case 467: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6065 + //line php5/php5.y:6070 { yyVAL.list = yyDollar[1].list @@ -8615,7 +8620,7 @@ yydefault: } case 468: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6071 + //line php5/php5.y:6076 { fetch := expr.NewPropertyFetch(nil, yyDollar[1].node) yyVAL.list = []node.Node{fetch} @@ -8627,7 +8632,7 @@ yydefault: } case 469: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:6084 + //line php5/php5.y:6089 { fetch := expr.NewArrayDimFetch(nil, yyDollar[3].node) yyVAL.list = append(yyDollar[1].list, fetch) @@ -8643,7 +8648,7 @@ yydefault: } case 470: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:6098 + //line php5/php5.y:6103 { fetch := expr.NewArrayDimFetch(nil, yyDollar[3].node) yyVAL.list = append(yyDollar[1].list, fetch) @@ -8659,7 +8664,7 @@ yydefault: } case 471: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6112 + //line php5/php5.y:6117 { fetch := expr.NewPropertyFetch(nil, yyDollar[1].node) yyVAL.list = []node.Node{fetch} @@ -8671,7 +8676,7 @@ yydefault: } case 472: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6125 + //line php5/php5.y:6130 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -8679,13 +8684,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.StringToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 473: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:6137 + //line php5/php5.y:6142 { yyVAL.node = yyDollar[2].node @@ -8700,7 +8705,7 @@ yydefault: } case 474: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6153 + //line php5/php5.y:6158 { n := expr.NewVariable(nil) yyVAL.simpleIndirectReference = simpleIndirectReference{[]*expr.Variable{n}, n} @@ -8715,7 +8720,7 @@ yydefault: } case 475: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:6166 + //line php5/php5.y:6171 { n := expr.NewVariable(nil) @@ -8734,7 +8739,7 @@ yydefault: } case 476: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:6186 + //line php5/php5.y:6191 { if len(yyDollar[1].list) == 0 { yyDollar[1].list = []node.Node{expr.NewArrayItem(nil, nil)} @@ -8743,13 +8748,13 @@ yydefault: yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 477: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6199 + //line php5/php5.y:6204 { if yyDollar[1].node.(*expr.ArrayItem).Key == nil && yyDollar[1].node.(*expr.ArrayItem).Val == nil { yyVAL.list = []node.Node{} @@ -8761,7 +8766,7 @@ yydefault: } case 478: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6213 + //line php5/php5.y:6218 { yyVAL.node = expr.NewArrayItem(nil, yyDollar[1].node) @@ -8772,7 +8777,7 @@ yydefault: } case 479: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:6222 + //line php5/php5.y:6227 { item := expr.NewList(yyDollar[3].list) yyVAL.node = expr.NewArrayItem(nil, item) @@ -8790,7 +8795,7 @@ yydefault: } case 480: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:6238 + //line php5/php5.y:6243 { yyVAL.node = expr.NewArrayItem(nil, nil) @@ -8798,7 +8803,7 @@ yydefault: } case 481: yyDollar = yyS[yypt-0 : yypt+1] - //line php5/php5.y:6248 + //line php5/php5.y:6253 { yyVAL.list = []node.Node{} @@ -8806,7 +8811,7 @@ yydefault: } case 482: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:6254 + //line php5/php5.y:6259 { yyVAL.list = yyDollar[1].list @@ -8823,7 +8828,7 @@ yydefault: } case 483: yyDollar = yyS[yypt-5 : yypt+1] - //line php5/php5.y:6272 + //line php5/php5.y:6277 { arrayItem := expr.NewArrayItem(yyDollar[3].node, yyDollar[5].node) yyVAL.list = append(yyDollar[1].list, arrayItem) @@ -8839,7 +8844,7 @@ yydefault: } case 484: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:6286 + //line php5/php5.y:6291 { arrayItem := expr.NewArrayItem(nil, yyDollar[3].node) yyVAL.list = append(yyDollar[1].list, arrayItem) @@ -8854,7 +8859,7 @@ yydefault: } case 485: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:6299 + //line php5/php5.y:6304 { arrayItem := expr.NewArrayItem(yyDollar[1].node, yyDollar[3].node) yyVAL.list = []node.Node{arrayItem} @@ -8869,7 +8874,7 @@ yydefault: } case 486: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6312 + //line php5/php5.y:6317 { arrayItem := expr.NewArrayItem(nil, yyDollar[1].node) yyVAL.list = []node.Node{arrayItem} @@ -8881,7 +8886,7 @@ yydefault: } case 487: yyDollar = yyS[yypt-6 : yypt+1] - //line php5/php5.y:6322 + //line php5/php5.y:6327 { reference := expr.NewReference(yyDollar[6].node) arrayItem := expr.NewArrayItem(yyDollar[3].node, reference) @@ -8900,7 +8905,7 @@ yydefault: } case 488: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:6339 + //line php5/php5.y:6344 { reference := expr.NewReference(yyDollar[4].node) arrayItem := expr.NewArrayItem(nil, reference) @@ -8918,7 +8923,7 @@ yydefault: } case 489: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:6355 + //line php5/php5.y:6360 { reference := expr.NewReference(yyDollar[4].node) arrayItem := expr.NewArrayItem(yyDollar[1].node, reference) @@ -8936,7 +8941,7 @@ yydefault: } case 490: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:6371 + //line php5/php5.y:6376 { reference := expr.NewReference(yyDollar[2].node) arrayItem := expr.NewArrayItem(nil, reference) @@ -8953,7 +8958,7 @@ yydefault: } case 491: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:6389 + //line php5/php5.y:6394 { yyVAL.list = append(yyDollar[1].list, yyDollar[2].node) @@ -8961,7 +8966,7 @@ yydefault: } case 492: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:6395 + //line php5/php5.y:6400 { encapsed := scalar.NewEncapsedStringPart(yyDollar[2].token.Value) yyVAL.list = append(yyDollar[1].list, encapsed) @@ -8976,7 +8981,7 @@ yydefault: } case 493: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6408 + //line php5/php5.y:6413 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -8984,7 +8989,7 @@ yydefault: } case 494: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:6414 + //line php5/php5.y:6419 { encapsed := scalar.NewEncapsedStringPart(yyDollar[1].token.Value) yyVAL.list = []node.Node{encapsed, yyDollar[2].node} @@ -8999,7 +9004,7 @@ yydefault: } case 495: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6430 + //line php5/php5.y:6435 { name := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) yyVAL.node = expr.NewVariable(name) @@ -9015,7 +9020,7 @@ yydefault: } case 496: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:6444 + //line php5/php5.y:6449 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -9035,7 +9040,7 @@ yydefault: } case 497: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:6462 + //line php5/php5.y:6467 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -9051,13 +9056,13 @@ yydefault: // save comments addMeta(variable, yyDollar[1].token.Meta, meta.VariableToken) addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.ObjectOperatorToken) - addMeta(fetch, yyDollar[3].token.Meta, meta.StringToken) + addMeta(fetch, yyDollar[3].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 498: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:6482 + //line php5/php5.y:6487 { yyVAL.node = expr.NewVariable(yyDollar[2].node) @@ -9072,7 +9077,7 @@ yydefault: } case 499: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:6495 + //line php5/php5.y:6500 { name := node.NewIdentifier(yyDollar[2].token.Value) yyVAL.node = expr.NewVariable(name) @@ -9083,14 +9088,14 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.DollarOpenCurlyBracesToken) - addMeta(name, yyDollar[2].token.Meta, meta.StringVarnameToken) + addMeta(name, yyDollar[2].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[3].token.Meta, meta.CloseCurlyBracesToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 500: yyDollar = yyS[yypt-6 : yypt+1] - //line php5/php5.y:6511 + //line php5/php5.y:6516 { identifier := node.NewIdentifier(yyDollar[2].token.Value) variable := expr.NewVariable(identifier) @@ -9112,7 +9117,7 @@ yydefault: } case 501: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:6531 + //line php5/php5.y:6536 { yyVAL.node = yyDollar[2].node @@ -9120,7 +9125,7 @@ yydefault: } case 502: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6540 + //line php5/php5.y:6545 { yyVAL.node = scalar.NewString(yyDollar[1].token.Value) @@ -9134,7 +9139,7 @@ yydefault: } case 503: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6552 + //line php5/php5.y:6557 { // TODO: add option to handle 64 bit integer if _, err := strconv.Atoi(yyDollar[1].token.Value); err == nil { @@ -9153,7 +9158,7 @@ yydefault: } case 504: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6569 + //line php5/php5.y:6574 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) yyVAL.node = expr.NewVariable(identifier) @@ -9169,7 +9174,7 @@ yydefault: } case 505: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:6586 + //line php5/php5.y:6591 { yyVAL.node = expr.NewIsset(yyDollar[3].list) @@ -9185,7 +9190,7 @@ yydefault: } case 506: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:6600 + //line php5/php5.y:6605 { yyVAL.node = expr.NewEmpty(yyDollar[3].node) @@ -9201,7 +9206,7 @@ yydefault: } case 507: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:6614 + //line php5/php5.y:6619 { yyVAL.node = expr.NewEmpty(yyDollar[3].node) @@ -9217,7 +9222,7 @@ yydefault: } case 508: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:6628 + //line php5/php5.y:6633 { yyVAL.node = expr.NewInclude(yyDollar[2].node) @@ -9231,7 +9236,7 @@ yydefault: } case 509: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:6640 + //line php5/php5.y:6645 { yyVAL.node = expr.NewIncludeOnce(yyDollar[2].node) @@ -9245,7 +9250,7 @@ yydefault: } case 510: yyDollar = yyS[yypt-4 : yypt+1] - //line php5/php5.y:6652 + //line php5/php5.y:6657 { yyVAL.node = expr.NewEval(yyDollar[3].node) @@ -9261,7 +9266,7 @@ yydefault: } case 511: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:6666 + //line php5/php5.y:6671 { yyVAL.node = expr.NewRequire(yyDollar[2].node) @@ -9275,7 +9280,7 @@ yydefault: } case 512: yyDollar = yyS[yypt-2 : yypt+1] - //line php5/php5.y:6678 + //line php5/php5.y:6683 { yyVAL.node = expr.NewRequireOnce(yyDollar[2].node) @@ -9289,7 +9294,7 @@ yydefault: } case 513: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6693 + //line php5/php5.y:6698 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -9297,18 +9302,18 @@ yydefault: } case 514: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:6699 + //line php5/php5.y:6704 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 515: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6711 + //line php5/php5.y:6716 { yyVAL.node = yyDollar[1].node @@ -9316,7 +9321,7 @@ yydefault: } case 516: yyDollar = yyS[yypt-1 : yypt+1] - //line php5/php5.y:6717 + //line php5/php5.y:6722 { yyVAL.node = yyDollar[1].node @@ -9324,7 +9329,7 @@ yydefault: } case 517: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:6726 + //line php5/php5.y:6731 { target := node.NewIdentifier(yyDollar[3].token.Value) yyVAL.node = expr.NewClassConstFetch(yyDollar[1].node, target) @@ -9335,12 +9340,13 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.PaamayimNekudotayimToken) + addMeta(target, yyDollar[3].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 518: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:6740 + //line php5/php5.y:6746 { target := node.NewIdentifier(yyDollar[3].token.Value) yyVAL.node = expr.NewClassConstFetch(yyDollar[1].node, target) @@ -9351,12 +9357,13 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.PaamayimNekudotayimToken) + addMeta(target, yyDollar[3].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 519: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:6757 + //line php5/php5.y:6764 { target := node.NewIdentifier(yyDollar[3].token.Value) yyVAL.node = expr.NewClassConstFetch(yyDollar[1].node, target) @@ -9367,12 +9374,13 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.PaamayimNekudotayimToken) + addMeta(target, yyDollar[3].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 520: yyDollar = yyS[yypt-3 : yypt+1] - //line php5/php5.y:6774 + //line php5/php5.y:6782 { target := node.NewIdentifier(yyDollar[3].token.Value) yyVAL.node = expr.NewClassConstFetch(yyDollar[1].node, target) @@ -9383,6 +9391,7 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.PaamayimNekudotayimToken) + addMeta(target, yyDollar[3].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } diff --git a/php5/php5.y b/php5/php5.y index fa5bc7e..d5c7c38 100644 --- a/php5/php5.y +++ b/php5/php5.y @@ -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) } @@ -5643,13 +5640,21 @@ expr: parenthesis_expr: '(' expr ')' { - $$ = $2 + $$ = $2 + + // save comments + addMeta($$, $1.Meta, meta.OpenParenthesisToken) + addMeta($$, $3.Meta, meta.CloseParenthesisToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } | '(' yield_expr ')' { - $$ = $2 + $$ = $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) } diff --git a/php5/php5_test.go b/php5/php5_test.go index 4a6d106..6e47f41 100644 --- a/php5/php5_test.go +++ b/php5/php5_test.go @@ -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{ diff --git a/php7/php7.go b/php7/php7.go index 5109b8c..0c348de 100644 --- a/php7/php7.go +++ b/php7/php7.go @@ -18,9 +18,11 @@ import ( "github.com/z7zmey/php-parser/node/scalar" "github.com/z7zmey/php-parser/node/stmt" "github.com/z7zmey/php-parser/scanner" + + "github.com/davecgh/go-spew/spew" ) -//line php7/php7.y:22 +//line php7/php7.y:24 type yySymType struct { yys int node node.Node @@ -346,7 +348,7 @@ const yyEofCode = 1 const yyErrCode = 2 const yyInitialStackSize = 16 -//line php7/php7.y:5345 +//line php7/php7.y:5343 //line yacctab:1 var yyExca = [...]int{ @@ -2114,7 +2116,7 @@ yydefault: case 1: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:300 + //line php7/php7.y:302 { yylex.(*Parser).rootNode = node.NewRoot(yyDollar[1].list) @@ -2122,466 +2124,470 @@ yydefault: yylex.(*Parser).rootNode.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition(yyDollar[1].list)) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) + + if yylex.(*Parser).currentToken.Value == "\xff" { + addMeta(yylex.(*Parser).rootNode, yylex.(*Parser).currentToken.Meta, meta.NodeEnd) + } } case 2: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:311 + //line php7/php7.y:317 { yyVAL.token = yyDollar[1].token } case 3: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:311 + //line php7/php7.y:317 { yyVAL.token = yyDollar[1].token } case 4: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:311 + //line php7/php7.y:317 { yyVAL.token = yyDollar[1].token } case 5: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:311 + //line php7/php7.y:317 { yyVAL.token = yyDollar[1].token } case 6: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:311 + //line php7/php7.y:317 { yyVAL.token = yyDollar[1].token } case 7: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:311 + //line php7/php7.y:317 { yyVAL.token = yyDollar[1].token } case 8: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:311 + //line php7/php7.y:317 { yyVAL.token = yyDollar[1].token } case 9: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:311 + //line php7/php7.y:317 { yyVAL.token = yyDollar[1].token } case 10: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:312 + //line php7/php7.y:318 { yyVAL.token = yyDollar[1].token } case 11: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:312 + //line php7/php7.y:318 { yyVAL.token = yyDollar[1].token } case 12: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:312 + //line php7/php7.y:318 { yyVAL.token = yyDollar[1].token } case 13: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:312 + //line php7/php7.y:318 { yyVAL.token = yyDollar[1].token } case 14: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:312 + //line php7/php7.y:318 { yyVAL.token = yyDollar[1].token } case 15: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:312 + //line php7/php7.y:318 { yyVAL.token = yyDollar[1].token } case 16: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:312 + //line php7/php7.y:318 { yyVAL.token = yyDollar[1].token } case 17: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:312 + //line php7/php7.y:318 { yyVAL.token = yyDollar[1].token } case 18: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:312 + //line php7/php7.y:318 { yyVAL.token = yyDollar[1].token } case 19: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:312 + //line php7/php7.y:318 { yyVAL.token = yyDollar[1].token } case 20: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:312 + //line php7/php7.y:318 { yyVAL.token = yyDollar[1].token } case 21: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:312 + //line php7/php7.y:318 { yyVAL.token = yyDollar[1].token } case 22: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:313 + //line php7/php7.y:319 { yyVAL.token = yyDollar[1].token } case 23: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:313 + //line php7/php7.y:319 { yyVAL.token = yyDollar[1].token } case 24: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:313 + //line php7/php7.y:319 { yyVAL.token = yyDollar[1].token } case 25: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:313 + //line php7/php7.y:319 { yyVAL.token = yyDollar[1].token } case 26: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:313 + //line php7/php7.y:319 { yyVAL.token = yyDollar[1].token } case 27: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:313 + //line php7/php7.y:319 { yyVAL.token = yyDollar[1].token } case 28: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:313 + //line php7/php7.y:319 { yyVAL.token = yyDollar[1].token } case 29: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:313 + //line php7/php7.y:319 { yyVAL.token = yyDollar[1].token } case 30: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:313 + //line php7/php7.y:319 { yyVAL.token = yyDollar[1].token } case 31: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:313 + //line php7/php7.y:319 { yyVAL.token = yyDollar[1].token } case 32: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:314 + //line php7/php7.y:320 { yyVAL.token = yyDollar[1].token } case 33: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:314 + //line php7/php7.y:320 { yyVAL.token = yyDollar[1].token } case 34: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:314 + //line php7/php7.y:320 { yyVAL.token = yyDollar[1].token } case 35: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:314 + //line php7/php7.y:320 { yyVAL.token = yyDollar[1].token } case 36: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:314 + //line php7/php7.y:320 { yyVAL.token = yyDollar[1].token } case 37: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:314 + //line php7/php7.y:320 { yyVAL.token = yyDollar[1].token } case 38: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:314 + //line php7/php7.y:320 { yyVAL.token = yyDollar[1].token } case 39: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:314 + //line php7/php7.y:320 { yyVAL.token = yyDollar[1].token } case 40: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:314 + //line php7/php7.y:320 { yyVAL.token = yyDollar[1].token } case 41: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:314 + //line php7/php7.y:320 { yyVAL.token = yyDollar[1].token } case 42: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:315 + //line php7/php7.y:321 { yyVAL.token = yyDollar[1].token } case 43: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:315 + //line php7/php7.y:321 { yyVAL.token = yyDollar[1].token } case 44: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:315 + //line php7/php7.y:321 { yyVAL.token = yyDollar[1].token } case 45: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:315 + //line php7/php7.y:321 { yyVAL.token = yyDollar[1].token } case 46: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:315 + //line php7/php7.y:321 { yyVAL.token = yyDollar[1].token } case 47: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:315 + //line php7/php7.y:321 { yyVAL.token = yyDollar[1].token } case 48: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:315 + //line php7/php7.y:321 { yyVAL.token = yyDollar[1].token } case 49: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:315 + //line php7/php7.y:321 { yyVAL.token = yyDollar[1].token } case 50: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:315 + //line php7/php7.y:321 { yyVAL.token = yyDollar[1].token } case 51: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:315 + //line php7/php7.y:321 { yyVAL.token = yyDollar[1].token } case 52: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:315 + //line php7/php7.y:321 { yyVAL.token = yyDollar[1].token } case 53: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:316 + //line php7/php7.y:322 { yyVAL.token = yyDollar[1].token } case 54: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:316 + //line php7/php7.y:322 { yyVAL.token = yyDollar[1].token } case 55: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:316 + //line php7/php7.y:322 { yyVAL.token = yyDollar[1].token } case 56: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:316 + //line php7/php7.y:322 { yyVAL.token = yyDollar[1].token } case 57: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:316 + //line php7/php7.y:322 { yyVAL.token = yyDollar[1].token } case 58: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:316 + //line php7/php7.y:322 { yyVAL.token = yyDollar[1].token } case 59: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:316 + //line php7/php7.y:322 { yyVAL.token = yyDollar[1].token } case 60: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:316 + //line php7/php7.y:322 { yyVAL.token = yyDollar[1].token } case 61: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:317 + //line php7/php7.y:323 { yyVAL.token = yyDollar[1].token } case 62: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:317 + //line php7/php7.y:323 { yyVAL.token = yyDollar[1].token } case 63: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:317 + //line php7/php7.y:323 { yyVAL.token = yyDollar[1].token } case 64: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:317 + //line php7/php7.y:323 { yyVAL.token = yyDollar[1].token } case 65: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:317 + //line php7/php7.y:323 { yyVAL.token = yyDollar[1].token } case 66: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:317 + //line php7/php7.y:323 { yyVAL.token = yyDollar[1].token } case 67: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:317 + //line php7/php7.y:323 { yyVAL.token = yyDollar[1].token } case 68: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:317 + //line php7/php7.y:323 { yyVAL.token = yyDollar[1].token } case 69: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:322 + //line php7/php7.y:328 { yyVAL.token = yyDollar[1].token } case 70: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:325 + //line php7/php7.y:331 { yyVAL.token = yyDollar[1].token } case 71: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:325 + //line php7/php7.y:331 { yyVAL.token = yyDollar[1].token } case 72: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:325 + //line php7/php7.y:331 { yyVAL.token = yyDollar[1].token } case 73: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:325 + //line php7/php7.y:331 { yyVAL.token = yyDollar[1].token } case 74: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:325 + //line php7/php7.y:331 { yyVAL.token = yyDollar[1].token } case 75: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:325 + //line php7/php7.y:331 { yyVAL.token = yyDollar[1].token } case 76: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:330 + //line php7/php7.y:336 { yyVAL.token = yyDollar[1].token } case 77: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:334 + //line php7/php7.y:340 { yyVAL.token = yyDollar[1].token } case 78: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:341 + //line php7/php7.y:347 { if yyDollar[2].node != nil { yyVAL.list = append(yyDollar[1].list, yyDollar[2].node) @@ -2591,7 +2597,7 @@ yydefault: } case 79: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:349 + //line php7/php7.y:355 { yyVAL.list = []node.Node{} @@ -2599,7 +2605,7 @@ yydefault: } case 80: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:358 + //line php7/php7.y:364 { namePart := name.NewNamePart(yyDollar[1].token.Value) yyVAL.list = []node.Node{namePart} @@ -2614,7 +2620,7 @@ yydefault: } case 81: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:371 + //line php7/php7.y:377 { namePart := name.NewNamePart(yyDollar[3].token.Value) yyVAL.list = append(yyDollar[1].list, namePart) @@ -2630,7 +2636,7 @@ yydefault: } case 82: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:388 + //line php7/php7.y:394 { yyVAL.node = name.NewName(yyDollar[1].list) @@ -2641,7 +2647,7 @@ yydefault: } case 83: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:397 + //line php7/php7.y:403 { yyVAL.node = name.NewRelative(yyDollar[3].list) @@ -2656,7 +2662,7 @@ yydefault: } case 84: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:410 + //line php7/php7.y:416 { yyVAL.node = name.NewFullyQualified(yyDollar[2].list) @@ -2670,7 +2676,7 @@ yydefault: } case 85: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:425 + //line php7/php7.y:431 { // error yyVAL.node = nil @@ -2679,7 +2685,7 @@ yydefault: } case 86: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:432 + //line php7/php7.y:438 { yyVAL.node = yyDollar[1].node @@ -2687,7 +2693,7 @@ yydefault: } case 87: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:438 + //line php7/php7.y:444 { yyVAL.node = yyDollar[1].node @@ -2695,7 +2701,7 @@ yydefault: } case 88: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:444 + //line php7/php7.y:450 { yyVAL.node = yyDollar[1].node @@ -2703,7 +2709,7 @@ yydefault: } case 89: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:450 + //line php7/php7.y:456 { yyVAL.node = yyDollar[1].node @@ -2711,7 +2717,7 @@ yydefault: } case 90: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:456 + //line php7/php7.y:462 { yyVAL.node = yyDollar[1].node @@ -2719,7 +2725,7 @@ yydefault: } case 91: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:462 + //line php7/php7.y:468 { yyVAL.node = stmt.NewHaltCompiler() @@ -2736,7 +2742,7 @@ yydefault: } case 92: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:477 + //line php7/php7.y:483 { name := name.NewName(yyDollar[2].list) yyVAL.node = stmt.NewNamespace(name, nil) @@ -2753,7 +2759,7 @@ yydefault: } case 93: yyDollar = yyS[yypt-5 : yypt+1] - //line php7/php7.y:492 + //line php7/php7.y:498 { name := name.NewName(yyDollar[2].list) yyVAL.node = stmt.NewNamespace(name, yyDollar[4].list) @@ -2771,7 +2777,7 @@ yydefault: } case 94: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:508 + //line php7/php7.y:514 { yyVAL.node = stmt.NewNamespace(nil, yyDollar[3].list) @@ -2787,7 +2793,7 @@ yydefault: } case 95: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:522 + //line php7/php7.y:528 { yyVAL.node = yyDollar[2].node @@ -2802,7 +2808,7 @@ yydefault: } case 96: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:535 + //line php7/php7.y:541 { yyVAL.node = yyDollar[3].node.(*stmt.GroupUse).SetUseType(yyDollar[2].node) @@ -2817,7 +2823,7 @@ yydefault: } case 97: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:548 + //line php7/php7.y:554 { yyVAL.node = stmt.NewUseList(nil, yyDollar[2].list) @@ -2832,7 +2838,7 @@ yydefault: } case 98: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:561 + //line php7/php7.y:567 { yyVAL.node = stmt.NewUseList(yyDollar[2].node, yyDollar[3].list) @@ -2847,7 +2853,7 @@ yydefault: } case 99: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:574 + //line php7/php7.y:580 { yyVAL.node = stmt.NewConstList(yyDollar[2].list) @@ -2862,7 +2868,7 @@ yydefault: } case 100: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:590 + //line php7/php7.y:596 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -2870,13 +2876,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.FunctionToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 101: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:602 + //line php7/php7.y:608 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -2884,13 +2890,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.ConstToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 102: yyDollar = yyS[yypt-6 : yypt+1] - //line php7/php7.y:617 + //line php7/php7.y:623 { name := name.NewName(yyDollar[1].list) yyVAL.node = stmt.NewGroupUse(nil, name, yyDollar[4].list) @@ -2911,7 +2917,7 @@ yydefault: } case 103: yyDollar = yyS[yypt-7 : yypt+1] - //line php7/php7.y:636 + //line php7/php7.y:642 { name := name.NewName(yyDollar[2].list) yyVAL.node = stmt.NewGroupUse(nil, name, yyDollar[5].list) @@ -2933,7 +2939,7 @@ yydefault: } case 104: yyDollar = yyS[yypt-6 : yypt+1] - //line php7/php7.y:659 + //line php7/php7.y:665 { name := name.NewName(yyDollar[1].list) yyVAL.node = stmt.NewGroupUse(nil, name, yyDollar[4].list) @@ -2954,7 +2960,7 @@ yydefault: } case 105: yyDollar = yyS[yypt-7 : yypt+1] - //line php7/php7.y:678 + //line php7/php7.y:684 { name := name.NewName(yyDollar[2].list) yyVAL.node = stmt.NewGroupUse(nil, name, yyDollar[5].list) @@ -2976,30 +2982,30 @@ yydefault: } case 106: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:701 + //line php7/php7.y:707 { yyVAL.token = nil } case 107: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:705 + //line php7/php7.y:711 { yyVAL.token = yyDollar[1].token } case 108: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:712 + //line php7/php7.y:718 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 109: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:721 + //line php7/php7.y:727 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -3007,18 +3013,18 @@ yydefault: } case 110: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:730 + //line php7/php7.y:736 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 111: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:739 + //line php7/php7.y:745 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -3026,18 +3032,18 @@ yydefault: } case 112: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:748 + //line php7/php7.y:754 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 113: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:757 + //line php7/php7.y:763 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -3045,7 +3051,7 @@ yydefault: } case 114: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:766 + //line php7/php7.y:772 { yyVAL.node = yyDollar[1].node @@ -3053,7 +3059,7 @@ yydefault: } case 115: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:772 + //line php7/php7.y:778 { yyVAL.node = yyDollar[2].node.(*stmt.Use).SetUseType(yyDollar[1].node) @@ -3061,7 +3067,7 @@ yydefault: } case 116: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:781 + //line php7/php7.y:787 { name := name.NewName(yyDollar[1].list) yyVAL.node = stmt.NewUse(nil, name, nil) @@ -3074,7 +3080,7 @@ yydefault: } case 117: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:792 + //line php7/php7.y:798 { name := name.NewName(yyDollar[1].list) alias := node.NewIdentifier(yyDollar[3].token.Value) @@ -3087,13 +3093,13 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.AsToken) - addMeta(alias, yyDollar[3].token.Meta, meta.StringToken) + addMeta(alias, yyDollar[3].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 118: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:812 + //line php7/php7.y:818 { yyVAL.node = yyDollar[1].node @@ -3101,7 +3107,7 @@ yydefault: } case 119: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:818 + //line php7/php7.y:824 { yyVAL.node = yyDollar[2].node @@ -3112,18 +3118,18 @@ yydefault: } case 120: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:830 + //line php7/php7.y:836 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 121: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:839 + //line php7/php7.y:845 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -3131,7 +3137,7 @@ yydefault: } case 122: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:848 + //line php7/php7.y:854 { if yyDollar[2].node != nil { yyVAL.list = append(yyDollar[1].list, yyDollar[2].node) @@ -3141,7 +3147,7 @@ yydefault: } case 123: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:856 + //line php7/php7.y:862 { yyVAL.list = []node.Node{} @@ -3149,7 +3155,7 @@ yydefault: } case 124: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:865 + //line php7/php7.y:871 { // error yyVAL.node = nil @@ -3158,7 +3164,7 @@ yydefault: } case 125: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:872 + //line php7/php7.y:878 { yyVAL.node = yyDollar[1].node @@ -3166,7 +3172,7 @@ yydefault: } case 126: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:878 + //line php7/php7.y:884 { yyVAL.node = yyDollar[1].node @@ -3174,7 +3180,7 @@ yydefault: } case 127: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:884 + //line php7/php7.y:890 { yyVAL.node = yyDollar[1].node @@ -3182,7 +3188,7 @@ yydefault: } case 128: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:890 + //line php7/php7.y:896 { yyVAL.node = yyDollar[1].node @@ -3190,7 +3196,7 @@ yydefault: } case 129: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:896 + //line php7/php7.y:902 { yyVAL.node = yyDollar[1].node @@ -3198,7 +3204,7 @@ yydefault: } case 130: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:902 + //line php7/php7.y:908 { yyVAL.node = stmt.NewHaltCompiler() @@ -3215,7 +3221,7 @@ yydefault: } case 131: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:919 + //line php7/php7.y:925 { yyVAL.node = stmt.NewStmtList(yyDollar[2].list) @@ -3230,7 +3236,7 @@ yydefault: } case 132: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:932 + //line php7/php7.y:938 { yyVAL.node = yyDollar[1].node @@ -3238,7 +3244,7 @@ yydefault: } case 133: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:938 + //line php7/php7.y:944 { yyVAL.node = yyDollar[1].node @@ -3246,7 +3252,7 @@ yydefault: } case 134: yyDollar = yyS[yypt-5 : yypt+1] - //line php7/php7.y:944 + //line php7/php7.y:950 { switch n := yyDollar[5].node.(type) { case *stmt.While: @@ -3269,7 +3275,7 @@ yydefault: } case 135: yyDollar = yyS[yypt-7 : yypt+1] - //line php7/php7.y:965 + //line php7/php7.y:971 { yyVAL.node = stmt.NewDo(yyDollar[2].node, yyDollar[5].node) @@ -3287,7 +3293,7 @@ yydefault: } case 136: yyDollar = yyS[yypt-9 : yypt+1] - //line php7/php7.y:981 + //line php7/php7.y:987 { switch n := yyDollar[9].node.(type) { case *stmt.For: @@ -3316,7 +3322,7 @@ yydefault: } case 137: yyDollar = yyS[yypt-5 : yypt+1] - //line php7/php7.y:1008 + //line php7/php7.y:1014 { switch n := yyDollar[5].node.(type) { case *stmt.Switch: @@ -3341,7 +3347,7 @@ yydefault: } case 138: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:1031 + //line php7/php7.y:1037 { yyVAL.node = stmt.NewBreak(yyDollar[2].node) @@ -3356,7 +3362,7 @@ yydefault: } case 139: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:1044 + //line php7/php7.y:1050 { yyVAL.node = stmt.NewContinue(yyDollar[2].node) @@ -3371,7 +3377,7 @@ yydefault: } case 140: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:1057 + //line php7/php7.y:1063 { yyVAL.node = stmt.NewReturn(yyDollar[2].node) @@ -3386,7 +3392,7 @@ yydefault: } case 141: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:1070 + //line php7/php7.y:1076 { yyVAL.node = stmt.NewGlobal(yyDollar[2].list) @@ -3401,7 +3407,7 @@ yydefault: } case 142: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:1083 + //line php7/php7.y:1089 { yyVAL.node = stmt.NewStatic(yyDollar[2].list) @@ -3416,7 +3422,7 @@ yydefault: } case 143: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:1096 + //line php7/php7.y:1102 { yyVAL.node = stmt.NewEcho(yyDollar[2].list) @@ -3431,7 +3437,7 @@ yydefault: } case 144: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:1109 + //line php7/php7.y:1115 { yyVAL.node = stmt.NewInlineHtml(yyDollar[1].token.Value) @@ -3445,7 +3451,7 @@ yydefault: } case 145: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:1121 + //line php7/php7.y:1127 { yyVAL.node = stmt.NewExpression(yyDollar[1].node) @@ -3459,7 +3465,7 @@ yydefault: } case 146: yyDollar = yyS[yypt-6 : yypt+1] - //line php7/php7.y:1133 + //line php7/php7.y:1139 { yyVAL.node = stmt.NewUnset(yyDollar[3].list) @@ -3479,7 +3485,7 @@ yydefault: } case 147: yyDollar = yyS[yypt-7 : yypt+1] - //line php7/php7.y:1151 + //line php7/php7.y:1157 { switch n := yyDollar[7].node.(type) { case *stmt.Foreach: @@ -3505,7 +3511,7 @@ yydefault: } case 148: yyDollar = yyS[yypt-9 : yypt+1] - //line php7/php7.y:1175 + //line php7/php7.y:1181 { switch n := yyDollar[9].node.(type) { case *stmt.Foreach: @@ -3534,7 +3540,7 @@ yydefault: } case 149: yyDollar = yyS[yypt-5 : yypt+1] - //line php7/php7.y:1202 + //line php7/php7.y:1208 { yyVAL.node = stmt.NewDeclare(yyDollar[3].list, yyDollar[5].node) @@ -3550,7 +3556,7 @@ yydefault: } case 150: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:1216 + //line php7/php7.y:1222 { yyVAL.node = stmt.NewNop() @@ -3564,7 +3570,7 @@ yydefault: } case 151: yyDollar = yyS[yypt-6 : yypt+1] - //line php7/php7.y:1228 + //line php7/php7.y:1234 { if yyDollar[6].node == nil { yyVAL.node = stmt.NewTry(yyDollar[3].list, yyDollar[5].list, yyDollar[6].node) @@ -3583,7 +3589,7 @@ yydefault: } case 152: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:1245 + //line php7/php7.y:1251 { yyVAL.node = stmt.NewThrow(yyDollar[2].node) @@ -3598,7 +3604,7 @@ yydefault: } case 153: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:1258 + //line php7/php7.y:1264 { label := node.NewIdentifier(yyDollar[2].token.Value) yyVAL.node = stmt.NewGoto(label) @@ -3609,14 +3615,14 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.GotoToken) - addMeta(label, yyDollar[2].token.Meta, meta.StringToken) + addMeta(label, yyDollar[2].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[3].token.Meta, meta.SemiColonToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 154: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:1274 + //line php7/php7.y:1280 { label := node.NewIdentifier(yyDollar[1].token.Value) yyVAL.node = stmt.NewLabel(label) @@ -3626,14 +3632,14 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition(yyDollar[1].token, yyDollar[2].token)) // save comments - addMeta(label, yyDollar[1].token.Meta, meta.StringToken) + addMeta(label, yyDollar[1].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.ColonToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 155: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:1291 + //line php7/php7.y:1297 { yyVAL.list = []node.Node{} @@ -3641,7 +3647,7 @@ yydefault: } case 156: yyDollar = yyS[yypt-9 : yypt+1] - //line php7/php7.y:1297 + //line php7/php7.y:1303 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[5].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -3656,7 +3662,7 @@ yydefault: // save comments addMeta(catch, yyDollar[2].token.Meta, meta.CatchToken) addMeta(catch, yyDollar[3].token.Meta, meta.OpenParenthesisToken) - addMeta(variable, yyDollar[5].token.Meta, meta.StringToken) + addMeta(variable, yyDollar[5].token.Meta, meta.VariableToken) addMeta(catch, yyDollar[6].token.Meta, meta.CloseParenthesisToken) addMeta(catch, yyDollar[7].token.Meta, meta.OpenCurlyBracesToken) addMeta(catch, yyDollar[9].token.Meta, meta.CloseCurlyBracesToken) @@ -3665,7 +3671,7 @@ yydefault: } case 157: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:1321 + //line php7/php7.y:1327 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -3673,18 +3679,18 @@ yydefault: } case 158: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:1327 + //line php7/php7.y:1333 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.VerticalBarToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 159: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:1339 + //line php7/php7.y:1345 { yyVAL.node = nil @@ -3692,7 +3698,7 @@ yydefault: } case 160: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:1345 + //line php7/php7.y:1351 { yyVAL.node = stmt.NewFinally(yyDollar[3].list) @@ -3708,7 +3714,7 @@ yydefault: } case 161: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:1362 + //line php7/php7.y:1368 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -3716,18 +3722,18 @@ yydefault: } case 162: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:1368 + //line php7/php7.y:1374 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 163: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:1380 + //line php7/php7.y:1386 { yyVAL.node = yyDollar[1].node @@ -3735,7 +3741,7 @@ yydefault: } case 164: yyDollar = yyS[yypt-11 : yypt+1] - //line php7/php7.y:1389 + //line php7/php7.y:1395 { name := node.NewIdentifier(yyDollar[3].token.Value) yyVAL.node = stmt.NewFunction(name, yyDollar[2].token != nil, yyDollar[6].list, yyDollar[8].node, yyDollar[10].list, yyDollar[4].str) @@ -3749,7 +3755,7 @@ yydefault: if yyDollar[2].token != nil { addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.AmpersandToken) } - addMeta(name, yyDollar[3].token.Meta, meta.StringToken) + addMeta(name, yyDollar[3].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[5].token.Meta, meta.OpenParenthesisToken) addMeta(yyVAL.node, yyDollar[7].token.Meta, meta.CloseParenthesisToken) addMeta(yyVAL.node, yyDollar[9].token.Meta, meta.OpenCurlyBracesToken) @@ -3759,31 +3765,31 @@ yydefault: } case 165: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:1415 + //line php7/php7.y:1421 { yyVAL.token = nil } case 166: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:1419 + //line php7/php7.y:1425 { yyVAL.token = yyDollar[1].token } case 167: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:1426 + //line php7/php7.y:1432 { yyVAL.token = nil } case 168: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:1430 + //line php7/php7.y:1436 { yyVAL.token = yyDollar[1].token } case 169: yyDollar = yyS[yypt-9 : yypt+1] - //line php7/php7.y:1437 + //line php7/php7.y:1443 { name := node.NewIdentifier(yyDollar[3].token.Value) yyVAL.node = stmt.NewClass(name, yyDollar[1].list, nil, yyDollar[4].ClassExtends, yyDollar[5].ClassImplements, yyDollar[8].list, yyDollar[6].str) @@ -3794,7 +3800,7 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.ClassToken) - addMeta(name, yyDollar[3].token.Meta, meta.StringToken) + addMeta(name, yyDollar[3].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[7].token.Meta, meta.OpenCurlyBracesToken) addMeta(yyVAL.node, yyDollar[9].token.Meta, meta.CloseCurlyBracesToken) @@ -3802,7 +3808,7 @@ yydefault: } case 170: yyDollar = yyS[yypt-8 : yypt+1] - //line php7/php7.y:1454 + //line php7/php7.y:1460 { name := node.NewIdentifier(yyDollar[2].token.Value) yyVAL.node = stmt.NewClass(name, nil, nil, yyDollar[3].ClassExtends, yyDollar[4].ClassImplements, yyDollar[7].list, yyDollar[5].str) @@ -3813,7 +3819,7 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.ClassToken) - addMeta(name, yyDollar[2].token.Meta, meta.StringToken) + addMeta(name, yyDollar[2].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[6].token.Meta, meta.OpenCurlyBracesToken) addMeta(yyVAL.node, yyDollar[8].token.Meta, meta.CloseCurlyBracesToken) @@ -3821,7 +3827,7 @@ yydefault: } case 171: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:1474 + //line php7/php7.y:1480 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -3829,7 +3835,7 @@ yydefault: } case 172: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:1480 + //line php7/php7.y:1486 { yyVAL.list = append(yyDollar[1].list, yyDollar[2].node) @@ -3837,7 +3843,7 @@ yydefault: } case 173: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:1489 + //line php7/php7.y:1495 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -3845,13 +3851,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.AbstractToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 174: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:1501 + //line php7/php7.y:1507 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -3859,13 +3865,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.FinalToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 175: yyDollar = yyS[yypt-6 : yypt+1] - //line php7/php7.y:1516 + //line php7/php7.y:1522 { name := node.NewIdentifier(yyDollar[2].token.Value) yyVAL.node = stmt.NewTrait(name, yyDollar[5].list, yyDollar[3].str) @@ -3876,7 +3882,7 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.TraitToken) - addMeta(name, yyDollar[2].token.Meta, meta.StringToken) + addMeta(name, yyDollar[2].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[4].token.Meta, meta.OpenCurlyBracesToken) addMeta(yyVAL.node, yyDollar[6].token.Meta, meta.CloseCurlyBracesToken) @@ -3884,7 +3890,7 @@ yydefault: } case 176: yyDollar = yyS[yypt-7 : yypt+1] - //line php7/php7.y:1536 + //line php7/php7.y:1542 { name := node.NewIdentifier(yyDollar[2].token.Value) yyVAL.node = stmt.NewInterface(name, yyDollar[3].InterfaceExtends, yyDollar[6].list, yyDollar[4].str) @@ -3895,7 +3901,7 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.InterfaceToken) - addMeta(name, yyDollar[2].token.Meta, meta.StringToken) + addMeta(name, yyDollar[2].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[5].token.Meta, meta.OpenCurlyBracesToken) addMeta(yyVAL.node, yyDollar[7].token.Meta, meta.CloseCurlyBracesToken) @@ -3903,7 +3909,7 @@ yydefault: } case 177: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:1556 + //line php7/php7.y:1562 { yyVAL.ClassExtends = nil @@ -3911,7 +3917,7 @@ yydefault: } case 178: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:1562 + //line php7/php7.y:1568 { yyVAL.ClassExtends = stmt.NewClassExtends(yyDollar[2].node) @@ -3925,7 +3931,7 @@ yydefault: } case 179: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:1577 + //line php7/php7.y:1583 { yyVAL.InterfaceExtends = nil @@ -3933,7 +3939,7 @@ yydefault: } case 180: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:1583 + //line php7/php7.y:1589 { yyVAL.InterfaceExtends = stmt.NewInterfaceExtends(yyDollar[2].list) @@ -3947,7 +3953,7 @@ yydefault: } case 181: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:1598 + //line php7/php7.y:1604 { yyVAL.ClassImplements = nil @@ -3955,7 +3961,7 @@ yydefault: } case 182: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:1604 + //line php7/php7.y:1610 { yyVAL.ClassImplements = stmt.NewClassImplements(yyDollar[2].list) @@ -3969,7 +3975,7 @@ yydefault: } case 183: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:1619 + //line php7/php7.y:1625 { yyVAL.node = yyDollar[1].node @@ -3977,7 +3983,7 @@ yydefault: } case 184: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:1625 + //line php7/php7.y:1631 { yyVAL.node = expr.NewReference(yyDollar[2].node) @@ -3991,7 +3997,7 @@ yydefault: } case 185: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:1637 + //line php7/php7.y:1643 { yyVAL.node = expr.NewList(yyDollar[3].list) @@ -4007,7 +4013,7 @@ yydefault: } case 186: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:1651 + //line php7/php7.y:1657 { yyVAL.node = expr.NewShortList(yyDollar[2].list) @@ -4022,7 +4028,7 @@ yydefault: } case 187: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:1667 + //line php7/php7.y:1673 { yyVAL.node = stmt.NewFor(nil, nil, nil, yyDollar[1].node) @@ -4033,7 +4039,7 @@ yydefault: } case 188: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:1676 + //line php7/php7.y:1682 { stmtList := stmt.NewStmtList(yyDollar[2].list) yyVAL.node = stmt.NewAltFor(nil, nil, nil, stmtList) @@ -4051,7 +4057,7 @@ yydefault: } case 189: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:1695 + //line php7/php7.y:1701 { yyVAL.node = stmt.NewForeach(nil, nil, nil, yyDollar[1].node) @@ -4062,7 +4068,7 @@ yydefault: } case 190: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:1704 + //line php7/php7.y:1710 { stmtList := stmt.NewStmtList(yyDollar[2].list) yyVAL.node = stmt.NewAltForeach(nil, nil, nil, stmtList) @@ -4080,7 +4086,7 @@ yydefault: } case 191: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:1723 + //line php7/php7.y:1729 { yyVAL.node = yyDollar[1].node @@ -4088,7 +4094,7 @@ yydefault: } case 192: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:1729 + //line php7/php7.y:1735 { yyVAL.node = stmt.NewStmtList(yyDollar[2].list) @@ -4104,7 +4110,7 @@ yydefault: } case 193: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:1746 + //line php7/php7.y:1752 { caseList := stmt.NewCaseList(yyDollar[2].list) yyVAL.node = stmt.NewSwitch(nil, caseList) @@ -4121,7 +4127,7 @@ yydefault: } case 194: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:1761 + //line php7/php7.y:1767 { caseList := stmt.NewCaseList(yyDollar[3].list) yyVAL.node = stmt.NewSwitch(nil, caseList) @@ -4139,7 +4145,7 @@ yydefault: } case 195: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:1777 + //line php7/php7.y:1783 { caseList := stmt.NewCaseList(yyDollar[2].list) yyVAL.node = stmt.NewAltSwitch(nil, caseList) @@ -4149,15 +4155,15 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition(yyDollar[1].token, yyDollar[4].token)) // save comments - addMeta(caseList, yyDollar[1].token.Meta, meta.ColonToken) - addMeta(caseList, yyDollar[3].token.Meta, meta.EndswitchToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.ColonToken) + addMeta(yyVAL.node, yyDollar[3].token.Meta, meta.EndswitchToken) addMeta(yyVAL.node, yyDollar[4].token.Meta, meta.SemiColonToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 196: yyDollar = yyS[yypt-5 : yypt+1] - //line php7/php7.y:1793 + //line php7/php7.y:1799 { caseList := stmt.NewCaseList(yyDollar[3].list) @@ -4168,16 +4174,16 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition(yyDollar[1].token, yyDollar[5].token)) // save comments - addMeta(caseList, yyDollar[1].token.Meta, meta.ColonToken) - addMeta(caseList, yyDollar[2].token.Meta, meta.SemiColonToken) - addMeta(caseList, yyDollar[4].token.Meta, meta.EndswitchToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.ColonToken) + addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.SwitchSemicolonToken) + addMeta(yyVAL.node, yyDollar[4].token.Meta, meta.EndswitchToken) addMeta(yyVAL.node, yyDollar[5].token.Meta, meta.SemiColonToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 197: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:1814 + //line php7/php7.y:1820 { yyVAL.list = []node.Node{} @@ -4185,7 +4191,7 @@ yydefault: } case 198: yyDollar = yyS[yypt-5 : yypt+1] - //line php7/php7.y:1820 + //line php7/php7.y:1826 { _case := stmt.NewCase(yyDollar[3].node, yyDollar[5].list) yyVAL.list = append(yyDollar[1].list, _case) @@ -4201,7 +4207,7 @@ yydefault: } case 199: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:1834 + //line php7/php7.y:1840 { _default := stmt.NewDefault(yyDollar[4].list) yyVAL.list = append(yyDollar[1].list, _default) @@ -4217,19 +4223,19 @@ yydefault: } case 200: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:1851 + //line php7/php7.y:1857 { yyVAL.token = yyDollar[1].token } case 201: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:1855 + //line php7/php7.y:1861 { yyVAL.token = yyDollar[1].token } case 202: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:1862 + //line php7/php7.y:1868 { yyVAL.node = stmt.NewWhile(nil, yyDollar[1].node) @@ -4240,7 +4246,7 @@ yydefault: } case 203: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:1871 + //line php7/php7.y:1877 { stmtList := stmt.NewStmtList(yyDollar[2].list) yyVAL.node = stmt.NewAltWhile(nil, stmtList) @@ -4258,7 +4264,7 @@ yydefault: } case 204: yyDollar = yyS[yypt-5 : yypt+1] - //line php7/php7.y:1890 + //line php7/php7.y:1896 { yyVAL.node = stmt.NewIf(yyDollar[3].node, yyDollar[5].node, nil, nil) @@ -4274,7 +4280,7 @@ yydefault: } case 205: yyDollar = yyS[yypt-6 : yypt+1] - //line php7/php7.y:1904 + //line php7/php7.y:1910 { _elseIf := stmt.NewElseIf(yyDollar[4].node, yyDollar[6].node) yyVAL.node = yyDollar[1].node.(*stmt.If).AddElseIf(_elseIf) @@ -4292,7 +4298,7 @@ yydefault: } case 206: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:1923 + //line php7/php7.y:1929 { yyVAL.node = yyDollar[1].node @@ -4300,7 +4306,7 @@ yydefault: } case 207: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:1929 + //line php7/php7.y:1935 { _else := stmt.NewElse(yyDollar[3].node) yyVAL.node = yyDollar[1].node.(*stmt.If).SetElse(_else) @@ -4310,13 +4316,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewNodesPosition(yyDollar[1].node, yyDollar[3].node)) // save comments - addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.ElseToken) + addMeta(_else, yyDollar[2].token.Meta, meta.ElseToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 208: yyDollar = yyS[yypt-6 : yypt+1] - //line php7/php7.y:1946 + //line php7/php7.y:1952 { stmts := stmt.NewStmtList(yyDollar[6].list) yyVAL.node = stmt.NewAltIf(yyDollar[3].node, stmts, nil, nil) @@ -4335,7 +4341,7 @@ yydefault: } case 209: yyDollar = yyS[yypt-7 : yypt+1] - //line php7/php7.y:1963 + //line php7/php7.y:1969 { stmts := stmt.NewStmtList(yyDollar[7].list) _elseIf := stmt.NewAltElseIf(yyDollar[4].node, stmts) @@ -4355,7 +4361,7 @@ yydefault: } case 210: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:1984 + //line php7/php7.y:1990 { yyVAL.node = yyDollar[1].node @@ -4370,7 +4376,7 @@ yydefault: } case 211: yyDollar = yyS[yypt-6 : yypt+1] - //line php7/php7.y:1997 + //line php7/php7.y:2003 { stmts := stmt.NewStmtList(yyDollar[4].list) _else := stmt.NewAltElse(stmts) @@ -4391,7 +4397,7 @@ yydefault: } case 212: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2019 + //line php7/php7.y:2025 { yyVAL.list = yyDollar[1].list @@ -4399,7 +4405,7 @@ yydefault: } case 213: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:2025 + //line php7/php7.y:2031 { yyVAL.list = nil @@ -4407,7 +4413,7 @@ yydefault: } case 214: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2034 + //line php7/php7.y:2040 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -4415,18 +4421,18 @@ yydefault: } case 215: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2040 + //line php7/php7.y:2046 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 216: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:2052 + //line php7/php7.y:2058 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[4].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -4458,7 +4464,7 @@ yydefault: } case 217: yyDollar = yyS[yypt-6 : yypt+1] - //line php7/php7.y:2082 + //line php7/php7.y:2088 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[4].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -4491,7 +4497,7 @@ yydefault: } case 218: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:2116 + //line php7/php7.y:2122 { yyVAL.node = nil @@ -4499,7 +4505,7 @@ yydefault: } case 219: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2122 + //line php7/php7.y:2128 { yyVAL.node = yyDollar[1].node @@ -4507,7 +4513,7 @@ yydefault: } case 220: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2131 + //line php7/php7.y:2137 { yyVAL.node = yyDollar[1].node @@ -4515,7 +4521,7 @@ yydefault: } case 221: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:2137 + //line php7/php7.y:2143 { yyVAL.node = node.NewNullable(yyDollar[2].node) @@ -4529,7 +4535,7 @@ yydefault: } case 222: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2152 + //line php7/php7.y:2158 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -4537,13 +4543,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.ArrayToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 223: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2164 + //line php7/php7.y:2170 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -4551,13 +4557,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.CallableToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 224: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2176 + //line php7/php7.y:2182 { yyVAL.node = yyDollar[1].node @@ -4565,7 +4571,7 @@ yydefault: } case 225: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:2185 + //line php7/php7.y:2191 { yyVAL.node = nil @@ -4573,7 +4579,7 @@ yydefault: } case 226: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:2191 + //line php7/php7.y:2197 { yyVAL.node = yyDollar[2].node @@ -4584,7 +4590,7 @@ yydefault: } case 227: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:2203 + //line php7/php7.y:2209 { yyVAL.node = node.NewArgumentList(nil) @@ -4599,7 +4605,7 @@ yydefault: } case 228: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:2216 + //line php7/php7.y:2222 { yyVAL.node = node.NewArgumentList(yyDollar[2].list) @@ -4617,7 +4623,7 @@ yydefault: } case 229: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2235 + //line php7/php7.y:2241 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -4625,18 +4631,18 @@ yydefault: } case 230: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2241 + //line php7/php7.y:2247 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 231: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2253 + //line php7/php7.y:2259 { yyVAL.node = node.NewArgument(yyDollar[1].node, false, false) @@ -4647,7 +4653,7 @@ yydefault: } case 232: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:2262 + //line php7/php7.y:2268 { yyVAL.node = node.NewArgument(yyDollar[2].node, true, false) @@ -4661,18 +4667,18 @@ yydefault: } case 233: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2277 + //line php7/php7.y:2283 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 234: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2286 + //line php7/php7.y:2292 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -4680,7 +4686,7 @@ yydefault: } case 235: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2295 + //line php7/php7.y:2301 { yyVAL.node = yyDollar[1].node @@ -4688,18 +4694,18 @@ yydefault: } case 236: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2304 + //line php7/php7.y:2310 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 237: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2313 + //line php7/php7.y:2319 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -4707,7 +4713,7 @@ yydefault: } case 238: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2322 + //line php7/php7.y:2328 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -4725,7 +4731,7 @@ yydefault: } case 239: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2338 + //line php7/php7.y:2344 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -4744,7 +4750,7 @@ yydefault: } case 240: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:2358 + //line php7/php7.y:2364 { yyVAL.list = append(yyDollar[1].list, yyDollar[2].node) @@ -4752,7 +4758,7 @@ yydefault: } case 241: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:2364 + //line php7/php7.y:2370 { yyVAL.list = []node.Node{} @@ -4760,7 +4766,7 @@ yydefault: } case 242: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2373 + //line php7/php7.y:2379 { yyVAL.node = stmt.NewPropertyList(yyDollar[1].list, yyDollar[2].list) @@ -4774,7 +4780,7 @@ yydefault: } case 243: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:2385 + //line php7/php7.y:2391 { yyVAL.node = stmt.NewClassConstList(yyDollar[1].list, yyDollar[3].list) @@ -4789,18 +4795,9 @@ yydefault: } case 244: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2398 + //line php7/php7.y:2404 { - var adaptationList *stmt.TraitAdaptationList - - switch n := yyDollar[3].node.(type) { - case *stmt.TraitAdaptationList: - adaptationList = n - default: - adaptationList = nil - } - - yyVAL.node = stmt.NewTraitUse(yyDollar[2].list, adaptationList) + yyVAL.node = stmt.NewTraitUse(yyDollar[2].list, yyDollar[3].node) // save position yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenNodePosition(yyDollar[1].token, yyDollar[3].node)) @@ -4812,7 +4809,7 @@ yydefault: } case 245: yyDollar = yyS[yypt-10 : yypt+1] - //line php7/php7.y:2419 + //line php7/php7.y:2416 { name := node.NewIdentifier(yyDollar[4].token.Value) yyVAL.node = stmt.NewClassMethod(name, yyDollar[1].list, yyDollar[3].token != nil, yyDollar[7].list, yyDollar[9].node, yyDollar[10].node, yyDollar[5].str) @@ -4838,7 +4835,7 @@ yydefault: } case 246: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2446 + //line php7/php7.y:2443 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -4846,18 +4843,18 @@ yydefault: } case 247: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2452 + //line php7/php7.y:2449 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 248: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2464 + //line php7/php7.y:2461 { yyVAL.node = stmt.NewNop() @@ -4870,7 +4867,7 @@ yydefault: } case 249: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:2476 + //line php7/php7.y:2473 { yyVAL.node = stmt.NewTraitAdaptationList(nil) @@ -4884,7 +4881,7 @@ yydefault: } case 250: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2488 + //line php7/php7.y:2485 { yyVAL.node = stmt.NewTraitAdaptationList(yyDollar[2].list) @@ -4898,7 +4895,7 @@ yydefault: } case 251: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2503 + //line php7/php7.y:2500 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -4906,7 +4903,7 @@ yydefault: } case 252: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:2509 + //line php7/php7.y:2506 { yyVAL.list = append(yyDollar[1].list, yyDollar[2].node) @@ -4914,7 +4911,7 @@ yydefault: } case 253: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:2518 + //line php7/php7.y:2515 { yyVAL.node = yyDollar[1].node @@ -4925,7 +4922,7 @@ yydefault: } case 254: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:2527 + //line php7/php7.y:2524 { yyVAL.node = yyDollar[1].node @@ -4936,7 +4933,7 @@ yydefault: } case 255: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2539 + //line php7/php7.y:2536 { yyVAL.node = stmt.NewTraitUsePrecedence(yyDollar[1].node, yyDollar[3].list) @@ -4950,7 +4947,7 @@ yydefault: } case 256: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2554 + //line php7/php7.y:2551 { alias := node.NewIdentifier(yyDollar[3].token.Value) yyVAL.node = stmt.NewTraitUseAlias(yyDollar[1].node, nil, alias) @@ -4961,13 +4958,13 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.AsToken) - addMeta(alias, yyDollar[3].token.Meta, meta.StringToken) + addMeta(alias, yyDollar[3].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 257: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2569 + //line php7/php7.y:2566 { alias := node.NewIdentifier(yyDollar[3].token.Value) yyVAL.node = stmt.NewTraitUseAlias(yyDollar[1].node, nil, alias) @@ -4978,13 +4975,13 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.AsToken) - addMeta(alias, yyDollar[3].token.Meta, meta.StringToken) + addMeta(alias, yyDollar[3].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 258: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:2584 + //line php7/php7.y:2581 { alias := node.NewIdentifier(yyDollar[4].token.Value) yyVAL.node = stmt.NewTraitUseAlias(yyDollar[1].node, yyDollar[3].node, alias) @@ -5001,7 +4998,7 @@ yydefault: } case 259: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2599 + //line php7/php7.y:2596 { yyVAL.node = stmt.NewTraitUseAlias(yyDollar[1].node, yyDollar[3].node, nil) @@ -5015,7 +5012,7 @@ yydefault: } case 260: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2614 + //line php7/php7.y:2611 { name := node.NewIdentifier(yyDollar[1].token.Value) yyVAL.node = stmt.NewTraitMethodRef(nil, name) @@ -5031,7 +5028,7 @@ yydefault: } case 261: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2628 + //line php7/php7.y:2625 { yyVAL.node = yyDollar[1].node @@ -5039,7 +5036,7 @@ yydefault: } case 262: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2637 + //line php7/php7.y:2634 { target := node.NewIdentifier(yyDollar[3].token.Value) yyVAL.node = stmt.NewTraitMethodRef(yyDollar[1].node, target) @@ -5056,7 +5053,7 @@ yydefault: } case 263: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2655 + //line php7/php7.y:2652 { yyVAL.node = stmt.NewNop() @@ -5070,7 +5067,7 @@ yydefault: } case 264: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2667 + //line php7/php7.y:2664 { yyVAL.node = stmt.NewStmtList(yyDollar[2].list) @@ -5085,7 +5082,7 @@ yydefault: } case 265: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2683 + //line php7/php7.y:2680 { yyVAL.list = yyDollar[1].list @@ -5093,7 +5090,7 @@ yydefault: } case 266: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2689 + //line php7/php7.y:2686 { modifier := node.NewIdentifier(yyDollar[1].token.Value) yyVAL.list = []node.Node{modifier} @@ -5102,13 +5099,13 @@ yydefault: modifier.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(modifier, yyDollar[1].token.Meta, meta.VarToken) + addMeta(modifier, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 267: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:2705 + //line php7/php7.y:2702 { yyVAL.list = nil @@ -5116,7 +5113,7 @@ yydefault: } case 268: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2711 + //line php7/php7.y:2708 { yyVAL.list = yyDollar[1].list @@ -5124,7 +5121,7 @@ yydefault: } case 269: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2720 + //line php7/php7.y:2717 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -5132,7 +5129,7 @@ yydefault: } case 270: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:2726 + //line php7/php7.y:2723 { yyVAL.list = append(yyDollar[1].list, yyDollar[2].node) @@ -5140,7 +5137,7 @@ yydefault: } case 271: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2735 + //line php7/php7.y:2732 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -5148,13 +5145,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.PublicToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 272: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2747 + //line php7/php7.y:2744 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -5162,13 +5159,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.ProtectedToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 273: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2759 + //line php7/php7.y:2756 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -5176,13 +5173,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.PrivateToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 274: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2771 + //line php7/php7.y:2768 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -5190,13 +5187,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.StaticToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 275: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2783 + //line php7/php7.y:2780 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -5204,13 +5201,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.AbstractToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 276: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2795 + //line php7/php7.y:2792 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -5218,24 +5215,24 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.FinalToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 277: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2810 + //line php7/php7.y:2807 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 278: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2819 + //line php7/php7.y:2816 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -5243,7 +5240,7 @@ yydefault: } case 279: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:2828 + //line php7/php7.y:2825 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -5261,7 +5258,7 @@ yydefault: } case 280: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:2844 + //line php7/php7.y:2841 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -5280,18 +5277,18 @@ yydefault: } case 281: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2864 + //line php7/php7.y:2861 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 282: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2873 + //line php7/php7.y:2870 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -5299,7 +5296,7 @@ yydefault: } case 283: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:2882 + //line php7/php7.y:2879 { name := node.NewIdentifier(yyDollar[1].token.Value) yyVAL.node = stmt.NewConstant(name, yyDollar[3].node, yyDollar[4].str) @@ -5316,7 +5313,7 @@ yydefault: } case 284: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:2900 + //line php7/php7.y:2897 { name := node.NewIdentifier(yyDollar[1].token.Value) yyVAL.node = stmt.NewConstant(name, yyDollar[3].node, yyDollar[4].str) @@ -5326,25 +5323,25 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenNodePosition(yyDollar[1].token, yyDollar[3].node)) // save comments - addMeta(name, yyDollar[1].token.Meta, meta.StringToken) + addMeta(name, yyDollar[1].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.EqualToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 285: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2918 + //line php7/php7.y:2915 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 286: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2927 + //line php7/php7.y:2924 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -5352,7 +5349,7 @@ yydefault: } case 287: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2936 + //line php7/php7.y:2933 { yyVAL.node = yyDollar[1].node @@ -5360,7 +5357,7 @@ yydefault: } case 288: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:2945 + //line php7/php7.y:2942 { yyVAL.list = nil @@ -5368,7 +5365,7 @@ yydefault: } case 289: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2951 + //line php7/php7.y:2948 { yyVAL.list = yyDollar[1].list @@ -5376,18 +5373,18 @@ yydefault: } case 290: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2960 + //line php7/php7.y:2957 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 291: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:2969 + //line php7/php7.y:2966 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -5395,7 +5392,7 @@ yydefault: } case 292: yyDollar = yyS[yypt-8 : yypt+1] - //line php7/php7.y:2978 + //line php7/php7.y:2975 { if yyDollar[2].node != nil { yyVAL.node = stmt.NewClass(nil, nil, yyDollar[2].node.(*node.ArgumentList), yyDollar[3].ClassExtends, yyDollar[4].ClassImplements, yyDollar[7].list, yyDollar[5].str) @@ -5415,7 +5412,7 @@ yydefault: } case 293: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:2999 + //line php7/php7.y:2996 { if yyDollar[3].node != nil { yyVAL.node = expr.NewNew(yyDollar[2].node, yyDollar[3].node.(*node.ArgumentList)) @@ -5432,7 +5429,7 @@ yydefault: } case 294: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3014 + //line php7/php7.y:3011 { yyVAL.node = expr.NewNew(yyDollar[2].node, nil) @@ -5446,7 +5443,7 @@ yydefault: } case 295: yyDollar = yyS[yypt-6 : yypt+1] - //line php7/php7.y:3029 + //line php7/php7.y:3026 { list := expr.NewList(yyDollar[3].list) yyVAL.node = assign.NewAssign(list, yyDollar[6].node) @@ -5465,7 +5462,7 @@ yydefault: } case 296: yyDollar = yyS[yypt-5 : yypt+1] - //line php7/php7.y:3046 + //line php7/php7.y:3043 { shortList := expr.NewShortList(yyDollar[2].list) yyVAL.node = assign.NewAssign(shortList, yyDollar[5].node) @@ -5483,7 +5480,7 @@ yydefault: } case 297: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3062 + //line php7/php7.y:3059 { yyVAL.node = assign.NewAssign(yyDollar[1].node, yyDollar[3].node) @@ -5497,7 +5494,7 @@ yydefault: } case 298: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:3074 + //line php7/php7.y:3071 { yyVAL.node = assign.NewReference(yyDollar[1].node, yyDollar[4].node) @@ -5512,7 +5509,7 @@ yydefault: } case 299: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3087 + //line php7/php7.y:3084 { yyVAL.node = expr.NewClone(yyDollar[2].node) @@ -5526,7 +5523,7 @@ yydefault: } case 300: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3099 + //line php7/php7.y:3096 { yyVAL.node = assign.NewPlus(yyDollar[1].node, yyDollar[3].node) @@ -5540,7 +5537,7 @@ yydefault: } case 301: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3111 + //line php7/php7.y:3108 { yyVAL.node = assign.NewMinus(yyDollar[1].node, yyDollar[3].node) @@ -5554,7 +5551,7 @@ yydefault: } case 302: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3123 + //line php7/php7.y:3120 { yyVAL.node = assign.NewMul(yyDollar[1].node, yyDollar[3].node) @@ -5568,7 +5565,7 @@ yydefault: } case 303: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3135 + //line php7/php7.y:3132 { yyVAL.node = assign.NewPow(yyDollar[1].node, yyDollar[3].node) @@ -5582,7 +5579,7 @@ yydefault: } case 304: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3147 + //line php7/php7.y:3144 { yyVAL.node = assign.NewDiv(yyDollar[1].node, yyDollar[3].node) @@ -5596,7 +5593,7 @@ yydefault: } case 305: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3159 + //line php7/php7.y:3156 { yyVAL.node = assign.NewConcat(yyDollar[1].node, yyDollar[3].node) @@ -5610,7 +5607,7 @@ yydefault: } case 306: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3171 + //line php7/php7.y:3168 { yyVAL.node = assign.NewMod(yyDollar[1].node, yyDollar[3].node) @@ -5624,7 +5621,7 @@ yydefault: } case 307: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3183 + //line php7/php7.y:3180 { yyVAL.node = assign.NewBitwiseAnd(yyDollar[1].node, yyDollar[3].node) @@ -5638,7 +5635,7 @@ yydefault: } case 308: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3195 + //line php7/php7.y:3192 { yyVAL.node = assign.NewBitwiseOr(yyDollar[1].node, yyDollar[3].node) @@ -5652,7 +5649,7 @@ yydefault: } case 309: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3207 + //line php7/php7.y:3204 { yyVAL.node = assign.NewBitwiseXor(yyDollar[1].node, yyDollar[3].node) @@ -5666,7 +5663,7 @@ yydefault: } case 310: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3219 + //line php7/php7.y:3216 { yyVAL.node = assign.NewShiftLeft(yyDollar[1].node, yyDollar[3].node) @@ -5680,7 +5677,7 @@ yydefault: } case 311: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3231 + //line php7/php7.y:3228 { yyVAL.node = assign.NewShiftRight(yyDollar[1].node, yyDollar[3].node) @@ -5694,7 +5691,7 @@ yydefault: } case 312: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3243 + //line php7/php7.y:3240 { yyVAL.node = expr.NewPostInc(yyDollar[1].node) @@ -5708,7 +5705,7 @@ yydefault: } case 313: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3255 + //line php7/php7.y:3252 { yyVAL.node = expr.NewPreInc(yyDollar[2].node) @@ -5722,7 +5719,7 @@ yydefault: } case 314: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3267 + //line php7/php7.y:3264 { yyVAL.node = expr.NewPostDec(yyDollar[1].node) @@ -5736,7 +5733,7 @@ yydefault: } case 315: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3279 + //line php7/php7.y:3276 { yyVAL.node = expr.NewPreDec(yyDollar[2].node) @@ -5750,7 +5747,7 @@ yydefault: } case 316: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3291 + //line php7/php7.y:3288 { yyVAL.node = binary.NewBooleanOr(yyDollar[1].node, yyDollar[3].node) @@ -5764,7 +5761,7 @@ yydefault: } case 317: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3303 + //line php7/php7.y:3300 { yyVAL.node = binary.NewBooleanAnd(yyDollar[1].node, yyDollar[3].node) @@ -5778,7 +5775,7 @@ yydefault: } case 318: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3315 + //line php7/php7.y:3312 { yyVAL.node = binary.NewLogicalOr(yyDollar[1].node, yyDollar[3].node) @@ -5792,7 +5789,7 @@ yydefault: } case 319: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3327 + //line php7/php7.y:3324 { yyVAL.node = binary.NewLogicalAnd(yyDollar[1].node, yyDollar[3].node) @@ -5806,7 +5803,7 @@ yydefault: } case 320: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3339 + //line php7/php7.y:3336 { yyVAL.node = binary.NewLogicalXor(yyDollar[1].node, yyDollar[3].node) @@ -5820,7 +5817,7 @@ yydefault: } case 321: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3351 + //line php7/php7.y:3348 { yyVAL.node = binary.NewBitwiseOr(yyDollar[1].node, yyDollar[3].node) @@ -5834,7 +5831,7 @@ yydefault: } case 322: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3363 + //line php7/php7.y:3360 { yyVAL.node = binary.NewBitwiseAnd(yyDollar[1].node, yyDollar[3].node) @@ -5848,7 +5845,7 @@ yydefault: } case 323: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3375 + //line php7/php7.y:3372 { yyVAL.node = binary.NewBitwiseXor(yyDollar[1].node, yyDollar[3].node) @@ -5862,7 +5859,7 @@ yydefault: } case 324: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3387 + //line php7/php7.y:3384 { yyVAL.node = binary.NewConcat(yyDollar[1].node, yyDollar[3].node) @@ -5876,7 +5873,7 @@ yydefault: } case 325: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3399 + //line php7/php7.y:3396 { yyVAL.node = binary.NewPlus(yyDollar[1].node, yyDollar[3].node) @@ -5890,7 +5887,7 @@ yydefault: } case 326: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3411 + //line php7/php7.y:3408 { yyVAL.node = binary.NewMinus(yyDollar[1].node, yyDollar[3].node) @@ -5904,7 +5901,7 @@ yydefault: } case 327: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3423 + //line php7/php7.y:3420 { yyVAL.node = binary.NewMul(yyDollar[1].node, yyDollar[3].node) @@ -5918,7 +5915,7 @@ yydefault: } case 328: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3435 + //line php7/php7.y:3432 { yyVAL.node = binary.NewPow(yyDollar[1].node, yyDollar[3].node) @@ -5932,7 +5929,7 @@ yydefault: } case 329: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3447 + //line php7/php7.y:3444 { yyVAL.node = binary.NewDiv(yyDollar[1].node, yyDollar[3].node) @@ -5946,7 +5943,7 @@ yydefault: } case 330: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3459 + //line php7/php7.y:3456 { yyVAL.node = binary.NewMod(yyDollar[1].node, yyDollar[3].node) @@ -5960,7 +5957,7 @@ yydefault: } case 331: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3471 + //line php7/php7.y:3468 { yyVAL.node = binary.NewShiftLeft(yyDollar[1].node, yyDollar[3].node) @@ -5974,7 +5971,7 @@ yydefault: } case 332: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3483 + //line php7/php7.y:3480 { yyVAL.node = binary.NewShiftRight(yyDollar[1].node, yyDollar[3].node) @@ -5988,7 +5985,7 @@ yydefault: } case 333: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3495 + //line php7/php7.y:3492 { yyVAL.node = expr.NewUnaryPlus(yyDollar[2].node) @@ -6002,7 +5999,7 @@ yydefault: } case 334: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3507 + //line php7/php7.y:3504 { yyVAL.node = expr.NewUnaryMinus(yyDollar[2].node) @@ -6016,7 +6013,7 @@ yydefault: } case 335: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3519 + //line php7/php7.y:3516 { yyVAL.node = expr.NewBooleanNot(yyDollar[2].node) @@ -6030,7 +6027,7 @@ yydefault: } case 336: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3531 + //line php7/php7.y:3528 { yyVAL.node = expr.NewBitwiseNot(yyDollar[2].node) @@ -6044,7 +6041,7 @@ yydefault: } case 337: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3543 + //line php7/php7.y:3540 { yyVAL.node = binary.NewIdentical(yyDollar[1].node, yyDollar[3].node) @@ -6058,7 +6055,7 @@ yydefault: } case 338: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3555 + //line php7/php7.y:3552 { yyVAL.node = binary.NewNotIdentical(yyDollar[1].node, yyDollar[3].node) @@ -6072,7 +6069,7 @@ yydefault: } case 339: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3567 + //line php7/php7.y:3564 { yyVAL.node = binary.NewEqual(yyDollar[1].node, yyDollar[3].node) @@ -6086,7 +6083,7 @@ yydefault: } case 340: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3579 + //line php7/php7.y:3576 { yyVAL.node = binary.NewNotEqual(yyDollar[1].node, yyDollar[3].node) @@ -6100,7 +6097,7 @@ yydefault: } case 341: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3591 + //line php7/php7.y:3588 { yyVAL.node = binary.NewSmaller(yyDollar[1].node, yyDollar[3].node) @@ -6114,7 +6111,7 @@ yydefault: } case 342: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3603 + //line php7/php7.y:3600 { yyVAL.node = binary.NewSmallerOrEqual(yyDollar[1].node, yyDollar[3].node) @@ -6128,7 +6125,7 @@ yydefault: } case 343: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3615 + //line php7/php7.y:3612 { yyVAL.node = binary.NewGreater(yyDollar[1].node, yyDollar[3].node) @@ -6142,7 +6139,7 @@ yydefault: } case 344: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3627 + //line php7/php7.y:3624 { yyVAL.node = binary.NewGreaterOrEqual(yyDollar[1].node, yyDollar[3].node) @@ -6156,7 +6153,7 @@ yydefault: } case 345: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3639 + //line php7/php7.y:3636 { yyVAL.node = binary.NewSpaceship(yyDollar[1].node, yyDollar[3].node) @@ -6170,7 +6167,7 @@ yydefault: } case 346: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3651 + //line php7/php7.y:3648 { yyVAL.node = expr.NewInstanceOf(yyDollar[1].node, yyDollar[3].node) @@ -6184,7 +6181,7 @@ yydefault: } case 347: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3663 + //line php7/php7.y:3660 { yyVAL.node = yyDollar[2].node @@ -6196,7 +6193,7 @@ yydefault: } case 348: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:3673 + //line php7/php7.y:3670 { yyVAL.node = yyDollar[1].node @@ -6204,7 +6201,7 @@ yydefault: } case 349: yyDollar = yyS[yypt-5 : yypt+1] - //line php7/php7.y:3679 + //line php7/php7.y:3676 { yyVAL.node = expr.NewTernary(yyDollar[1].node, yyDollar[3].node, yyDollar[5].node) @@ -6219,7 +6216,7 @@ yydefault: } case 350: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:3692 + //line php7/php7.y:3689 { yyVAL.node = expr.NewTernary(yyDollar[1].node, nil, yyDollar[4].node) @@ -6234,7 +6231,7 @@ yydefault: } case 351: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3705 + //line php7/php7.y:3702 { yyVAL.node = binary.NewCoalesce(yyDollar[1].node, yyDollar[3].node) @@ -6248,7 +6245,7 @@ yydefault: } case 352: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:3717 + //line php7/php7.y:3714 { yyVAL.node = yyDollar[1].node @@ -6256,7 +6253,7 @@ yydefault: } case 353: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3723 + //line php7/php7.y:3720 { yyVAL.node = cast.NewInt(yyDollar[2].node) @@ -6270,7 +6267,7 @@ yydefault: } case 354: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3735 + //line php7/php7.y:3732 { yyVAL.node = cast.NewDouble(yyDollar[2].node) @@ -6284,7 +6281,7 @@ yydefault: } case 355: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3747 + //line php7/php7.y:3744 { yyVAL.node = cast.NewString(yyDollar[2].node) @@ -6298,7 +6295,7 @@ yydefault: } case 356: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3759 + //line php7/php7.y:3756 { yyVAL.node = cast.NewArray(yyDollar[2].node) @@ -6312,7 +6309,7 @@ yydefault: } case 357: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3771 + //line php7/php7.y:3768 { yyVAL.node = cast.NewObject(yyDollar[2].node) @@ -6326,7 +6323,7 @@ yydefault: } case 358: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3783 + //line php7/php7.y:3780 { yyVAL.node = cast.NewBool(yyDollar[2].node) @@ -6340,7 +6337,7 @@ yydefault: } case 359: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3795 + //line php7/php7.y:3792 { yyVAL.node = cast.NewUnset(yyDollar[2].node) @@ -6354,7 +6351,7 @@ yydefault: } case 360: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3807 + //line php7/php7.y:3804 { if strings.EqualFold(yyDollar[1].token.Value, "die") { yyVAL.node = expr.NewDie(nil) @@ -6382,7 +6379,7 @@ yydefault: } case 361: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3833 + //line php7/php7.y:3830 { yyVAL.node = expr.NewErrorSuppress(yyDollar[2].node) @@ -6396,7 +6393,7 @@ yydefault: } case 362: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:3845 + //line php7/php7.y:3842 { yyVAL.node = yyDollar[1].node @@ -6404,7 +6401,7 @@ yydefault: } case 363: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:3851 + //line php7/php7.y:3848 { yyVAL.node = expr.NewShellExec(yyDollar[2].list) @@ -6419,7 +6416,7 @@ yydefault: } case 364: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3864 + //line php7/php7.y:3861 { yyVAL.node = expr.NewPrint(yyDollar[2].node) @@ -6433,7 +6430,7 @@ yydefault: } case 365: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:3876 + //line php7/php7.y:3873 { yyVAL.node = expr.NewYield(nil, nil) @@ -6447,7 +6444,7 @@ yydefault: } case 366: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3888 + //line php7/php7.y:3885 { yyVAL.node = expr.NewYield(nil, yyDollar[2].node) @@ -6461,7 +6458,7 @@ yydefault: } case 367: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:3900 + //line php7/php7.y:3897 { yyVAL.node = expr.NewYield(yyDollar[2].node, yyDollar[4].node) @@ -6476,7 +6473,7 @@ yydefault: } case 368: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:3913 + //line php7/php7.y:3910 { yyVAL.node = expr.NewYieldFrom(yyDollar[2].node) @@ -6490,7 +6487,7 @@ yydefault: } case 369: yyDollar = yyS[yypt-11 : yypt+1] - //line php7/php7.y:3925 + //line php7/php7.y:3922 { yyVAL.node = expr.NewClosure(yyDollar[5].list, yyDollar[7].ClosureUse, yyDollar[8].node, yyDollar[10].list, false, yyDollar[2].token != nil, yyDollar[3].str) @@ -6511,7 +6508,7 @@ yydefault: } case 370: yyDollar = yyS[yypt-12 : yypt+1] - //line php7/php7.y:3944 + //line php7/php7.y:3941 { yyVAL.node = expr.NewClosure(yyDollar[6].list, yyDollar[8].ClosureUse, yyDollar[9].node, yyDollar[11].list, true, yyDollar[3].token != nil, yyDollar[4].str) @@ -6533,7 +6530,7 @@ yydefault: } case 371: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:3967 + //line php7/php7.y:3964 { yyVAL.str = yylex.(*Parser).PhpDocComment yylex.(*Parser).PhpDocComment = "" @@ -6542,19 +6539,19 @@ yydefault: } case 372: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:3977 + //line php7/php7.y:3974 { yyVAL.token = nil } case 373: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:3981 + //line php7/php7.y:3978 { yyVAL.token = yyDollar[1].token } case 374: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:3988 + //line php7/php7.y:3985 { yyVAL.ClosureUse = nil @@ -6562,7 +6559,7 @@ yydefault: } case 375: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:3994 + //line php7/php7.y:3991 { yyVAL.ClosureUse = expr.NewClosureUse(yyDollar[3].list) @@ -6578,18 +6575,18 @@ yydefault: } case 376: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4011 + //line php7/php7.y:4008 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 377: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4020 + //line php7/php7.y:4017 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -6597,7 +6594,7 @@ yydefault: } case 378: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4029 + //line php7/php7.y:4026 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) yyVAL.node = expr.NewVariable(identifier) @@ -6613,7 +6610,7 @@ yydefault: } case 379: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:4043 + //line php7/php7.y:4040 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[2].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -6632,7 +6629,7 @@ yydefault: } case 380: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:4063 + //line php7/php7.y:4060 { yyVAL.node = expr.NewFunctionCall(yyDollar[1].node, yyDollar[2].node.(*node.ArgumentList)) @@ -6643,7 +6640,7 @@ yydefault: } case 381: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:4072 + //line php7/php7.y:4069 { yyVAL.node = expr.NewStaticCall(yyDollar[1].node, yyDollar[3].node, yyDollar[4].node.(*node.ArgumentList)) @@ -6657,7 +6654,7 @@ yydefault: } case 382: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:4084 + //line php7/php7.y:4081 { yyVAL.node = expr.NewStaticCall(yyDollar[1].node, yyDollar[3].node, yyDollar[4].node.(*node.ArgumentList)) @@ -6671,7 +6668,7 @@ yydefault: } case 383: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:4096 + //line php7/php7.y:4093 { yyVAL.node = expr.NewFunctionCall(yyDollar[1].node, yyDollar[2].node.(*node.ArgumentList)) @@ -6682,7 +6679,7 @@ yydefault: } case 384: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4108 + //line php7/php7.y:4105 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -6690,13 +6687,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.StaticToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 385: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4120 + //line php7/php7.y:4117 { yyVAL.node = yyDollar[1].node @@ -6704,7 +6701,7 @@ yydefault: } case 386: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4129 + //line php7/php7.y:4126 { yyVAL.node = yyDollar[1].node @@ -6712,7 +6709,7 @@ yydefault: } case 387: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4135 + //line php7/php7.y:4132 { yyVAL.node = yyDollar[1].node @@ -6720,7 +6717,7 @@ yydefault: } case 388: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:4144 + //line php7/php7.y:4141 { yyVAL.node = nil @@ -6728,7 +6725,7 @@ yydefault: } case 389: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4150 + //line php7/php7.y:4147 { yyVAL.node = expr.NewExit(yyDollar[2].node) @@ -6736,14 +6733,14 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.OpenParenthesisToken) - addMeta(yyVAL.node, yyDollar[3].token.Meta, meta.CloseParenthesisToken) + addMeta(yyDollar[2].node, yyDollar[1].token.Meta, meta.OpenParenthesisToken) + addMeta(yyDollar[2].node, yyDollar[3].token.Meta, meta.CloseParenthesisToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 390: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:4166 + //line php7/php7.y:4163 { yyVAL.list = []node.Node{} @@ -6751,7 +6748,7 @@ yydefault: } case 391: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4172 + //line php7/php7.y:4169 { yyVAL.list = []node.Node{scalar.NewEncapsedStringPart(yyDollar[1].token.Value)} @@ -6759,7 +6756,7 @@ yydefault: } case 392: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4178 + //line php7/php7.y:4175 { yyVAL.list = yyDollar[1].list @@ -6767,7 +6764,7 @@ yydefault: } case 393: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:4187 + //line php7/php7.y:4184 { yyVAL.node = nil @@ -6775,7 +6772,7 @@ yydefault: } case 394: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4193 + //line php7/php7.y:4190 { yyVAL.node = yyDollar[1].node @@ -6783,7 +6780,7 @@ yydefault: } case 395: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:4202 + //line php7/php7.y:4199 { yyVAL.node = expr.NewArray(yyDollar[3].list) @@ -6799,7 +6796,7 @@ yydefault: } case 396: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4216 + //line php7/php7.y:4213 { yyVAL.node = expr.NewShortArray(yyDollar[2].list) @@ -6814,7 +6811,7 @@ yydefault: } case 397: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4229 + //line php7/php7.y:4226 { yyVAL.node = scalar.NewString(yyDollar[1].token.Value) @@ -6828,7 +6825,7 @@ yydefault: } case 398: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4244 + //line php7/php7.y:4241 { yyVAL.node = scalar.NewLnumber(yyDollar[1].token.Value) @@ -6842,7 +6839,7 @@ yydefault: } case 399: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4256 + //line php7/php7.y:4253 { yyVAL.node = scalar.NewDnumber(yyDollar[1].token.Value) @@ -6856,7 +6853,7 @@ yydefault: } case 400: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4268 + //line php7/php7.y:4265 { yyVAL.node = scalar.NewMagicConstant(yyDollar[1].token.Value) @@ -6864,13 +6861,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.LineToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MagicConstantToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 401: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4280 + //line php7/php7.y:4277 { yyVAL.node = scalar.NewMagicConstant(yyDollar[1].token.Value) @@ -6878,13 +6875,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.FileToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MagicConstantToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 402: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4292 + //line php7/php7.y:4289 { yyVAL.node = scalar.NewMagicConstant(yyDollar[1].token.Value) @@ -6892,13 +6889,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.DirToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MagicConstantToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 403: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4304 + //line php7/php7.y:4301 { yyVAL.node = scalar.NewMagicConstant(yyDollar[1].token.Value) @@ -6906,13 +6903,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.TraitCToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MagicConstantToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 404: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4316 + //line php7/php7.y:4313 { yyVAL.node = scalar.NewMagicConstant(yyDollar[1].token.Value) @@ -6920,13 +6917,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MethodCToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MagicConstantToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 405: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4328 + //line php7/php7.y:4325 { yyVAL.node = scalar.NewMagicConstant(yyDollar[1].token.Value) @@ -6934,13 +6931,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.FuncCToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MagicConstantToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 406: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4340 + //line php7/php7.y:4337 { yyVAL.node = scalar.NewMagicConstant(yyDollar[1].token.Value) @@ -6948,13 +6945,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.NsCToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MagicConstantToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 407: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4352 + //line php7/php7.y:4349 { yyVAL.node = scalar.NewMagicConstant(yyDollar[1].token.Value) @@ -6962,13 +6959,13 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.ClassCToken) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.MagicConstantToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 408: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4364 + //line php7/php7.y:4361 { encapsed := scalar.NewEncapsedStringPart(yyDollar[2].token.Value) yyVAL.node = scalar.NewHeredoc(yyDollar[1].token.Value, []node.Node{encapsed}) @@ -6984,7 +6981,7 @@ yydefault: } case 409: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:4378 + //line php7/php7.y:4375 { yyVAL.node = scalar.NewHeredoc(yyDollar[1].token.Value, nil) @@ -6998,7 +6995,7 @@ yydefault: } case 410: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4390 + //line php7/php7.y:4387 { yyVAL.node = scalar.NewEncapsed(yyDollar[2].list) @@ -7012,7 +7009,7 @@ yydefault: } case 411: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4402 + //line php7/php7.y:4399 { yyVAL.node = scalar.NewHeredoc(yyDollar[1].token.Value, yyDollar[2].list) @@ -7026,7 +7023,7 @@ yydefault: } case 412: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4414 + //line php7/php7.y:4411 { yyVAL.node = yyDollar[1].node @@ -7034,7 +7031,7 @@ yydefault: } case 413: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4420 + //line php7/php7.y:4417 { yyVAL.node = yyDollar[1].node @@ -7042,7 +7039,7 @@ yydefault: } case 414: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4429 + //line php7/php7.y:4426 { yyVAL.node = expr.NewConstFetch(yyDollar[1].node) @@ -7053,7 +7050,7 @@ yydefault: } case 415: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4438 + //line php7/php7.y:4435 { target := node.NewIdentifier(yyDollar[3].token.Value) yyVAL.node = expr.NewClassConstFetch(yyDollar[1].node, target) @@ -7070,7 +7067,7 @@ yydefault: } case 416: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4453 + //line php7/php7.y:4450 { target := node.NewIdentifier(yyDollar[3].token.Value) yyVAL.node = expr.NewClassConstFetch(yyDollar[1].node, target) @@ -7087,7 +7084,7 @@ yydefault: } case 417: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4471 + //line php7/php7.y:4468 { yyVAL.node = yyDollar[1].node @@ -7095,7 +7092,7 @@ yydefault: } case 418: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4477 + //line php7/php7.y:4474 { yyVAL.node = yyDollar[1].node @@ -7103,7 +7100,7 @@ yydefault: } case 419: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:4486 + //line php7/php7.y:4483 { yyVAL.node = nil @@ -7111,7 +7108,7 @@ yydefault: } case 420: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4492 + //line php7/php7.y:4489 { yyVAL.node = yyDollar[1].node @@ -7119,7 +7116,7 @@ yydefault: } case 421: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4501 + //line php7/php7.y:4498 { yyVAL.node = yyDollar[1].node @@ -7127,7 +7124,7 @@ yydefault: } case 422: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4510 + //line php7/php7.y:4507 { yyVAL.node = yyDollar[1].node @@ -7135,7 +7132,7 @@ yydefault: } case 423: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4516 + //line php7/php7.y:4513 { yyVAL.node = yyDollar[2].node @@ -7147,7 +7144,7 @@ yydefault: } case 424: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4526 + //line php7/php7.y:4523 { yyVAL.node = yyDollar[1].node @@ -7155,7 +7152,7 @@ yydefault: } case 425: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4535 + //line php7/php7.y:4532 { yyVAL.node = yyDollar[1].node @@ -7163,7 +7160,7 @@ yydefault: } case 426: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4541 + //line php7/php7.y:4538 { yyVAL.node = yyDollar[2].node @@ -7175,7 +7172,7 @@ yydefault: } case 427: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4551 + //line php7/php7.y:4548 { yyVAL.node = yyDollar[1].node @@ -7183,7 +7180,7 @@ yydefault: } case 428: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4560 + //line php7/php7.y:4557 { yyVAL.node = yyDollar[1].node @@ -7191,7 +7188,7 @@ yydefault: } case 429: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:4566 + //line php7/php7.y:4563 { yyVAL.node = expr.NewArrayDimFetch(yyDollar[1].node, yyDollar[3].node) @@ -7206,7 +7203,7 @@ yydefault: } case 430: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:4579 + //line php7/php7.y:4576 { yyVAL.node = expr.NewArrayDimFetch(yyDollar[1].node, yyDollar[3].node) @@ -7221,7 +7218,7 @@ yydefault: } case 431: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:4592 + //line php7/php7.y:4589 { yyVAL.node = expr.NewArrayDimFetch(yyDollar[1].node, yyDollar[3].node) @@ -7236,7 +7233,7 @@ yydefault: } case 432: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:4605 + //line php7/php7.y:4602 { yyVAL.node = expr.NewMethodCall(yyDollar[1].node, yyDollar[3].node, yyDollar[4].node.(*node.ArgumentList)) @@ -7250,7 +7247,7 @@ yydefault: } case 433: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4617 + //line php7/php7.y:4614 { yyVAL.node = yyDollar[1].node @@ -7258,7 +7255,7 @@ yydefault: } case 434: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4626 + //line php7/php7.y:4623 { yyVAL.node = yyDollar[1].node @@ -7266,7 +7263,7 @@ yydefault: } case 435: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4632 + //line php7/php7.y:4629 { yyVAL.node = yyDollar[1].node @@ -7274,7 +7271,7 @@ yydefault: } case 436: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4638 + //line php7/php7.y:4635 { yyVAL.node = expr.NewPropertyFetch(yyDollar[1].node, yyDollar[3].node) @@ -7288,7 +7285,7 @@ yydefault: } case 437: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4653 + //line php7/php7.y:4650 { name := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) yyVAL.node = expr.NewVariable(name) @@ -7304,7 +7301,7 @@ yydefault: } case 438: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:4667 + //line php7/php7.y:4664 { yyVAL.node = expr.NewVariable(yyDollar[3].node) @@ -7320,7 +7317,7 @@ yydefault: } case 439: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:4681 + //line php7/php7.y:4678 { yyVAL.node = expr.NewVariable(yyDollar[2].node) @@ -7334,7 +7331,7 @@ yydefault: } case 440: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4696 + //line php7/php7.y:4693 { yyVAL.node = expr.NewStaticPropertyFetch(yyDollar[1].node, yyDollar[3].node) @@ -7348,7 +7345,7 @@ yydefault: } case 441: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4708 + //line php7/php7.y:4705 { yyVAL.node = expr.NewStaticPropertyFetch(yyDollar[1].node, yyDollar[3].node) @@ -7362,7 +7359,7 @@ yydefault: } case 442: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4723 + //line php7/php7.y:4720 { yyVAL.node = yyDollar[1].node @@ -7370,7 +7367,7 @@ yydefault: } case 443: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:4729 + //line php7/php7.y:4726 { yyVAL.node = expr.NewArrayDimFetch(yyDollar[1].node, yyDollar[3].node) @@ -7385,7 +7382,7 @@ yydefault: } case 444: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:4742 + //line php7/php7.y:4739 { yyVAL.node = expr.NewArrayDimFetch(yyDollar[1].node, yyDollar[3].node) @@ -7400,7 +7397,7 @@ yydefault: } case 445: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4755 + //line php7/php7.y:4752 { yyVAL.node = expr.NewPropertyFetch(yyDollar[1].node, yyDollar[3].node) @@ -7414,7 +7411,7 @@ yydefault: } case 446: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4767 + //line php7/php7.y:4764 { yyVAL.node = expr.NewStaticPropertyFetch(yyDollar[1].node, yyDollar[3].node) @@ -7428,7 +7425,7 @@ yydefault: } case 447: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4779 + //line php7/php7.y:4776 { yyVAL.node = expr.NewStaticPropertyFetch(yyDollar[1].node, yyDollar[3].node) @@ -7442,7 +7439,7 @@ yydefault: } case 448: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4794 + //line php7/php7.y:4791 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -7456,7 +7453,7 @@ yydefault: } case 449: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4806 + //line php7/php7.y:4803 { yyVAL.node = yyDollar[2].node @@ -7468,7 +7465,7 @@ yydefault: } case 450: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4816 + //line php7/php7.y:4813 { yyVAL.node = yyDollar[1].node @@ -7476,7 +7473,7 @@ yydefault: } case 451: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4825 + //line php7/php7.y:4822 { yyVAL.node = node.NewIdentifier(yyDollar[1].token.Value) @@ -7484,13 +7481,14 @@ yydefault: yyVAL.node.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition(yyDollar[1].token)) // save comments - addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.StringToken) + spew.Dump(yyDollar[1].token.Meta) + addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 452: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4837 + //line php7/php7.y:4835 { yyVAL.node = yyDollar[2].node @@ -7502,7 +7500,7 @@ yydefault: } case 453: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4847 + //line php7/php7.y:4845 { yyVAL.node = yyDollar[1].node @@ -7510,7 +7508,7 @@ yydefault: } case 454: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4856 + //line php7/php7.y:4854 { yyVAL.list = yyDollar[1].list @@ -7518,7 +7516,7 @@ yydefault: } case 455: yyDollar = yyS[yypt-0 : yypt+1] - //line php7/php7.y:4865 + //line php7/php7.y:4863 { yyVAL.node = expr.NewArrayItem(nil, nil) @@ -7526,7 +7524,7 @@ yydefault: } case 456: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4871 + //line php7/php7.y:4869 { yyVAL.node = yyDollar[1].node @@ -7534,7 +7532,7 @@ yydefault: } case 457: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4880 + //line php7/php7.y:4878 { if len(yyDollar[1].list) == 0 { yyDollar[1].list = []node.Node{expr.NewArrayItem(nil, nil)} @@ -7543,13 +7541,13 @@ yydefault: yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 458: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4893 + //line php7/php7.y:4891 { if yyDollar[1].node.(*expr.ArrayItem).Key == nil && yyDollar[1].node.(*expr.ArrayItem).Val == nil { yyVAL.list = []node.Node{} @@ -7561,7 +7559,7 @@ yydefault: } case 459: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:4906 + //line php7/php7.y:4904 { yyVAL.node = expr.NewArrayItem(yyDollar[1].node, yyDollar[3].node) @@ -7575,7 +7573,7 @@ yydefault: } case 460: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:4918 + //line php7/php7.y:4916 { yyVAL.node = expr.NewArrayItem(nil, yyDollar[1].node) @@ -7586,7 +7584,7 @@ yydefault: } case 461: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:4927 + //line php7/php7.y:4925 { reference := expr.NewReference(yyDollar[4].node) yyVAL.node = expr.NewArrayItem(yyDollar[1].node, reference) @@ -7603,7 +7601,7 @@ yydefault: } case 462: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:4942 + //line php7/php7.y:4940 { reference := expr.NewReference(yyDollar[2].node) yyVAL.node = expr.NewArrayItem(nil, reference) @@ -7619,7 +7617,7 @@ yydefault: } case 463: yyDollar = yyS[yypt-6 : yypt+1] - //line php7/php7.y:4956 + //line php7/php7.y:4954 { // TODO: Cannot use list() as standalone expression list := expr.NewList(yyDollar[5].list) @@ -7639,7 +7637,7 @@ yydefault: } case 464: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:4974 + //line php7/php7.y:4972 { // TODO: Cannot use list() as standalone expression list := expr.NewList(yyDollar[3].list) @@ -7658,7 +7656,7 @@ yydefault: } case 465: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:4994 + //line php7/php7.y:4992 { yyVAL.list = append(yyDollar[1].list, yyDollar[2].node) @@ -7666,7 +7664,7 @@ yydefault: } case 466: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:5000 + //line php7/php7.y:4998 { encapsed := scalar.NewEncapsedStringPart(yyDollar[2].token.Value) yyVAL.list = append(yyDollar[1].list, encapsed) @@ -7681,7 +7679,7 @@ yydefault: } case 467: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:5013 + //line php7/php7.y:5011 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -7689,7 +7687,7 @@ yydefault: } case 468: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:5019 + //line php7/php7.y:5017 { encapsed := scalar.NewEncapsedStringPart(yyDollar[1].token.Value) yyVAL.list = []node.Node{encapsed, yyDollar[2].node} @@ -7704,7 +7702,7 @@ yydefault: } case 469: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:5035 + //line php7/php7.y:5033 { name := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) yyVAL.node = expr.NewVariable(name) @@ -7720,7 +7718,7 @@ yydefault: } case 470: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:5049 + //line php7/php7.y:5047 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -7740,7 +7738,7 @@ yydefault: } case 471: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:5067 + //line php7/php7.y:5065 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) variable := expr.NewVariable(identifier) @@ -7756,13 +7754,13 @@ yydefault: // save comments addMeta(variable, yyDollar[1].token.Meta, meta.VariableToken) addMeta(yyVAL.node, yyDollar[2].token.Meta, meta.ObjectOperatorToken) - addMeta(fetch, yyDollar[3].token.Meta, meta.StringToken) + addMeta(fetch, yyDollar[3].token.Meta, meta.IdentifierToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 472: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:5087 + //line php7/php7.y:5085 { yyVAL.node = expr.NewVariable(yyDollar[2].node) @@ -7777,7 +7775,7 @@ yydefault: } case 473: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:5100 + //line php7/php7.y:5098 { name := node.NewIdentifier(yyDollar[2].token.Value) yyVAL.node = expr.NewVariable(name) @@ -7788,14 +7786,14 @@ yydefault: // save comments addMeta(yyVAL.node, yyDollar[1].token.Meta, meta.DollarOpenCurlyBracesToken) - addMeta(name, yyDollar[2].token.Meta, meta.StringVarnameToken) + addMeta(name, yyDollar[2].token.Meta, meta.IdentifierToken) addMeta(yyVAL.node, yyDollar[3].token.Meta, meta.CloseCurlyBracesToken) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 474: yyDollar = yyS[yypt-6 : yypt+1] - //line php7/php7.y:5116 + //line php7/php7.y:5114 { identifier := node.NewIdentifier(yyDollar[2].token.Value) variable := expr.NewVariable(identifier) @@ -7817,7 +7815,7 @@ yydefault: } case 475: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:5136 + //line php7/php7.y:5134 { yyVAL.node = yyDollar[2].node @@ -7825,7 +7823,7 @@ yydefault: } case 476: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:5145 + //line php7/php7.y:5143 { yyVAL.node = scalar.NewString(yyDollar[1].token.Value) @@ -7839,7 +7837,7 @@ yydefault: } case 477: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:5157 + //line php7/php7.y:5155 { // TODO: add option to handle 64 bit integer if _, err := strconv.Atoi(yyDollar[1].token.Value); err == nil { @@ -7858,7 +7856,7 @@ yydefault: } case 478: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:5174 + //line php7/php7.y:5172 { var lnumber *scalar.Lnumber // TODO: add option to handle 64 bit integer @@ -7891,7 +7889,7 @@ yydefault: } case 479: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:5205 + //line php7/php7.y:5203 { identifier := node.NewIdentifier(strings.TrimLeftFunc(yyDollar[1].token.Value, isDollar)) yyVAL.node = expr.NewVariable(identifier) @@ -7907,7 +7905,7 @@ yydefault: } case 480: yyDollar = yyS[yypt-5 : yypt+1] - //line php7/php7.y:5222 + //line php7/php7.y:5220 { yyVAL.node = expr.NewIsset(yyDollar[3].list) @@ -7926,7 +7924,7 @@ yydefault: } case 481: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:5239 + //line php7/php7.y:5237 { yyVAL.node = expr.NewEmpty(yyDollar[3].node) @@ -7942,7 +7940,7 @@ yydefault: } case 482: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:5253 + //line php7/php7.y:5251 { yyVAL.node = expr.NewInclude(yyDollar[2].node) @@ -7956,7 +7954,7 @@ yydefault: } case 483: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:5265 + //line php7/php7.y:5263 { yyVAL.node = expr.NewIncludeOnce(yyDollar[2].node) @@ -7970,7 +7968,7 @@ yydefault: } case 484: yyDollar = yyS[yypt-4 : yypt+1] - //line php7/php7.y:5277 + //line php7/php7.y:5275 { yyVAL.node = expr.NewEval(yyDollar[3].node) @@ -7986,7 +7984,7 @@ yydefault: } case 485: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:5291 + //line php7/php7.y:5289 { yyVAL.node = expr.NewRequire(yyDollar[2].node) @@ -8000,7 +7998,7 @@ yydefault: } case 486: yyDollar = yyS[yypt-2 : yypt+1] - //line php7/php7.y:5303 + //line php7/php7.y:5301 { yyVAL.node = expr.NewRequireOnce(yyDollar[2].node) @@ -8014,7 +8012,7 @@ yydefault: } case 487: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:5318 + //line php7/php7.y:5316 { yyVAL.list = []node.Node{yyDollar[1].node} @@ -8022,18 +8020,18 @@ yydefault: } case 488: yyDollar = yyS[yypt-3 : yypt+1] - //line php7/php7.y:5324 + //line php7/php7.y:5322 { yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) // save comments - addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.CommaToken) + addMeta(lastNode(yyDollar[1].list), yyDollar[2].token.Meta, meta.NodeEnd) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } case 489: yyDollar = yyS[yypt-1 : yypt+1] - //line php7/php7.y:5336 + //line php7/php7.y:5334 { yyVAL.node = yyDollar[1].node diff --git a/php7/php7.y b/php7/php7.y index bc6c4bd..8b90edc 100644 --- a/php7/php7.y +++ b/php7/php7.y @@ -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) } diff --git a/php7/php7_test.go b/php7/php7_test.go index 9dc3546..74645fb 100644 --- a/php7/php7_test.go +++ b/php7/php7_test.go @@ -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, diff --git a/printer/pretty_printer.go b/printer/pretty_printer.go new file mode 100644 index 0000000..9fd17e6 --- /dev/null +++ b/printer/pretty_printer.go @@ -0,0 +1,2182 @@ +package printer + +import ( + "io" + "strings" + + "github.com/z7zmey/php-parser/node/stmt" + + "github.com/z7zmey/php-parser/node" + "github.com/z7zmey/php-parser/node/expr" + "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/z7zmey/php-parser/node/name" + "github.com/z7zmey/php-parser/node/scalar" +) + +type PrettyPrinter struct { + w io.Writer + indentStr string + indentDepth int +} + +// NewPrettyPrinter - Constructor for PrettyPrinter +func NewPrettyPrinter(w io.Writer, indentStr string) *PrettyPrinter { + return &PrettyPrinter{ + w: w, + indentStr: indentStr, + indentDepth: 0, + } +} + +func (p *PrettyPrinter) Print(n node.Node) { + p.printNode(n) +} + +func (p *PrettyPrinter) joinPrint(glue string, nn []node.Node) { + for k, n := range nn { + if k > 0 { + io.WriteString(p.w, glue) + } + + p.Print(n) + } +} + +func (p *PrettyPrinter) printNodes(nn []node.Node) { + p.indentDepth++ + l := len(nn) - 1 + for k, n := range nn { + p.printIndent() + p.Print(n) + if k < l { + io.WriteString(p.w, "\n") + } + } + p.indentDepth-- +} + +func (p *PrettyPrinter) printIndent() { + for i := 0; i < p.indentDepth; i++ { + io.WriteString(p.w, p.indentStr) + } +} + +func (p *PrettyPrinter) printNode(n node.Node) { + switch n.(type) { + + // node + + case *node.Root: + p.printNodeRoot(n) + case *node.Identifier: + p.printNodeIdentifier(n) + case *node.Parameter: + p.printNodeParameter(n) + case *node.Nullable: + p.printNodeNullable(n) + case *node.Argument: + p.printNodeArgument(n) + + // name + + case *name.NamePart: + p.printNameNamePart(n) + case *name.Name: + p.printNameName(n) + case *name.FullyQualified: + p.printNameFullyQualified(n) + case *name.Relative: + p.printNameRelative(n) + + // scalar + + case *scalar.Lnumber: + p.printScalarLNumber(n) + case *scalar.Dnumber: + p.printScalarDNumber(n) + case *scalar.String: + p.printScalarString(n) + case *scalar.EncapsedStringPart: + p.printScalarEncapsedStringPart(n) + case *scalar.Encapsed: + p.printScalarEncapsed(n) + case *scalar.Heredoc: + p.printScalarHeredoc(n) + case *scalar.MagicConstant: + p.printScalarMagicConstant(n) + + // assign + + case *assign.Assign: + p.printAssign(n) + case *assign.Reference: + p.printReference(n) + case *assign.BitwiseAnd: + p.printAssignBitwiseAnd(n) + case *assign.BitwiseOr: + p.printAssignBitwiseOr(n) + case *assign.BitwiseXor: + p.printAssignBitwiseXor(n) + case *assign.Concat: + p.printAssignConcat(n) + case *assign.Div: + p.printAssignDiv(n) + case *assign.Minus: + p.printAssignMinus(n) + case *assign.Mod: + p.printAssignMod(n) + case *assign.Mul: + p.printAssignMul(n) + case *assign.Plus: + p.printAssignPlus(n) + case *assign.Pow: + p.printAssignPow(n) + case *assign.ShiftLeft: + p.printAssignShiftLeft(n) + case *assign.ShiftRight: + p.printAssignShiftRight(n) + + // binary + + case *binary.BitwiseAnd: + p.printBinaryBitwiseAnd(n) + case *binary.BitwiseOr: + p.printBinaryBitwiseOr(n) + case *binary.BitwiseXor: + p.printBinaryBitwiseXor(n) + case *binary.BooleanAnd: + p.printBinaryBooleanAnd(n) + case *binary.BooleanOr: + p.printBinaryBooleanOr(n) + case *binary.Coalesce: + p.printBinaryCoalesce(n) + case *binary.Concat: + p.printBinaryConcat(n) + case *binary.Div: + p.printBinaryDiv(n) + case *binary.Equal: + p.printBinaryEqual(n) + case *binary.GreaterOrEqual: + p.printBinaryGreaterOrEqual(n) + case *binary.Greater: + p.printBinaryGreater(n) + case *binary.Identical: + p.printBinaryIdentical(n) + case *binary.LogicalAnd: + p.printBinaryLogicalAnd(n) + case *binary.LogicalOr: + p.printBinaryLogicalOr(n) + case *binary.LogicalXor: + p.printBinaryLogicalXor(n) + case *binary.Minus: + p.printBinaryMinus(n) + case *binary.Mod: + p.printBinaryMod(n) + case *binary.Mul: + p.printBinaryMul(n) + case *binary.NotEqual: + p.printBinaryNotEqual(n) + case *binary.NotIdentical: + p.printBinaryNotIdentical(n) + case *binary.Plus: + p.printBinaryPlus(n) + case *binary.Pow: + p.printBinaryPow(n) + case *binary.ShiftLeft: + p.printBinaryShiftLeft(n) + case *binary.ShiftRight: + p.printBinaryShiftRight(n) + case *binary.SmallerOrEqual: + p.printBinarySmallerOrEqual(n) + case *binary.Smaller: + p.printBinarySmaller(n) + case *binary.Spaceship: + p.printBinarySpaceship(n) + + // cast + + case *cast.Array: + p.printArray(n) + case *cast.Bool: + p.printBool(n) + case *cast.Double: + p.printDouble(n) + case *cast.Int: + p.printInt(n) + case *cast.Object: + p.printObject(n) + case *cast.String: + p.printString(n) + case *cast.Unset: + p.printUnset(n) + + // expr + + case *expr.ArrayDimFetch: + p.printExprArrayDimFetch(n) + case *expr.ArrayItem: + p.printExprArrayItem(n) + case *expr.Array: + p.printExprArray(n) + case *expr.BitwiseNot: + p.printExprBitwiseNot(n) + case *expr.BooleanNot: + p.printExprBooleanNot(n) + case *expr.ClassConstFetch: + p.printExprClassConstFetch(n) + case *expr.Clone: + p.printExprClone(n) + case *expr.ClosureUse: + p.printExprClosureUse(n) + case *expr.Closure: + p.printExprClosure(n) + case *expr.ConstFetch: + p.printExprConstFetch(n) + case *expr.Die: + p.printExprDie(n) + case *expr.Empty: + p.printExprEmpty(n) + case *expr.ErrorSuppress: + p.printExprErrorSuppress(n) + case *expr.Eval: + p.printExprEval(n) + case *expr.Exit: + p.printExprExit(n) + case *expr.FunctionCall: + p.printExprFunctionCall(n) + case *expr.Include: + p.printExprInclude(n) + case *expr.IncludeOnce: + p.printExprIncludeOnce(n) + case *expr.InstanceOf: + p.printExprInstanceOf(n) + case *expr.Isset: + p.printExprIsset(n) + case *expr.List: + p.printExprList(n) + case *expr.MethodCall: + p.printExprMethodCall(n) + case *expr.New: + p.printExprNew(n) + case *expr.PostDec: + p.printExprPostDec(n) + case *expr.PostInc: + p.printExprPostInc(n) + case *expr.PreDec: + p.printExprPreDec(n) + case *expr.PreInc: + p.printExprPreInc(n) + case *expr.Print: + p.printExprPrint(n) + case *expr.PropertyFetch: + p.printExprPropertyFetch(n) + case *expr.Reference: + p.printExprReference(n) + case *expr.Require: + p.printExprRequire(n) + case *expr.RequireOnce: + p.printExprRequireOnce(n) + case *expr.ShellExec: + p.printExprShellExec(n) + case *expr.ShortArray: + p.printExprShortArray(n) + case *expr.ShortList: + p.printExprShortList(n) + case *expr.StaticCall: + p.printExprStaticCall(n) + case *expr.StaticPropertyFetch: + p.printExprStaticPropertyFetch(n) + case *expr.Ternary: + p.printExprTernary(n) + case *expr.UnaryMinus: + p.printExprUnaryMinus(n) + case *expr.UnaryPlus: + p.printExprUnaryPlus(n) + case *expr.Variable: + p.printExprVariable(n) + case *expr.YieldFrom: + p.printExprYieldFrom(n) + case *expr.Yield: + p.printExprYield(n) + + // stmt + + case *stmt.AltElseIf: + p.printStmtAltElseIf(n) + case *stmt.AltElse: + p.printStmtAltElse(n) + case *stmt.AltFor: + p.printStmtAltFor(n) + case *stmt.AltForeach: + p.printStmtAltForeach(n) + case *stmt.AltIf: + p.printStmtAltIf(n) + case *stmt.AltSwitch: + p.printStmtAltSwitch(n) + case *stmt.AltWhile: + p.printStmtAltWhile(n) + case *stmt.Break: + p.printStmtBreak(n) + case *stmt.Case: + p.printStmtCase(n) + case *stmt.Catch: + p.printStmtCatch(n) + case *stmt.ClassMethod: + p.printStmtClassMethod(n) + case *stmt.Class: + p.printStmtClass(n) + case *stmt.ClassConstList: + p.printStmtClassConstList(n) + case *stmt.Constant: + p.printStmtConstant(n) + case *stmt.Continue: + p.printStmtContinue(n) + case *stmt.Declare: + p.printStmtDeclare(n) + case *stmt.Default: + p.printStmtDefault(n) + case *stmt.Do: + p.printStmtDo(n) + case *stmt.Echo: + p.printStmtEcho(n) + case *stmt.ElseIf: + p.printStmtElseif(n) + case *stmt.Else: + p.printStmtElse(n) + case *stmt.Expression: + p.printStmtExpression(n) + case *stmt.Finally: + p.printStmtFinally(n) + case *stmt.For: + p.printStmtFor(n) + case *stmt.Foreach: + p.printStmtForeach(n) + case *stmt.Function: + p.printStmtFunction(n) + case *stmt.Global: + p.printStmtGlobal(n) + case *stmt.Goto: + p.printStmtGoto(n) + case *stmt.GroupUse: + p.printStmtGroupUse(n) + case *stmt.HaltCompiler: + p.printStmtHaltCompiler(n) + case *stmt.If: + p.printStmtIf(n) + case *stmt.InlineHtml: + p.printStmtInlineHTML(n) + case *stmt.Interface: + p.printStmtInterface(n) + case *stmt.Label: + p.printStmtLabel(n) + case *stmt.Namespace: + p.printStmtNamespace(n) + case *stmt.Nop: + p.printStmtNop(n) + case *stmt.PropertyList: + p.printStmtPropertyList(n) + case *stmt.Property: + p.printStmtProperty(n) + case *stmt.Return: + p.printStmtReturn(n) + case *stmt.StaticVar: + p.printStmtStaticVar(n) + case *stmt.Static: + p.printStmtStatic(n) + case *stmt.StmtList: + p.printStmtStmtList(n) + case *stmt.Switch: + p.printStmtSwitch(n) + case *stmt.Throw: + p.printStmtThrow(n) + case *stmt.TraitMethodRef: + p.printStmtTraitMethodRef(n) + case *stmt.TraitUseAlias: + p.printStmtTraitUseAlias(n) + case *stmt.TraitUsePrecedence: + p.printStmtTraitUsePrecedence(n) + case *stmt.TraitUse: + p.printStmtTraitUse(n) + case *stmt.Trait: + p.printStmtTrait(n) + case *stmt.Try: + p.printStmtTry(n) + case *stmt.Unset: + p.printStmtUnset(n) + case *stmt.UseList: + p.printStmtUseList(n) + case *stmt.Use: + p.printStmtUse(n) + case *stmt.While: + p.printStmtWhile(n) + } +} + +// node + +func (p *PrettyPrinter) printNodeRoot(n node.Node) { + v := n.(*node.Root) + + if len(v.Stmts) > 0 { + firstStmt := v.Stmts[0] + v.Stmts = v.Stmts[1:] + + switch fs := firstStmt.(type) { + case *stmt.InlineHtml: + io.WriteString(p.w, fs.Value) + io.WriteString(p.w, " 0 { + io.WriteString(p.w, "\\") + } + + p.Print(part) + } +} + +func (p *PrettyPrinter) printNameFullyQualified(n node.Node) { + nn := n.(*name.FullyQualified) + + for _, part := range nn.Parts { + io.WriteString(p.w, "\\") + p.Print(part) + } +} + +func (p *PrettyPrinter) printNameRelative(n node.Node) { + nn := n.(*name.Relative) + + io.WriteString(p.w, "namespace") + for _, part := range nn.Parts { + io.WriteString(p.w, "\\") + p.Print(part) + } +} + +// scalar + +func (p *PrettyPrinter) printScalarLNumber(n node.Node) { + v := n.(*scalar.Lnumber).Value + io.WriteString(p.w, v) +} + +func (p *PrettyPrinter) printScalarDNumber(n node.Node) { + v := n.(*scalar.Dnumber).Value + io.WriteString(p.w, v) +} + +func (p *PrettyPrinter) printScalarString(n node.Node) { + v := n.(*scalar.String).Value + + io.WriteString(p.w, v) +} + +func (p *PrettyPrinter) printScalarEncapsedStringPart(n node.Node) { + v := n.(*scalar.EncapsedStringPart).Value + io.WriteString(p.w, v) +} + +func (p *PrettyPrinter) printScalarEncapsed(n node.Node) { + io.WriteString(p.w, "\"") + + for _, nn := range n.(*scalar.Encapsed).Parts { + p.Print(nn) + } + + io.WriteString(p.w, "\"") +} + +func (p *PrettyPrinter) printScalarHeredoc(n node.Node) { + nn := n.(*scalar.Heredoc) + + io.WriteString(p.w, "<<<") + io.WriteString(p.w, nn.Label) + io.WriteString(p.w, "\n") + + for _, nn := range nn.Parts { + p.Print(nn) + } + + io.WriteString(p.w, strings.Trim(nn.Label, "\"'")) +} + +func (p *PrettyPrinter) printScalarMagicConstant(n node.Node) { + v := n.(*scalar.MagicConstant).Value + io.WriteString(p.w, v) +} + +// Assign + +func (p *PrettyPrinter) printAssign(n node.Node) { + nn := n.(*assign.Assign) + p.Print(nn.Variable) + io.WriteString(p.w, " = ") + p.Print(nn.Expression) +} + +func (p *PrettyPrinter) printReference(n node.Node) { + nn := n.(*assign.Reference) + p.Print(nn.Variable) + io.WriteString(p.w, " =& ") + p.Print(nn.Expression) +} + +func (p *PrettyPrinter) printAssignBitwiseAnd(n node.Node) { + nn := n.(*assign.BitwiseAnd) + p.Print(nn.Variable) + io.WriteString(p.w, " &= ") + p.Print(nn.Expression) +} + +func (p *PrettyPrinter) printAssignBitwiseOr(n node.Node) { + nn := n.(*assign.BitwiseOr) + p.Print(nn.Variable) + io.WriteString(p.w, " |= ") + p.Print(nn.Expression) +} + +func (p *PrettyPrinter) printAssignBitwiseXor(n node.Node) { + nn := n.(*assign.BitwiseXor) + p.Print(nn.Variable) + io.WriteString(p.w, " ^= ") + p.Print(nn.Expression) +} + +func (p *PrettyPrinter) printAssignConcat(n node.Node) { + nn := n.(*assign.Concat) + p.Print(nn.Variable) + io.WriteString(p.w, " .= ") + p.Print(nn.Expression) +} + +func (p *PrettyPrinter) printAssignDiv(n node.Node) { + nn := n.(*assign.Div) + p.Print(nn.Variable) + io.WriteString(p.w, " /= ") + p.Print(nn.Expression) +} + +func (p *PrettyPrinter) printAssignMinus(n node.Node) { + nn := n.(*assign.Minus) + p.Print(nn.Variable) + io.WriteString(p.w, " -= ") + p.Print(nn.Expression) +} + +func (p *PrettyPrinter) printAssignMod(n node.Node) { + nn := n.(*assign.Mod) + p.Print(nn.Variable) + io.WriteString(p.w, " %= ") + p.Print(nn.Expression) +} + +func (p *PrettyPrinter) printAssignMul(n node.Node) { + nn := n.(*assign.Mul) + p.Print(nn.Variable) + io.WriteString(p.w, " *= ") + p.Print(nn.Expression) +} + +func (p *PrettyPrinter) printAssignPlus(n node.Node) { + nn := n.(*assign.Plus) + p.Print(nn.Variable) + io.WriteString(p.w, " += ") + p.Print(nn.Expression) +} + +func (p *PrettyPrinter) printAssignPow(n node.Node) { + nn := n.(*assign.Pow) + p.Print(nn.Variable) + io.WriteString(p.w, " **= ") + p.Print(nn.Expression) +} + +func (p *PrettyPrinter) printAssignShiftLeft(n node.Node) { + nn := n.(*assign.ShiftLeft) + p.Print(nn.Variable) + io.WriteString(p.w, " <<= ") + p.Print(nn.Expression) +} + +func (p *PrettyPrinter) printAssignShiftRight(n node.Node) { + nn := n.(*assign.ShiftRight) + p.Print(nn.Variable) + io.WriteString(p.w, " >>= ") + p.Print(nn.Expression) +} + +// binary + +func (p *PrettyPrinter) printBinaryBitwiseAnd(n node.Node) { + nn := n.(*binary.BitwiseAnd) + + p.Print(nn.Left) + io.WriteString(p.w, " & ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryBitwiseOr(n node.Node) { + nn := n.(*binary.BitwiseOr) + + p.Print(nn.Left) + io.WriteString(p.w, " | ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryBitwiseXor(n node.Node) { + nn := n.(*binary.BitwiseXor) + + p.Print(nn.Left) + io.WriteString(p.w, " ^ ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryBooleanAnd(n node.Node) { + nn := n.(*binary.BooleanAnd) + + p.Print(nn.Left) + io.WriteString(p.w, " && ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryBooleanOr(n node.Node) { + nn := n.(*binary.BooleanOr) + + p.Print(nn.Left) + io.WriteString(p.w, " || ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryCoalesce(n node.Node) { + nn := n.(*binary.Coalesce) + + p.Print(nn.Left) + io.WriteString(p.w, " ?? ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryConcat(n node.Node) { + nn := n.(*binary.Concat) + + p.Print(nn.Left) + io.WriteString(p.w, " . ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryDiv(n node.Node) { + nn := n.(*binary.Div) + + p.Print(nn.Left) + io.WriteString(p.w, " / ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryEqual(n node.Node) { + nn := n.(*binary.Equal) + + p.Print(nn.Left) + io.WriteString(p.w, " == ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryGreaterOrEqual(n node.Node) { + nn := n.(*binary.GreaterOrEqual) + + p.Print(nn.Left) + io.WriteString(p.w, " >= ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryGreater(n node.Node) { + nn := n.(*binary.Greater) + + p.Print(nn.Left) + io.WriteString(p.w, " > ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryIdentical(n node.Node) { + nn := n.(*binary.Identical) + + p.Print(nn.Left) + io.WriteString(p.w, " === ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryLogicalAnd(n node.Node) { + nn := n.(*binary.LogicalAnd) + + p.Print(nn.Left) + io.WriteString(p.w, " and ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryLogicalOr(n node.Node) { + nn := n.(*binary.LogicalOr) + + p.Print(nn.Left) + io.WriteString(p.w, " or ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryLogicalXor(n node.Node) { + nn := n.(*binary.LogicalXor) + + p.Print(nn.Left) + io.WriteString(p.w, " xor ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryMinus(n node.Node) { + nn := n.(*binary.Minus) + + p.Print(nn.Left) + io.WriteString(p.w, " - ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryMod(n node.Node) { + nn := n.(*binary.Mod) + + p.Print(nn.Left) + io.WriteString(p.w, " % ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryMul(n node.Node) { + nn := n.(*binary.Mul) + + p.Print(nn.Left) + io.WriteString(p.w, " * ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryNotEqual(n node.Node) { + nn := n.(*binary.NotEqual) + + p.Print(nn.Left) + io.WriteString(p.w, " != ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryNotIdentical(n node.Node) { + nn := n.(*binary.NotIdentical) + + p.Print(nn.Left) + io.WriteString(p.w, " !== ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryPlus(n node.Node) { + nn := n.(*binary.Plus) + + p.Print(nn.Left) + io.WriteString(p.w, " + ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryPow(n node.Node) { + nn := n.(*binary.Pow) + + p.Print(nn.Left) + io.WriteString(p.w, " ** ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryShiftLeft(n node.Node) { + nn := n.(*binary.ShiftLeft) + + p.Print(nn.Left) + io.WriteString(p.w, " << ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinaryShiftRight(n node.Node) { + nn := n.(*binary.ShiftRight) + + p.Print(nn.Left) + io.WriteString(p.w, " >> ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinarySmallerOrEqual(n node.Node) { + nn := n.(*binary.SmallerOrEqual) + + p.Print(nn.Left) + io.WriteString(p.w, " <= ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinarySmaller(n node.Node) { + nn := n.(*binary.Smaller) + + p.Print(nn.Left) + io.WriteString(p.w, " < ") + p.Print(nn.Right) +} + +func (p *PrettyPrinter) printBinarySpaceship(n node.Node) { + nn := n.(*binary.Spaceship) + + p.Print(nn.Left) + io.WriteString(p.w, " <=> ") + p.Print(nn.Right) +} + +// cast + +func (p *PrettyPrinter) printArray(n node.Node) { + nn := n.(*cast.Array) + + io.WriteString(p.w, "(array)") + p.Print(nn.Expr) +} + +func (p *PrettyPrinter) printBool(n node.Node) { + nn := n.(*cast.Bool) + + io.WriteString(p.w, "(bool)") + p.Print(nn.Expr) +} + +func (p *PrettyPrinter) printDouble(n node.Node) { + nn := n.(*cast.Double) + + io.WriteString(p.w, "(float)") + p.Print(nn.Expr) +} + +func (p *PrettyPrinter) printInt(n node.Node) { + nn := n.(*cast.Int) + + io.WriteString(p.w, "(int)") + p.Print(nn.Expr) +} + +func (p *PrettyPrinter) printObject(n node.Node) { + nn := n.(*cast.Object) + + io.WriteString(p.w, "(object)") + p.Print(nn.Expr) +} + +func (p *PrettyPrinter) printString(n node.Node) { + nn := n.(*cast.String) + + io.WriteString(p.w, "(string)") + p.Print(nn.Expr) +} + +func (p *PrettyPrinter) printUnset(n node.Node) { + nn := n.(*cast.Unset) + + io.WriteString(p.w, "(unset)") + p.Print(nn.Expr) +} + +// expr + +func (p *PrettyPrinter) printExprArrayDimFetch(n node.Node) { + nn := n.(*expr.ArrayDimFetch) + p.Print(nn.Variable) + io.WriteString(p.w, "[") + p.Print(nn.Dim) + io.WriteString(p.w, "]") +} + +func (p *PrettyPrinter) printExprArrayItem(n node.Node) { + nn := n.(*expr.ArrayItem) + + if nn.Key != nil { + p.Print(nn.Key) + io.WriteString(p.w, " => ") + } + + p.Print(nn.Val) +} + +func (p *PrettyPrinter) printExprArray(n node.Node) { + nn := n.(*expr.Array) + + io.WriteString(p.w, "array(") + p.joinPrint(", ", nn.Items) + io.WriteString(p.w, ")") +} + +func (p *PrettyPrinter) printExprBitwiseNot(n node.Node) { + nn := n.(*expr.BitwiseNot) + io.WriteString(p.w, "~") + p.Print(nn.Expr) +} + +func (p *PrettyPrinter) printExprBooleanNot(n node.Node) { + nn := n.(*expr.BooleanNot) + io.WriteString(p.w, "!") + p.Print(nn.Expr) +} + +func (p *PrettyPrinter) printExprClassConstFetch(n node.Node) { + nn := n.(*expr.ClassConstFetch) + + p.Print(nn.Class) + io.WriteString(p.w, "::") + io.WriteString(p.w, nn.ConstantName.(*node.Identifier).Value) +} + +func (p *PrettyPrinter) printExprClone(n node.Node) { + nn := n.(*expr.Clone) + + io.WriteString(p.w, "clone ") + p.Print(nn.Expr) +} + +func (p *PrettyPrinter) printExprClosureUse(n node.Node) { + nn := n.(*expr.ClosureUse) + + io.WriteString(p.w, "use (") + p.joinPrint(", ", nn.Uses) + io.WriteString(p.w, ")") +} + +func (p *PrettyPrinter) printExprClosure(n node.Node) { + nn := n.(*expr.Closure) + + if nn.Static { + io.WriteString(p.w, "static ") + } + + io.WriteString(p.w, "function ") + + if nn.ReturnsRef { + io.WriteString(p.w, "&") + } + + io.WriteString(p.w, "(") + p.joinPrint(", ", nn.Params) + io.WriteString(p.w, ")") + + if nn.ClosureUse != nil { + io.WriteString(p.w, " ") + p.Print(nn.ClosureUse) + } + + if nn.ReturnType != nil { + io.WriteString(p.w, ": ") + p.Print(nn.ReturnType) + } + + io.WriteString(p.w, " {\n") + p.printNodes(nn.Stmts) + io.WriteString(p.w, "\n") + p.printIndent() + io.WriteString(p.w, "}") +} + +func (p *PrettyPrinter) printExprConstFetch(n node.Node) { + nn := n.(*expr.ConstFetch) + + p.Print(nn.Constant) +} + +func (p *PrettyPrinter) printExprDie(n node.Node) { + nn := n.(*expr.Die) + + io.WriteString(p.w, "die(") + p.Print(nn.Expr) + io.WriteString(p.w, ")") +} + +func (p *PrettyPrinter) printExprEmpty(n node.Node) { + nn := n.(*expr.Empty) + + io.WriteString(p.w, "empty(") + p.Print(nn.Expr) + io.WriteString(p.w, ")") +} + +func (p *PrettyPrinter) printExprErrorSuppress(n node.Node) { + nn := n.(*expr.ErrorSuppress) + + io.WriteString(p.w, "@") + p.Print(nn.Expr) +} + +func (p *PrettyPrinter) printExprEval(n node.Node) { + nn := n.(*expr.Eval) + + io.WriteString(p.w, "eval(") + p.Print(nn.Expr) + io.WriteString(p.w, ")") +} + +func (p *PrettyPrinter) printExprExit(n node.Node) { + nn := n.(*expr.Exit) + + io.WriteString(p.w, "exit(") + p.Print(nn.Expr) + io.WriteString(p.w, ")") +} + +func (p *PrettyPrinter) printExprFunctionCall(n node.Node) { + nn := n.(*expr.FunctionCall) + + p.Print(nn.Function) + io.WriteString(p.w, "(") + p.joinPrint(", ", nn.ArgumentList.Arguments) + io.WriteString(p.w, ")") +} + +func (p *PrettyPrinter) printExprInclude(n node.Node) { + nn := n.(*expr.Include) + + io.WriteString(p.w, "include ") + p.Print(nn.Expr) +} + +func (p *PrettyPrinter) printExprIncludeOnce(n node.Node) { + nn := n.(*expr.IncludeOnce) + + io.WriteString(p.w, "include_once ") + p.Print(nn.Expr) +} + +func (p *PrettyPrinter) printExprInstanceOf(n node.Node) { + nn := n.(*expr.InstanceOf) + + p.Print(nn.Expr) + io.WriteString(p.w, " instanceof ") + p.Print(nn.Class) +} + +func (p *PrettyPrinter) printExprIsset(n node.Node) { + nn := n.(*expr.Isset) + + io.WriteString(p.w, "isset(") + p.joinPrint(", ", nn.Variables) + io.WriteString(p.w, ")") +} + +func (p *PrettyPrinter) printExprList(n node.Node) { + nn := n.(*expr.List) + + io.WriteString(p.w, "list(") + p.joinPrint(", ", nn.Items) + io.WriteString(p.w, ")") +} + +func (p *PrettyPrinter) printExprMethodCall(n node.Node) { + nn := n.(*expr.MethodCall) + + p.Print(nn.Variable) + io.WriteString(p.w, "->") + p.Print(nn.Method) + io.WriteString(p.w, "(") + p.joinPrint(", ", nn.ArgumentList.Arguments) + io.WriteString(p.w, ")") +} + +func (p *PrettyPrinter) printExprNew(n node.Node) { + nn := n.(*expr.New) + + io.WriteString(p.w, "new ") + p.Print(nn.Class) + + if nn.ArgumentList != nil { + io.WriteString(p.w, "(") + p.joinPrint(", ", nn.ArgumentList.Arguments) + io.WriteString(p.w, ")") + } +} + +func (p *PrettyPrinter) printExprPostDec(n node.Node) { + nn := n.(*expr.PostDec) + + p.Print(nn.Variable) + io.WriteString(p.w, "--") +} + +func (p *PrettyPrinter) printExprPostInc(n node.Node) { + nn := n.(*expr.PostInc) + + p.Print(nn.Variable) + io.WriteString(p.w, "++") +} + +func (p *PrettyPrinter) printExprPreDec(n node.Node) { + nn := n.(*expr.PreDec) + + io.WriteString(p.w, "--") + p.Print(nn.Variable) +} + +func (p *PrettyPrinter) printExprPreInc(n node.Node) { + nn := n.(*expr.PreInc) + + io.WriteString(p.w, "++") + p.Print(nn.Variable) +} + +func (p *PrettyPrinter) printExprPrint(n node.Node) { + nn := n.(*expr.Print) + + io.WriteString(p.w, "print(") + p.Print(nn.Expr) + io.WriteString(p.w, ")") +} + +func (p *PrettyPrinter) printExprPropertyFetch(n node.Node) { + nn := n.(*expr.PropertyFetch) + + p.Print(nn.Variable) + io.WriteString(p.w, "->") + p.Print(nn.Property) +} + +func (p *PrettyPrinter) printExprReference(n node.Node) { + nn := n.(*expr.Reference) + + io.WriteString(p.w, "&") + p.Print(nn.Variable) +} + +func (p *PrettyPrinter) printExprRequire(n node.Node) { + nn := n.(*expr.Require) + + io.WriteString(p.w, "require ") + p.Print(nn.Expr) +} + +func (p *PrettyPrinter) printExprRequireOnce(n node.Node) { + nn := n.(*expr.RequireOnce) + + io.WriteString(p.w, "require_once ") + p.Print(nn.Expr) +} + +func (p *PrettyPrinter) printExprShellExec(n node.Node) { + nn := n.(*expr.ShellExec) + + io.WriteString(p.w, "`") + for _, part := range nn.Parts { + p.Print(part) + } + io.WriteString(p.w, "`") +} + +func (p *PrettyPrinter) printExprShortArray(n node.Node) { + nn := n.(*expr.ShortArray) + + io.WriteString(p.w, "[") + p.joinPrint(", ", nn.Items) + io.WriteString(p.w, "]") +} + +func (p *PrettyPrinter) printExprShortList(n node.Node) { + nn := n.(*expr.ShortList) + + io.WriteString(p.w, "[") + p.joinPrint(", ", nn.Items) + io.WriteString(p.w, "]") +} + +func (p *PrettyPrinter) printExprStaticCall(n node.Node) { + nn := n.(*expr.StaticCall) + + p.Print(nn.Class) + io.WriteString(p.w, "::") + p.Print(nn.Call) + io.WriteString(p.w, "(") + p.joinPrint(", ", nn.ArgumentList.Arguments) + io.WriteString(p.w, ")") +} + +func (p *PrettyPrinter) printExprStaticPropertyFetch(n node.Node) { + nn := n.(*expr.StaticPropertyFetch) + + p.Print(nn.Class) + io.WriteString(p.w, "::") + p.Print(nn.Property) +} + +func (p *PrettyPrinter) printExprTernary(n node.Node) { + nn := n.(*expr.Ternary) + + p.Print(nn.Condition) + io.WriteString(p.w, " ?") + + if nn.IfTrue != nil { + io.WriteString(p.w, " ") + p.Print(nn.IfTrue) + io.WriteString(p.w, " ") + } + + io.WriteString(p.w, ": ") + p.Print(nn.IfFalse) +} + +func (p *PrettyPrinter) printExprUnaryMinus(n node.Node) { + nn := n.(*expr.UnaryMinus) + + io.WriteString(p.w, "-") + p.Print(nn.Expr) +} + +func (p *PrettyPrinter) printExprUnaryPlus(n node.Node) { + nn := n.(*expr.UnaryPlus) + + io.WriteString(p.w, "+") + p.Print(nn.Expr) +} + +func (p *PrettyPrinter) printExprVariable(n node.Node) { + io.WriteString(p.w, "$") + p.Print(n.(*expr.Variable).VarName) +} + +func (p *PrettyPrinter) printExprYieldFrom(n node.Node) { + nn := n.(*expr.YieldFrom) + + io.WriteString(p.w, "yield from ") + p.Print(nn.Expr) +} + +func (p *PrettyPrinter) printExprYield(n node.Node) { + nn := n.(*expr.Yield) + + io.WriteString(p.w, "yield ") + + if nn.Key != nil { + p.Print(nn.Key) + io.WriteString(p.w, " => ") + } + + p.Print(nn.Value) +} + +// smtm + +func (p *PrettyPrinter) printStmtAltElseIf(n node.Node) { + nn := n.(*stmt.AltElseIf) + + io.WriteString(p.w, "elseif (") + p.Print(nn.Cond) + io.WriteString(p.w, ") :") + + if s := nn.Stmt.(*stmt.StmtList).Stmts; len(s) > 0 { + io.WriteString(p.w, "\n") + p.printNodes(s) + } +} + +func (p *PrettyPrinter) printStmtAltElse(n node.Node) { + nn := n.(*stmt.AltElse) + + io.WriteString(p.w, "else :") + + if s := nn.Stmt.(*stmt.StmtList).Stmts; len(s) > 0 { + io.WriteString(p.w, "\n") + p.printNodes(s) + } +} + +func (p *PrettyPrinter) printStmtAltFor(n node.Node) { + nn := n.(*stmt.AltFor) + + io.WriteString(p.w, "for (") + p.joinPrint(", ", nn.Init) + io.WriteString(p.w, "; ") + p.joinPrint(", ", nn.Cond) + io.WriteString(p.w, "; ") + p.joinPrint(", ", nn.Loop) + io.WriteString(p.w, ") :\n") + + s := nn.Stmt.(*stmt.StmtList) + p.printNodes(s.Stmts) + io.WriteString(p.w, "\n") + p.printIndent() + + io.WriteString(p.w, "endfor;") +} + +func (p *PrettyPrinter) printStmtAltForeach(n node.Node) { + nn := n.(*stmt.AltForeach) + + io.WriteString(p.w, "foreach (") + p.Print(nn.Expr) + io.WriteString(p.w, " as ") + + if nn.Key != nil { + p.Print(nn.Key) + io.WriteString(p.w, " => ") + } + + p.Print(nn.Variable) + + io.WriteString(p.w, ") :\n") + + s := nn.Stmt.(*stmt.StmtList) + p.printNodes(s.Stmts) + + io.WriteString(p.w, "\n") + p.printIndent() + io.WriteString(p.w, "endforeach;") +} + +func (p *PrettyPrinter) printStmtAltIf(n node.Node) { + nn := n.(*stmt.AltIf) + + io.WriteString(p.w, "if (") + p.Print(nn.Cond) + io.WriteString(p.w, ") :\n") + + s := nn.Stmt.(*stmt.StmtList) + p.printNodes(s.Stmts) + + for _, elseif := range nn.ElseIf { + io.WriteString(p.w, "\n") + p.printIndent() + p.Print(elseif) + } + + if nn.Else != nil { + io.WriteString(p.w, "\n") + p.printIndent() + p.Print(nn.Else) + } + + io.WriteString(p.w, "\n") + p.printIndent() + io.WriteString(p.w, "endif;") +} + +func (p *PrettyPrinter) printStmtAltSwitch(n node.Node) { + nn := n.(*stmt.AltSwitch) + + io.WriteString(p.w, "switch (") + p.Print(nn.Cond) + io.WriteString(p.w, ") :\n") + + s := nn.CaseList.Cases + p.printNodes(s) + + io.WriteString(p.w, "\n") + p.printIndent() + io.WriteString(p.w, "endswitch;") +} + +func (p *PrettyPrinter) printStmtAltWhile(n node.Node) { + nn := n.(*stmt.AltWhile) + + io.WriteString(p.w, "while (") + p.Print(nn.Cond) + io.WriteString(p.w, ") :\n") + + s := nn.Stmt.(*stmt.StmtList) + p.printNodes(s.Stmts) + + io.WriteString(p.w, "\n") + p.printIndent() + io.WriteString(p.w, "endwhile;") +} + +func (p *PrettyPrinter) printStmtBreak(n node.Node) { + nn := n.(*stmt.Break) + + io.WriteString(p.w, "break") + if nn.Expr != nil { + io.WriteString(p.w, " ") + p.Print(nn.Expr) + } + + io.WriteString(p.w, ";") +} + +func (p *PrettyPrinter) printStmtCase(n node.Node) { + nn := n.(*stmt.Case) + + io.WriteString(p.w, "case ") + p.Print(nn.Cond) + io.WriteString(p.w, ":") + + if len(nn.Stmts) > 0 { + io.WriteString(p.w, "\n") + p.printNodes(nn.Stmts) + } +} + +func (p *PrettyPrinter) printStmtCatch(n node.Node) { + nn := n.(*stmt.Catch) + + io.WriteString(p.w, "catch (") + p.joinPrint(" | ", nn.Types) + io.WriteString(p.w, " ") + p.Print(nn.Variable) + io.WriteString(p.w, ") {\n") + p.printNodes(nn.Stmts) + io.WriteString(p.w, "\n") + p.printIndent() + io.WriteString(p.w, "}") +} + +func (p *PrettyPrinter) printStmtClassMethod(n node.Node) { + nn := n.(*stmt.ClassMethod) + + if nn.Modifiers != nil { + p.joinPrint(" ", nn.Modifiers) + io.WriteString(p.w, " ") + } + io.WriteString(p.w, "function ") + + if nn.ReturnsRef { + io.WriteString(p.w, "&") + } + + p.Print(nn.MethodName) + io.WriteString(p.w, "(") + p.joinPrint(", ", nn.Params) + io.WriteString(p.w, ")") + + if nn.ReturnType != nil { + io.WriteString(p.w, ": ") + p.Print(nn.ReturnType) + } + + switch s := nn.Stmt.(type) { + case *stmt.StmtList: + io.WriteString(p.w, "\n") + p.printIndent() + io.WriteString(p.w, "{\n") + p.printNodes(s.Stmts) + io.WriteString(p.w, "\n") + p.printIndent() + io.WriteString(p.w, "}") + default: + p.Print(s) + } +} + +func (p *PrettyPrinter) printStmtClass(n node.Node) { + nn := n.(*stmt.Class) + + if nn.Modifiers != nil { + p.joinPrint(" ", nn.Modifiers) + io.WriteString(p.w, " ") + } + io.WriteString(p.w, "class") + + if nn.ClassName != nil { + io.WriteString(p.w, " ") + p.Print(nn.ClassName) + } + + if nn.ArgumentList != nil { + io.WriteString(p.w, "(") + p.joinPrint(", ", nn.ArgumentList.Arguments) + io.WriteString(p.w, ")") + } + + if nn.Extends != nil { + io.WriteString(p.w, " extends ") + p.Print(nn.Extends.ClassName) + } + + if nn.Implements != nil { + io.WriteString(p.w, " implements ") + p.joinPrint(", ", nn.Implements.InterfaceNames) + } + + io.WriteString(p.w, "\n") + p.printIndent() + io.WriteString(p.w, "{\n") + p.printNodes(nn.Stmts) + io.WriteString(p.w, "\n") + p.printIndent() + io.WriteString(p.w, "}") +} + +func (p *PrettyPrinter) printStmtClassConstList(n node.Node) { + nn := n.(*stmt.ClassConstList) + + if nn.Modifiers != nil { + p.joinPrint(" ", nn.Modifiers) + io.WriteString(p.w, " ") + } + io.WriteString(p.w, "const ") + + p.joinPrint(", ", nn.Consts) + + io.WriteString(p.w, ";") +} + +func (p *PrettyPrinter) printStmtConstant(n node.Node) { + nn := n.(*stmt.Constant) + + p.Print(nn.ConstantName) + io.WriteString(p.w, " = ") + p.Print(nn.Expr) +} + +func (p *PrettyPrinter) printStmtContinue(n node.Node) { + nn := n.(*stmt.Continue) + + io.WriteString(p.w, "continue") + if nn.Expr != nil { + io.WriteString(p.w, " ") + p.Print(nn.Expr) + } + + io.WriteString(p.w, ";") +} + +func (p *PrettyPrinter) printStmtDeclare(n node.Node) { + nn := n.(*stmt.Declare) + + io.WriteString(p.w, "declare(") + p.joinPrint(", ", nn.Consts) + io.WriteString(p.w, ")") + + switch s := nn.Stmt.(type) { + case *stmt.Nop: + p.Print(s) + break + case *stmt.StmtList: + io.WriteString(p.w, " ") + p.Print(s) + default: + io.WriteString(p.w, "\n") + p.indentDepth++ + p.printIndent() + p.Print(s) + p.indentDepth-- + } +} + +func (p *PrettyPrinter) printStmtDefault(n node.Node) { + nn := n.(*stmt.Default) + io.WriteString(p.w, "default:") + + if len(nn.Stmts) > 0 { + io.WriteString(p.w, "\n") + p.printNodes(nn.Stmts) + } +} + +func (p *PrettyPrinter) printStmtDo(n node.Node) { + nn := n.(*stmt.Do) + io.WriteString(p.w, "do") + + switch s := nn.Stmt.(type) { + case *stmt.StmtList: + io.WriteString(p.w, " ") + p.Print(s) + io.WriteString(p.w, " ") + default: + io.WriteString(p.w, "\n") + p.indentDepth++ + p.printIndent() + p.Print(s) + p.indentDepth-- + io.WriteString(p.w, "\n") + p.printIndent() + } + + io.WriteString(p.w, "while (") + p.Print(nn.Cond) + io.WriteString(p.w, ");") +} + +func (p *PrettyPrinter) printStmtEcho(n node.Node) { + nn := n.(*stmt.Echo) + io.WriteString(p.w, "echo ") + p.joinPrint(", ", nn.Exprs) + io.WriteString(p.w, ";") +} + +func (p *PrettyPrinter) printStmtElseif(n node.Node) { + nn := n.(*stmt.ElseIf) + + io.WriteString(p.w, "elseif (") + p.Print(nn.Cond) + io.WriteString(p.w, ")") + + switch s := nn.Stmt.(type) { + case *stmt.Nop: + p.Print(s) + break + case *stmt.StmtList: + io.WriteString(p.w, " ") + p.Print(s) + default: + io.WriteString(p.w, "\n") + p.indentDepth++ + p.printIndent() + p.Print(s) + p.indentDepth-- + } +} + +func (p *PrettyPrinter) printStmtElse(n node.Node) { + nn := n.(*stmt.Else) + + io.WriteString(p.w, "else") + + switch s := nn.Stmt.(type) { + case *stmt.Nop: + p.Print(s) + break + case *stmt.StmtList: + io.WriteString(p.w, " ") + p.Print(s) + default: + io.WriteString(p.w, "\n") + p.indentDepth++ + p.printIndent() + p.Print(s) + p.indentDepth-- + } +} + +func (p *PrettyPrinter) printStmtExpression(n node.Node) { + nn := n.(*stmt.Expression) + + p.Print(nn.Expr) + + io.WriteString(p.w, ";") +} + +func (p *PrettyPrinter) printStmtFinally(n node.Node) { + nn := n.(*stmt.Finally) + + io.WriteString(p.w, "finally {\n") + p.printNodes(nn.Stmts) + io.WriteString(p.w, "\n") + p.printIndent() + io.WriteString(p.w, "}") +} + +func (p *PrettyPrinter) printStmtFor(n node.Node) { + nn := n.(*stmt.For) + + io.WriteString(p.w, "for (") + p.joinPrint(", ", nn.Init) + io.WriteString(p.w, "; ") + p.joinPrint(", ", nn.Cond) + io.WriteString(p.w, "; ") + p.joinPrint(", ", nn.Loop) + io.WriteString(p.w, ")") + + switch s := nn.Stmt.(type) { + case *stmt.Nop: + p.Print(s) + break + case *stmt.StmtList: + io.WriteString(p.w, " ") + p.Print(s) + default: + io.WriteString(p.w, "\n") + p.indentDepth++ + p.printIndent() + p.Print(s) + p.indentDepth-- + } +} + +func (p *PrettyPrinter) printStmtForeach(n node.Node) { + nn := n.(*stmt.Foreach) + + io.WriteString(p.w, "foreach (") + p.Print(nn.Expr) + io.WriteString(p.w, " as ") + + if nn.Key != nil { + p.Print(nn.Key) + io.WriteString(p.w, " => ") + } + + p.Print(nn.Variable) + io.WriteString(p.w, ")") + + switch s := nn.Stmt.(type) { + case *stmt.Nop: + p.Print(s) + break + case *stmt.StmtList: + io.WriteString(p.w, " ") + p.Print(s) + default: + io.WriteString(p.w, "\n") + p.indentDepth++ + p.printIndent() + p.Print(s) + p.indentDepth-- + } +} + +func (p *PrettyPrinter) printStmtFunction(n node.Node) { + nn := n.(*stmt.Function) + + io.WriteString(p.w, "function ") + + if nn.ReturnsRef { + io.WriteString(p.w, "&") + } + + p.Print(nn.FunctionName) + + io.WriteString(p.w, "(") + p.joinPrint(", ", nn.Params) + io.WriteString(p.w, ")") + + if nn.ReturnType != nil { + io.WriteString(p.w, ": ") + p.Print(nn.ReturnType) + } + + io.WriteString(p.w, " {\n") + p.printNodes(nn.Stmts) + io.WriteString(p.w, "\n") + p.printIndent() + io.WriteString(p.w, "}") +} + +func (p *PrettyPrinter) printStmtGlobal(n node.Node) { + nn := n.(*stmt.Global) + + io.WriteString(p.w, "global ") + p.joinPrint(", ", nn.Vars) + io.WriteString(p.w, ";") +} + +func (p *PrettyPrinter) printStmtGoto(n node.Node) { + nn := n.(*stmt.Goto) + + io.WriteString(p.w, "goto ") + p.Print(nn.Label) + io.WriteString(p.w, ";") +} + +func (p *PrettyPrinter) printStmtGroupUse(n node.Node) { + nn := n.(*stmt.GroupUse) + + io.WriteString(p.w, "use ") + + if nn.UseType != nil { + p.Print(nn.UseType) + io.WriteString(p.w, " ") + } + + p.Print(nn.Prefix) + io.WriteString(p.w, "\\{") + p.joinPrint(", ", nn.UseList) + io.WriteString(p.w, "};") +} + +func (p *PrettyPrinter) printStmtHaltCompiler(n node.Node) { + io.WriteString(p.w, "__halt_compiler();") +} + +func (p *PrettyPrinter) printStmtIf(n node.Node) { + nn := n.(*stmt.If) + + io.WriteString(p.w, "if (") + p.Print(nn.Cond) + io.WriteString(p.w, ")") + + switch s := nn.Stmt.(type) { + case *stmt.Nop: + p.Print(s) + break + case *stmt.StmtList: + io.WriteString(p.w, " ") + p.Print(s) + default: + io.WriteString(p.w, "\n") + p.indentDepth++ + p.printIndent() + p.Print(s) + p.indentDepth-- + } + + if nn.ElseIf != nil { + io.WriteString(p.w, "\n") + p.indentDepth-- + p.printNodes(nn.ElseIf) + p.indentDepth++ + } + + if nn.Else != nil { + io.WriteString(p.w, "\n") + p.printIndent() + p.Print(nn.Else) + } +} + +func (p *PrettyPrinter) printStmtInlineHTML(n node.Node) { + nn := n.(*stmt.InlineHtml) + + io.WriteString(p.w, "?>") + io.WriteString(p.w, nn.Value) + io.WriteString(p.w, "HTML"}, + &stmt.Expression{ + Expr: &scalar.Heredoc{ + Label: "\"LBL\"", + Parts: []node.Node{ + &scalar.EncapsedStringPart{Value: "hello world\n"}, + }, + }, + }, + }, + }) + + expected := `
HTML
>= $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +// binary + +func TestPrintBinaryBitwiseAnd(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.BitwiseAnd{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a & $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryBitwiseOr(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.BitwiseOr{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a | $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryBitwiseXor(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.BitwiseXor{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a ^ $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryBooleanAnd(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.BooleanAnd{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a && $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryBooleanOr(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.BooleanOr{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a || $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryCoalesce(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.Coalesce{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a ?? $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryConcat(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.Concat{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a . $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryDiv(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.Div{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a / $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryEqual(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.Equal{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a == $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryGreaterOrEqual(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.GreaterOrEqual{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a >= $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryGreater(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.Greater{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a > $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryIdentical(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.Identical{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a === $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryLogicalAnd(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.LogicalAnd{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a and $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryLogicalOr(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.LogicalOr{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a or $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryLogicalXor(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.LogicalXor{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a xor $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryMinus(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.Minus{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a - $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryMod(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.Mod{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a % $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryMul(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.Mul{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a * $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryNotEqual(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.NotEqual{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a != $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryNotIdentical(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.NotIdentical{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a !== $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryPlus(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.Plus{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a + $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryPow(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.Pow{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a ** $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryShiftLeft(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.ShiftLeft{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a << $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinaryShiftRight(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.ShiftRight{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a >> $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinarySmallerOrEqual(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.SmallerOrEqual{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a <= $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinarySmaller(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.Smaller{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a < $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBinarySpaceship(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&binary.Spaceship{ + Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a <=> $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +// cast + +func TestPrintArray(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&cast.Array{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `(array)$var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintBool(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&cast.Bool{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `(bool)$var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintDouble(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&cast.Double{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `(float)$var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintInt(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&cast.Int{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `(int)$var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintObject(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&cast.Object{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `(object)$var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintString(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&cast.String{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `(string)$var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintUnset(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&cast.Unset{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `(unset)$var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +// expr + +func TestPrintExprArrayDimFetch(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.ArrayDimFetch{ + Variable: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + Dim: &scalar.Lnumber{Value: "1"}, + }) + + expected := `$var[1]` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintExprArrayItemWithKey(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.ArrayItem{ + Key: &scalar.String{Value: "'Hello'"}, + Val: &expr.Variable{VarName: &node.Identifier{Value: "world"}}, + }) + + expected := `'Hello' => $world` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintExprArrayItem(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.ArrayItem{ + Val: &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "world"}}}, + }) + + expected := `&$world` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintExprArray(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.Array{ + Items: []node.Node{ + &expr.ArrayItem{ + Key: &scalar.String{Value: "'Hello'"}, + Val: &expr.Variable{VarName: &node.Identifier{Value: "world"}}, + }, + &expr.ArrayItem{ + Key: &scalar.Lnumber{Value: "2"}, + Val: &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "var"}}}, + }, + &expr.ArrayItem{ + Val: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }, + }, + }) + + expected := `array('Hello' => $world, 2 => &$var, $var)` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintExprBitwiseNot(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.BitwiseNot{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `~$var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintExprBooleanNot(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.BooleanNot{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `!$var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintExprClassConstFetch(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.ClassConstFetch{ + Class: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + ConstantName: &node.Identifier{Value: "CONST"}, + }) + + expected := `$var::CONST` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintExprClone(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.Clone{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `clone $var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintExprClosureUse(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.ClosureUse{ + Uses: []node.Node{ + &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "foo"}}}, + &expr.Variable{VarName: &node.Identifier{Value: "bar"}}, + }, + }) + + expected := `use (&$foo, $bar)` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintExprClosure(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &expr.Closure{ + Static: true, + ReturnsRef: true, + Params: []node.Node{ + &node.Parameter{ + ByRef: true, + Variadic: false, + Variable: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }, + }, + ClosureUse: &expr.ClosureUse{ + Uses: []node.Node{ + &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, + &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + }, + ReturnType: &name.FullyQualified{Parts: []node.Node{&name.NamePart{Value: "Foo"}}}, + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, + }, + }, + }, + }) + + expected := `namespace { + static function &(&$var) use (&$a, $b): \Foo { + $a; + } +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintExprConstFetch(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.ConstFetch{ + Constant: &name.Name{Parts: []node.Node{&name.NamePart{Value: "null"}}}, + }) + + expected := "null" + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintDie(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.Die{Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}}) + + expected := `die($var)` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintEmpty(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.Empty{Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}}) + + expected := `empty($var)` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrettyPrinterrorSuppress(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.ErrorSuppress{Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}}) + + expected := `@$var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintEval(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.Eval{Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}}) + + expected := `eval($var)` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintExit(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.Exit{Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}}) + + expected := `exit($var)` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintFunctionCall(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.FunctionCall{ + Function: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + ArgumentList: &node.ArgumentList{ + Arguments: []node.Node{ + &node.Argument{ + IsReference: true, + Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + }, + &node.Argument{ + Variadic: true, + Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + &node.Argument{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "c"}}, + }, + }, + }, + }) + + expected := `$var(&$a, ...$b, $c)` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintInclude(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.Include{Expr: &scalar.String{Value: "'path'"}}) + + expected := `include 'path'` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintIncludeOnce(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.IncludeOnce{Expr: &scalar.String{Value: "'path'"}}) + + expected := `include_once 'path'` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintInstanceOf(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.InstanceOf{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + Class: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}}, + }) + + expected := `$var instanceof Foo` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintIsset(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.Isset{ + Variables: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + }) + + expected := `isset($a, $b)` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintList(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.List{ + Items: []node.Node{ + &expr.ArrayItem{ + Val: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + }, + &expr.ArrayItem{ + Val: &expr.List{ + Items: []node.Node{ + &expr.ArrayItem{ + Val: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + &expr.ArrayItem{ + Val: &expr.Variable{VarName: &node.Identifier{Value: "c"}}, + }, + }, + }, + }, + }, + }) + + expected := `list($a, list($b, $c))` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintMethodCall(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.MethodCall{ + Variable: &expr.Variable{VarName: &node.Identifier{Value: "foo"}}, + Method: &node.Identifier{Value: "bar"}, + ArgumentList: &node.ArgumentList{ + Arguments: []node.Node{ + &node.Argument{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + }, + &node.Argument{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + }, + }, + }) + + expected := `$foo->bar($a, $b)` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintNew(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.New{ + Class: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}}, + ArgumentList: &node.ArgumentList{ + Arguments: []node.Node{ + &node.Argument{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + }, + &node.Argument{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + }, + }, + }) + + expected := `new Foo($a, $b)` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintPostDec(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.PostDec{ + Variable: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `$var--` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintPostInc(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.PostInc{ + Variable: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `$var++` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintPreDec(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.PreDec{ + Variable: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `--$var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintPreInc(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.PreInc{ + Variable: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `++$var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintPrint(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.Print{Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}}) + + expected := `print($var)` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintPropertyFetch(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.PropertyFetch{ + Variable: &expr.Variable{VarName: &node.Identifier{Value: "foo"}}, + Property: &node.Identifier{Value: "bar"}, + }) + + expected := `$foo->bar` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintExprReference(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.Reference{ + Variable: &expr.Variable{VarName: &node.Identifier{Value: "foo"}}, + }) + + expected := `&$foo` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintRequire(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.Require{Expr: &scalar.String{Value: "'path'"}}) + + expected := `require 'path'` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintRequireOnce(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.RequireOnce{Expr: &scalar.String{Value: "'path'"}}) + + expected := `require_once 'path'` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintShellExec(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.ShellExec{ + Parts: []node.Node{ + &scalar.EncapsedStringPart{Value: "hello "}, + &expr.Variable{VarName: &node.Identifier{Value: "world"}}, + &scalar.EncapsedStringPart{Value: "!"}, + }, + }) + + expected := "`hello $world!`" + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintExprShortArray(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.ShortArray{ + Items: []node.Node{ + &expr.ArrayItem{ + Key: &scalar.String{Value: "'Hello'"}, + Val: &expr.Variable{VarName: &node.Identifier{Value: "world"}}, + }, + &expr.ArrayItem{ + Key: &scalar.Lnumber{Value: "2"}, + Val: &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "var"}}}, + }, + &expr.ArrayItem{ + Val: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }, + }, + }) + + expected := `['Hello' => $world, 2 => &$var, $var]` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintShortList(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.ShortList{ + Items: []node.Node{ + &expr.ArrayItem{ + Val: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + }, + &expr.ArrayItem{ + Val: &expr.List{ + Items: []node.Node{ + &expr.ArrayItem{ + Val: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + &expr.ArrayItem{ + Val: &expr.Variable{VarName: &node.Identifier{Value: "c"}}, + }, + }, + }, + }, + }, + }) + + expected := `[$a, list($b, $c)]` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStaticCall(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.StaticCall{ + Class: &node.Identifier{Value: "Foo"}, + Call: &node.Identifier{Value: "bar"}, + ArgumentList: &node.ArgumentList{ + Arguments: []node.Node{ + &node.Argument{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + }, + &node.Argument{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + }, + }, + }) + + expected := `Foo::bar($a, $b)` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStaticPropertyFetch(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.StaticPropertyFetch{ + Class: &node.Identifier{Value: "Foo"}, + Property: &expr.Variable{VarName: &node.Identifier{Value: "bar"}}, + }) + + expected := `Foo::$bar` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintTernary(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.Ternary{ + Condition: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + IfFalse: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }) + + expected := `$a ?: $b` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintTernaryFull(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.Ternary{ + Condition: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + IfTrue: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + IfFalse: &expr.Variable{VarName: &node.Identifier{Value: "c"}}, + }) + + expected := `$a ? $b : $c` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintUnaryMinus(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.UnaryMinus{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `-$var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintUnaryPlus(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.UnaryPlus{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `+$var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintVariable(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.Variable{VarName: &expr.Variable{VarName: &node.Identifier{Value: "var"}}}) + + expected := `$$var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintYieldFrom(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.YieldFrom{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `yield from $var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintYield(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.Yield{ + Value: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `yield $var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintYieldFull(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.Yield{ + Key: &expr.Variable{VarName: &node.Identifier{Value: "k"}}, + Value: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) + + expected := `yield $k => $var` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +// stmt + +func TestPrintAltElseIf(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.AltElseIf{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}}, + }, + }, + }) + + expected := `elseif ($a) : + $b;` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintAltElseIfEmpty(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.AltElseIf{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Stmt: &stmt.StmtList{}, + }) + + expected := `elseif ($a) :` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintAltElse(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.AltElse{ + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}}, + }, + }, + }) + + expected := `else : + $b;` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintAltElseEmpty(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.AltElse{ + Stmt: &stmt.StmtList{}, + }) + + expected := `else :` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintAltFor(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &stmt.AltFor{ + Init: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + }, + Cond: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + Loop: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "c"}}, + }, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "d"}}}, + }, + }, + }, + }, + }) + + expected := `namespace { + for ($a; $b; $c) : + $d; + endfor; +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintAltForeach(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &stmt.AltForeach{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + Key: &expr.Variable{VarName: &node.Identifier{Value: "key"}}, + Variable: &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "val"}}}, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "d"}}}, + }, + }, + }, + }, + }) + + expected := `namespace { + foreach ($var as $key => &$val) : + $d; + endforeach; +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintAltIf(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &stmt.AltIf{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "d"}}}, + }, + }, + ElseIf: []node.Node{ + &stmt.AltElseIf{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}}, + }, + }, + }, + &stmt.AltElseIf{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "c"}}, + Stmt: &stmt.StmtList{}, + }, + }, + Else: &stmt.AltElse{ + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}}, + }, + }, + }, + }, + }, + }) + + expected := `namespace { + if ($a) : + $d; + elseif ($b) : + $b; + elseif ($c) : + else : + $b; + endif; +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtAltSwitch(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &stmt.AltSwitch{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + CaseList: &stmt.CaseList{ + Cases: []node.Node{ + &stmt.Case{ + Cond: &scalar.String{Value: "'a'"}, + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, + }, + }, + &stmt.Case{ + Cond: &scalar.String{Value: "'b'"}, + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}}, + }, + }, + }, + }, + }, + }, + }) + + expected := `namespace { + switch ($var) : + case 'a': + $a; + case 'b': + $b; + endswitch; +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintAltWhile(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &stmt.AltWhile{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}}, + }, + }, + }, + }, + }) + + expected := `namespace { + while ($a) : + $b; + endwhile; +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtBreak(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Break{ + Expr: &scalar.Lnumber{Value: "1"}, + }) + + expected := "break 1;" + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtCase(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Case{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, + }, + }) + + expected := `case $a: + $a;` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtCaseEmpty(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Case{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Stmts: []node.Node{}, + }) + + expected := "case $a:" + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtCatch(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &stmt.Catch{ + Types: []node.Node{ + &name.Name{Parts: []node.Node{&name.NamePart{Value: "Exception"}}}, + &name.FullyQualified{Parts: []node.Node{&name.NamePart{Value: "RuntimeException"}}}, + }, + Variable: &expr.Variable{VarName: &node.Identifier{Value: "e"}}, + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, + }, + }, + }, + }) + + expected := `namespace { + catch (Exception | \RuntimeException $e) { + $a; + } +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtClassMethod(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.ClassMethod{ + Modifiers: []node.Node{&node.Identifier{Value: "public"}}, + ReturnsRef: true, + MethodName: &node.Identifier{Value: "foo"}, + Params: []node.Node{ + &node.Parameter{ + ByRef: true, + VariableType: &node.Nullable{Expr: &name.Name{Parts: []node.Node{&name.NamePart{Value: "int"}}}}, + Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + DefaultValue: &expr.ConstFetch{Constant: &name.Name{Parts: []node.Node{&name.NamePart{Value: "null"}}}}, + }, + &node.Parameter{ + Variadic: true, + Variable: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + }, + ReturnType: &name.Name{Parts: []node.Node{&name.NamePart{Value: "void"}}}, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, + }, + }, + }) + + expected := `public function &foo(?int &$a = null, ...$b): void +{ + $a; +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} +func TestPrintStmtAbstractClassMethod(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.ClassMethod{ + Modifiers: []node.Node{&node.Identifier{Value: "public"}}, + ReturnsRef: true, + MethodName: &node.Identifier{Value: "foo"}, + Params: []node.Node{ + &node.Parameter{ + ByRef: true, + VariableType: &node.Nullable{Expr: &name.Name{Parts: []node.Node{&name.NamePart{Value: "int"}}}}, + Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + DefaultValue: &expr.ConstFetch{Constant: &name.Name{Parts: []node.Node{&name.NamePart{Value: "null"}}}}, + }, + &node.Parameter{ + Variadic: true, + Variable: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + }, + ReturnType: &name.Name{Parts: []node.Node{&name.NamePart{Value: "void"}}}, + Stmt: &stmt.Nop{}, + }) + + expected := `public function &foo(?int &$a = null, ...$b): void;` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtClass(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &stmt.Class{ + Modifiers: []node.Node{&node.Identifier{Value: "abstract"}}, + ClassName: &node.Identifier{Value: "Foo"}, + Extends: &stmt.ClassExtends{ + ClassName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}}, + }, + Implements: &stmt.ClassImplements{ + InterfaceNames: []node.Node{ + &name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}}, + &name.Name{Parts: []node.Node{&name.NamePart{Value: "Quuz"}}}, + }, + }, + Stmts: []node.Node{ + &stmt.ClassConstList{ + Modifiers: []node.Node{&node.Identifier{Value: "public"}}, + Consts: []node.Node{ + &stmt.Constant{ + ConstantName: &node.Identifier{Value: "FOO"}, + Expr: &scalar.String{Value: "'bar'"}, + }, + }, + }, + }, + }, + }, + }) + + expected := `namespace { + abstract class Foo extends Bar implements Baz, Quuz + { + public const FOO = 'bar'; + } +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtAnonymousClass(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &stmt.Class{ + Modifiers: []node.Node{&node.Identifier{Value: "abstract"}}, + ArgumentList: &node.ArgumentList{ + Arguments: []node.Node{ + &node.Argument{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + }, + &node.Argument{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + }, + }, + Extends: &stmt.ClassExtends{ + ClassName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}}, + }, + Implements: &stmt.ClassImplements{ + InterfaceNames: []node.Node{ + &name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}}, + &name.Name{Parts: []node.Node{&name.NamePart{Value: "Quuz"}}}, + }, + }, + Stmts: []node.Node{ + &stmt.ClassConstList{ + Modifiers: []node.Node{&node.Identifier{Value: "public"}}, + Consts: []node.Node{ + &stmt.Constant{ + ConstantName: &node.Identifier{Value: "FOO"}, + Expr: &scalar.String{Value: "'bar'"}, + }, + }, + }, + }, + }, + }, + }) + + expected := `namespace { + abstract class($a, $b) extends Bar implements Baz, Quuz + { + public const FOO = 'bar'; + } +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtClassConstList(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.ClassConstList{ + Modifiers: []node.Node{&node.Identifier{Value: "public"}}, + Consts: []node.Node{ + &stmt.Constant{ + ConstantName: &node.Identifier{Value: "FOO"}, + Expr: &scalar.String{Value: "'a'"}, + }, + &stmt.Constant{ + ConstantName: &node.Identifier{Value: "BAR"}, + Expr: &scalar.String{Value: "'b'"}, + }, + }, + }) + + expected := `public const FOO = 'a', BAR = 'b';` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtConstant(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Constant{ + ConstantName: &node.Identifier{Value: "FOO"}, + Expr: &scalar.String{Value: "'BAR'"}, + }) + + expected := "FOO = 'BAR'" + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtContinue(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Continue{ + Expr: &scalar.Lnumber{Value: "1"}, + }) + + expected := `continue 1;` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtDeclareStmts(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Declare{ + Consts: []node.Node{ + &stmt.Constant{ + ConstantName: &node.Identifier{Value: "FOO"}, + Expr: &scalar.String{Value: "'bar'"}, + }, + }, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Nop{}, + }, + }, + }, + }, + }) + + expected := `{ + declare(FOO = 'bar') { + ; + } +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtDeclareExpr(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Declare{ + Consts: []node.Node{ + &stmt.Constant{ + ConstantName: &node.Identifier{Value: "FOO"}, + Expr: &scalar.String{Value: "'bar'"}, + }, + }, + Stmt: &stmt.Expression{Expr: &scalar.String{Value: "'bar'"}}, + }, + }, + }) + + expected := `{ + declare(FOO = 'bar') + 'bar'; +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtDeclareNop(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Declare{ + Consts: []node.Node{ + &stmt.Constant{ + ConstantName: &node.Identifier{Value: "FOO"}, + Expr: &scalar.String{Value: "'bar'"}, + }, + }, + Stmt: &stmt.Nop{}, + }) + + expected := `declare(FOO = 'bar');` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtDefalut(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Default{ + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, + }, + }) + + expected := `default: + $a;` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtDefalutEmpty(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Default{ + Stmts: []node.Node{}, + }) + + expected := `default:` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtDo_Expression(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &stmt.Do{ + Cond: &scalar.Lnumber{Value: "1"}, + Stmt: &stmt.Expression{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + }, + }, + }, + }) + + expected := `namespace { + do + $a; + while (1); +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtDo_StmtList(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &stmt.Do{ + Cond: &scalar.Lnumber{Value: "1"}, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, + }, + }, + }, + }, + }) + + expected := `namespace { + do { + $a; + } while (1); +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtEcho(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Echo{ + Exprs: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + }) + + expected := `echo $a, $b;` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtElseIfStmts(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.ElseIf{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Nop{}, + }, + }, + }) + + expected := `elseif ($a) { + ; +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtElseIfExpr(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.ElseIf{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Stmt: &stmt.Expression{Expr: &scalar.String{Value: "'bar'"}}, + }) + + expected := `elseif ($a) + 'bar';` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtElseIfNop(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.ElseIf{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Stmt: &stmt.Nop{}, + }) + + expected := `elseif ($a);` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtElseStmts(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Else{ + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Nop{}, + }, + }, + }) + + expected := `else { + ; +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtElseExpr(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Else{ + Stmt: &stmt.Expression{Expr: &scalar.String{Value: "'bar'"}}, + }) + + expected := `else + 'bar';` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtElseNop(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Else{ + Stmt: &stmt.Nop{}, + }) + + expected := `else;` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintExpression(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}) + + expected := `$a;` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtFinally(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &stmt.Finally{ + Stmts: []node.Node{ + &stmt.Nop{}, + }, + }, + }, + }) + + expected := `namespace { + finally { + ; + } +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtForStmts(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &stmt.For{ + Init: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + Cond: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "c"}}, + &expr.Variable{VarName: &node.Identifier{Value: "d"}}, + }, + Loop: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "e"}}, + &expr.Variable{VarName: &node.Identifier{Value: "f"}}, + }, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Nop{}, + }, + }, + }, + }, + }) + + expected := `namespace { + for ($a, $b; $c, $d; $e, $f) { + ; + } +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtForExpr(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &stmt.For{ + Init: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + }, + Cond: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + Loop: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "c"}}, + }, + Stmt: &stmt.Expression{Expr: &scalar.String{Value: "'bar'"}}, + }, + }, + }) + + expected := `namespace { + for ($a; $b; $c) + 'bar'; +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtForNop(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.For{ + Init: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + }, + Cond: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + Loop: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "c"}}, + }, + Stmt: &stmt.Nop{}, + }) + + expected := `for ($a; $b; $c);` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtForeachStmts(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &stmt.Foreach{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Variable: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Nop{}, + }, + }, + }, + }, + }) + + expected := `namespace { + foreach ($a as $b) { + ; + } +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtForeachExpr(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &stmt.Foreach{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Key: &expr.Variable{VarName: &node.Identifier{Value: "k"}}, + Variable: &expr.Variable{VarName: &node.Identifier{Value: "v"}}, + Stmt: &stmt.Expression{Expr: &scalar.String{Value: "'bar'"}}, + }, + }, + }) + + expected := `namespace { + foreach ($a as $k => $v) + 'bar'; +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtForeachNop(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Foreach{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Key: &expr.Variable{VarName: &node.Identifier{Value: "k"}}, + Variable: &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "v"}}}, + Stmt: &stmt.Nop{}, + }) + + expected := `foreach ($a as $k => &$v);` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtFunction(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &stmt.Function{ + ReturnsRef: true, + FunctionName: &node.Identifier{Value: "foo"}, + Params: []node.Node{ + &node.Parameter{ + ByRef: true, + Variadic: false, + Variable: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }, + }, + ReturnType: &name.FullyQualified{Parts: []node.Node{&name.NamePart{Value: "Foo"}}}, + Stmts: []node.Node{ + &stmt.Nop{}, + }, + }, + }, + }) + + expected := `namespace { + function &foo(&$var): \Foo { + ; + } +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtGlobal(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Global{ + Vars: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + }) + + expected := `global $a, $b;` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtGoto(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Goto{ + Label: &node.Identifier{Value: "FOO"}, + }) + + expected := `goto FOO;` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintStmtGroupUse(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.GroupUse{ + UseType: &node.Identifier{Value: "function"}, + Prefix: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}}, + UseList: []node.Node{ + &stmt.Use{ + Use: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}}, + Alias: &node.Identifier{Value: "Baz"}, + }, + &stmt.Use{ + Use: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Quuz"}}}, + }, + }, + }) + + expected := `use function Foo\{Bar as Baz, Quuz};` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintHaltCompiler(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.HaltCompiler{}) + + expected := `__halt_compiler();` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintIfExpression(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &stmt.If{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Stmt: &stmt.Expression{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + ElseIf: []node.Node{ + &stmt.ElseIf{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "c"}}, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "d"}}, + }, + }, + }, + }, + &stmt.ElseIf{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "e"}}, + Stmt: &stmt.Nop{}, + }, + }, + Else: &stmt.Else{ + Stmt: &stmt.Expression{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "f"}}, + }, + }, + }, + }, + }) + + expected := `namespace { + if ($a) + $b; + elseif ($c) { + $d; + } + elseif ($e); + else + $f; +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintIfStmtList(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.Namespace{ + Stmts: []node.Node{ + &stmt.If{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + }, + }, + }, + }, + }) + + expected := `namespace { + if ($a) { + $b; + } +}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintIfNop(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.If{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Stmt: &stmt.Nop{}, + }) + + expected := `if ($a);` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintInlineHtml(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&stmt.InlineHtml{ + Value: "test", + }) + + expected := `?>test 0 { - firstStmt := v.Stmts[0] - v.Stmts = v.Stmts[1:] + var stmts []node.Node + + if len(nn.Stmts) > 0 { + firstStmt := nn.Stmts[0] + stmts = nn.Stmts[1:] switch fs := firstStmt.(type) { case *stmt.InlineHtml: io.WriteString(p.w, fs.Value) - io.WriteString(p.w, " 0 { @@ -506,62 +540,108 @@ func (p *Printer) printNameName(n node.Node) { p.Print(part) } + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printNameFullyQualified(n node.Node) { nn := n.(*name.FullyQualified) + p.printMeta(nn, meta.NodeStart) + + p.printMeta(nn, meta.NsSeparatorToken) for _, part := range nn.Parts { io.WriteString(p.w, "\\") p.Print(part) } + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printNameRelative(n node.Node) { nn := n.(*name.Relative) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.NamespaceToken) io.WriteString(p.w, "namespace") - for _, part := range nn.Parts { + for k, part := range nn.Parts { + if k == 0 { + p.printMeta(nn, meta.NsSeparatorToken) + } io.WriteString(p.w, "\\") p.Print(part) } + + p.printMeta(nn, meta.NodeEnd) } // scalar func (p *Printer) printScalarLNumber(n node.Node) { - v := n.(*scalar.Lnumber).Value - io.WriteString(p.w, v) + nn := n.(*scalar.Lnumber) + p.printMeta(nn, meta.NodeStart) + + p.printMeta(nn, meta.LnumberToken) + + io.WriteString(p.w, nn.Value) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printScalarDNumber(n node.Node) { - v := n.(*scalar.Dnumber).Value - io.WriteString(p.w, v) + nn := n.(*scalar.Dnumber) + p.printMeta(nn, meta.NodeStart) + + p.printMeta(nn, meta.DnumberToken) + + io.WriteString(p.w, nn.Value) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printScalarString(n node.Node) { - v := n.(*scalar.String).Value + nn := n.(*scalar.String) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, v) + p.printMeta(nn, meta.ConstantEncapsedStringToken) + + io.WriteString(p.w, nn.Value) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printScalarEncapsedStringPart(n node.Node) { - v := n.(*scalar.EncapsedStringPart).Value - io.WriteString(p.w, v) + nn := n.(*scalar.EncapsedStringPart) + p.printMeta(nn, meta.NodeStart) + + p.printMeta(nn, meta.EncapsedAndWhitespaceToken) + + io.WriteString(p.w, nn.Value) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printScalarEncapsed(n node.Node) { + nn := n.(*scalar.Encapsed) + p.printMeta(nn, meta.NodeStart) + + p.printMeta(nn, meta.DoubleQuoteToken) io.WriteString(p.w, "\"") - for _, nn := range n.(*scalar.Encapsed).Parts { - p.Print(nn) + for _, part := range nn.Parts { + p.Print(part) } io.WriteString(p.w, "\"") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printScalarHeredoc(n node.Node) { nn := n.(*scalar.Heredoc) + p.printMeta(nn, meta.NodeStart) + + p.printMeta(nn, meta.StartHeredocToken) io.WriteString(p.w, "<<<") io.WriteString(p.w, nn.Label) @@ -572,1611 +652,2228 @@ func (p *Printer) printScalarHeredoc(n node.Node) { } io.WriteString(p.w, strings.Trim(nn.Label, "\"'")) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printScalarMagicConstant(n node.Node) { - v := n.(*scalar.MagicConstant).Value - io.WriteString(p.w, v) + nn := n.(*scalar.MagicConstant) + p.printMeta(nn, meta.NodeStart) + + p.printMeta(nn, meta.MagicConstantToken) + + io.WriteString(p.w, nn.Value) + + p.printMeta(nn, meta.NodeEnd) } // Assign func (p *Printer) printAssign(n node.Node) { nn := n.(*assign.Assign) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) - io.WriteString(p.w, " = ") + p.printMeta(nn, meta.EqualToken) + io.WriteString(p.w, "=") p.Print(nn.Expression) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printReference(n node.Node) { nn := n.(*assign.Reference) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) - io.WriteString(p.w, " =& ") + p.printMeta(nn, meta.EqualToken) + io.WriteString(p.w, "=") + p.printMeta(nn, meta.AmpersandToken) + io.WriteString(p.w, "&") p.Print(nn.Expression) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printAssignBitwiseAnd(n node.Node) { nn := n.(*assign.BitwiseAnd) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) - io.WriteString(p.w, " &= ") + p.printMeta(nn, meta.AndEqualToken) + io.WriteString(p.w, "&") + io.WriteString(p.w, "=") p.Print(nn.Expression) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printAssignBitwiseOr(n node.Node) { nn := n.(*assign.BitwiseOr) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) - io.WriteString(p.w, " |= ") + p.printMeta(nn, meta.OrEqualToken) + io.WriteString(p.w, "|=") p.Print(nn.Expression) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printAssignBitwiseXor(n node.Node) { nn := n.(*assign.BitwiseXor) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) - io.WriteString(p.w, " ^= ") + p.printMeta(nn, meta.XorEqualToken) + io.WriteString(p.w, "^=") p.Print(nn.Expression) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printAssignConcat(n node.Node) { nn := n.(*assign.Concat) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) - io.WriteString(p.w, " .= ") + p.printMeta(nn, meta.ConcatEqualToken) + io.WriteString(p.w, ".=") p.Print(nn.Expression) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printAssignDiv(n node.Node) { nn := n.(*assign.Div) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) - io.WriteString(p.w, " /= ") + p.printMeta(nn, meta.DivEqualToken) + io.WriteString(p.w, "/=") p.Print(nn.Expression) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printAssignMinus(n node.Node) { nn := n.(*assign.Minus) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) - io.WriteString(p.w, " -= ") + p.printMeta(nn, meta.MinusEqualToken) + io.WriteString(p.w, "-=") p.Print(nn.Expression) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printAssignMod(n node.Node) { nn := n.(*assign.Mod) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) - io.WriteString(p.w, " %= ") + p.printMeta(nn, meta.ModEqualToken) + io.WriteString(p.w, "%=") p.Print(nn.Expression) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printAssignMul(n node.Node) { nn := n.(*assign.Mul) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) - io.WriteString(p.w, " *= ") + p.printMeta(nn, meta.MulEqualToken) + io.WriteString(p.w, "*=") p.Print(nn.Expression) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printAssignPlus(n node.Node) { nn := n.(*assign.Plus) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) - io.WriteString(p.w, " += ") + p.printMeta(nn, meta.PlusEqualToken) + io.WriteString(p.w, "+=") p.Print(nn.Expression) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printAssignPow(n node.Node) { nn := n.(*assign.Pow) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) - io.WriteString(p.w, " **= ") + p.printMeta(nn, meta.PowEqualToken) + io.WriteString(p.w, "**=") p.Print(nn.Expression) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printAssignShiftLeft(n node.Node) { nn := n.(*assign.ShiftLeft) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) - io.WriteString(p.w, " <<= ") + p.printMeta(nn, meta.SlEqualToken) + io.WriteString(p.w, "<<=") p.Print(nn.Expression) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printAssignShiftRight(n node.Node) { nn := n.(*assign.ShiftRight) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) - io.WriteString(p.w, " >>= ") + p.printMeta(nn, meta.SrEqualToken) + io.WriteString(p.w, ">>=") p.Print(nn.Expression) + + p.printMeta(nn, meta.NodeEnd) } // binary func (p *Printer) printBinaryBitwiseAnd(n node.Node) { nn := n.(*binary.BitwiseAnd) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " & ") + p.printMeta(nn, meta.AmpersandToken) + io.WriteString(p.w, "&") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryBitwiseOr(n node.Node) { nn := n.(*binary.BitwiseOr) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " | ") + p.printMeta(nn, meta.VerticalBarToken) + io.WriteString(p.w, "|") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryBitwiseXor(n node.Node) { nn := n.(*binary.BitwiseXor) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " ^ ") + p.printMeta(nn, meta.CaretToken) + io.WriteString(p.w, "^") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryBooleanAnd(n node.Node) { nn := n.(*binary.BooleanAnd) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " && ") + p.printMeta(nn, meta.BooleanAndToken) + io.WriteString(p.w, "&&") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryBooleanOr(n node.Node) { nn := n.(*binary.BooleanOr) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " || ") + p.printMeta(nn, meta.BooleanOrToken) + io.WriteString(p.w, "||") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryCoalesce(n node.Node) { nn := n.(*binary.Coalesce) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " ?? ") + p.printMeta(nn, meta.CoalesceToken) + io.WriteString(p.w, "??") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryConcat(n node.Node) { nn := n.(*binary.Concat) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " . ") + p.printMeta(nn, meta.DotToken) + io.WriteString(p.w, ".") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryDiv(n node.Node) { nn := n.(*binary.Div) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " / ") + p.printMeta(nn, meta.SlashToken) + io.WriteString(p.w, "/") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryEqual(n node.Node) { nn := n.(*binary.Equal) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " == ") + p.printMeta(nn, meta.IsEqualToken) + io.WriteString(p.w, "==") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryGreaterOrEqual(n node.Node) { nn := n.(*binary.GreaterOrEqual) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " >= ") + p.printMeta(nn, meta.IsGreaterOrEqualToken) + io.WriteString(p.w, ">=") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryGreater(n node.Node) { nn := n.(*binary.Greater) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " > ") + p.printMeta(nn, meta.GreaterToken) + io.WriteString(p.w, ">") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryIdentical(n node.Node) { nn := n.(*binary.Identical) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " === ") + p.printMeta(nn, meta.IsIdenticalToken) + io.WriteString(p.w, "===") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryLogicalAnd(n node.Node) { nn := n.(*binary.LogicalAnd) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " and ") + p.printMeta(nn, meta.LogicalAndToken) + io.WriteString(p.w, "and") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryLogicalOr(n node.Node) { nn := n.(*binary.LogicalOr) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " or ") + p.printMeta(nn, meta.LogicalOrToken) + io.WriteString(p.w, "or") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryLogicalXor(n node.Node) { nn := n.(*binary.LogicalXor) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " xor ") + p.printMeta(nn, meta.LogicalXorToken) + io.WriteString(p.w, "xor") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryMinus(n node.Node) { nn := n.(*binary.Minus) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " - ") + p.printMeta(nn, meta.MinusToken) + io.WriteString(p.w, "-") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryMod(n node.Node) { nn := n.(*binary.Mod) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " % ") + p.printMeta(nn, meta.PercentToken) + io.WriteString(p.w, "%") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryMul(n node.Node) { nn := n.(*binary.Mul) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " * ") + p.printMeta(nn, meta.AsteriskToken) + io.WriteString(p.w, "*") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryNotEqual(n node.Node) { nn := n.(*binary.NotEqual) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " != ") + p.printMeta(nn, meta.IsNotEqualToken) + io.WriteString(p.w, "!=") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryNotIdentical(n node.Node) { nn := n.(*binary.NotIdentical) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " !== ") + p.printMeta(nn, meta.IsNotIdenticalToken) + io.WriteString(p.w, "!==") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryPlus(n node.Node) { nn := n.(*binary.Plus) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " + ") + p.printMeta(nn, meta.PlusToken) + io.WriteString(p.w, "+") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryPow(n node.Node) { nn := n.(*binary.Pow) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " ** ") + p.printMeta(nn, meta.PowToken) + io.WriteString(p.w, "**") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryShiftLeft(n node.Node) { nn := n.(*binary.ShiftLeft) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " << ") + p.printMeta(nn, meta.SlToken) + io.WriteString(p.w, "<<") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinaryShiftRight(n node.Node) { nn := n.(*binary.ShiftRight) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " >> ") + p.printMeta(nn, meta.SrToken) + io.WriteString(p.w, ">>") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinarySmallerOrEqual(n node.Node) { nn := n.(*binary.SmallerOrEqual) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " <= ") + p.printMeta(nn, meta.IsSmallerOrEqualToken) + io.WriteString(p.w, "<=") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinarySmaller(n node.Node) { nn := n.(*binary.Smaller) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " < ") + p.printMeta(nn, meta.LessToken) + io.WriteString(p.w, "<") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBinarySpaceship(n node.Node) { nn := n.(*binary.Spaceship) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Left) - io.WriteString(p.w, " <=> ") + p.printMeta(nn, meta.SpaceshipToken) + io.WriteString(p.w, "<=>") p.Print(nn.Right) + + p.printMeta(nn, meta.NodeEnd) } // cast func (p *Printer) printArray(n node.Node) { nn := n.(*cast.Array) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.ArrayCastToken) io.WriteString(p.w, "(array)") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printBool(n node.Node) { nn := n.(*cast.Bool) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.BoolCastToken) io.WriteString(p.w, "(bool)") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printDouble(n node.Node) { nn := n.(*cast.Double) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.DoubleCastToken) io.WriteString(p.w, "(float)") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printInt(n node.Node) { nn := n.(*cast.Int) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.IntCastToken) io.WriteString(p.w, "(int)") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printObject(n node.Node) { nn := n.(*cast.Object) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.ObjectCastToken) io.WriteString(p.w, "(object)") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printString(n node.Node) { nn := n.(*cast.String) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.StringCastToken) io.WriteString(p.w, "(string)") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printUnset(n node.Node) { nn := n.(*cast.Unset) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.UnsetCastToken) io.WriteString(p.w, "(unset)") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } // expr func (p *Printer) printExprArrayDimFetch(n node.Node) { nn := n.(*expr.ArrayDimFetch) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) + p.printMeta(nn, meta.OpenSquareBracket) io.WriteString(p.w, "[") p.Print(nn.Dim) + p.printMeta(nn, meta.CloseSquareBracket) io.WriteString(p.w, "]") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprArrayItem(n node.Node) { nn := n.(*expr.ArrayItem) + p.printMeta(nn, meta.NodeStart) if nn.Key != nil { p.Print(nn.Key) - io.WriteString(p.w, " => ") + p.printMeta(nn, meta.DoubleArrowToken) + io.WriteString(p.w, "=>") } p.Print(nn.Val) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprArray(n node.Node) { nn := n.(*expr.Array) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "array(") - p.joinPrint(", ", nn.Items) + p.printMeta(nn, meta.ArrayToken) + io.WriteString(p.w, "array") + p.printMeta(nn, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") + p.joinPrint(",", nn.Items) + p.printMeta(nn, meta.CloseParenthesisToken) io.WriteString(p.w, ")") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprBitwiseNot(n node.Node) { nn := n.(*expr.BitwiseNot) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.TildeToken) io.WriteString(p.w, "~") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprBooleanNot(n node.Node) { nn := n.(*expr.BooleanNot) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.ExclamationMarkToken) io.WriteString(p.w, "!") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprClassConstFetch(n node.Node) { nn := n.(*expr.ClassConstFetch) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Class) + p.printMeta(nn, meta.PaamayimNekudotayimToken) io.WriteString(p.w, "::") - io.WriteString(p.w, nn.ConstantName.(*node.Identifier).Value) + p.Print(nn.ConstantName) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprClone(n node.Node) { nn := n.(*expr.Clone) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "clone ") + p.printMeta(nn, meta.CloneToken) + io.WriteString(p.w, "clone") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprClosureUse(n node.Node) { nn := n.(*expr.ClosureUse) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "use (") - p.joinPrint(", ", nn.Uses) + p.printMeta(nn, meta.UseToken) + io.WriteString(p.w, "use") + p.printMeta(nn, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") + p.joinPrint(",", nn.Uses) + p.printMeta(nn, meta.CloseParenthesisToken) io.WriteString(p.w, ")") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprClosure(n node.Node) { nn := n.(*expr.Closure) + p.printMeta(nn, meta.NodeStart) if nn.Static { - io.WriteString(p.w, "static ") + p.printMeta(nn, meta.StaticToken) + io.WriteString(p.w, "static") } - io.WriteString(p.w, "function ") + p.printMeta(nn, meta.FunctionToken) + io.WriteString(p.w, "function") if nn.ReturnsRef { + p.printMeta(nn, meta.AmpersandToken) io.WriteString(p.w, "&") } + p.printMeta(nn, meta.OpenParenthesisToken) io.WriteString(p.w, "(") - p.joinPrint(", ", nn.Params) + p.joinPrint(",", nn.Params) + p.printMeta(nn, meta.CloseParenthesisToken) io.WriteString(p.w, ")") if nn.ClosureUse != nil { - io.WriteString(p.w, " ") p.Print(nn.ClosureUse) } if nn.ReturnType != nil { - io.WriteString(p.w, ": ") + p.printMeta(nn.ReturnType, meta.ColonToken) + io.WriteString(p.w, ":") p.Print(nn.ReturnType) } - io.WriteString(p.w, " {\n") + p.printMeta(nn, meta.OpenCurlyBracesToken) + io.WriteString(p.w, "{") p.printNodes(nn.Stmts) - io.WriteString(p.w, "\n") - p.printIndent() + p.printMeta(nn, meta.CloseCurlyBracesToken) io.WriteString(p.w, "}") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprConstFetch(n node.Node) { nn := n.(*expr.ConstFetch) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Constant) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprDie(n node.Node) { nn := n.(*expr.Die) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "die(") + p.printMeta(nn, meta.ExitToken) + io.WriteString(p.w, "die") + p.printMeta(nn.Expr, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") p.Print(nn.Expr) + p.printMeta(nn.Expr, meta.CloseParenthesisToken) io.WriteString(p.w, ")") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprEmpty(n node.Node) { nn := n.(*expr.Empty) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "empty(") + p.printMeta(nn, meta.EmptyToken) + io.WriteString(p.w, "empty") + p.printMeta(nn, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") p.Print(nn.Expr) + p.printMeta(nn, meta.CloseParenthesisToken) io.WriteString(p.w, ")") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprErrorSuppress(n node.Node) { nn := n.(*expr.ErrorSuppress) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.AtToken) io.WriteString(p.w, "@") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprEval(n node.Node) { nn := n.(*expr.Eval) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "eval(") + p.printMeta(nn, meta.EvalToken) + io.WriteString(p.w, "eval") + p.printMeta(nn, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") p.Print(nn.Expr) + p.printMeta(nn, meta.CloseParenthesisToken) io.WriteString(p.w, ")") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprExit(n node.Node) { nn := n.(*expr.Exit) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "exit(") + p.printMeta(nn, meta.ExitToken) + io.WriteString(p.w, "exit") + p.printMeta(nn.Expr, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") p.Print(nn.Expr) + p.printMeta(nn.Expr, meta.CloseParenthesisToken) io.WriteString(p.w, ")") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprFunctionCall(n node.Node) { nn := n.(*expr.FunctionCall) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Function) + p.printMeta(nn.ArgumentList, meta.OpenParenthesisToken) io.WriteString(p.w, "(") - p.joinPrint(", ", nn.ArgumentList.Arguments) + p.joinPrint(",", nn.ArgumentList.Arguments) + p.printMeta(nn.ArgumentList, meta.CloseParenthesisToken) io.WriteString(p.w, ")") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprInclude(n node.Node) { nn := n.(*expr.Include) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "include ") + p.printMeta(nn, meta.IncludeToken) + io.WriteString(p.w, "include") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprIncludeOnce(n node.Node) { nn := n.(*expr.IncludeOnce) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "include_once ") + p.printMeta(nn, meta.IncludeOnceToken) + io.WriteString(p.w, "include_once") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprInstanceOf(n node.Node) { nn := n.(*expr.InstanceOf) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Expr) - io.WriteString(p.w, " instanceof ") + p.printMeta(nn, meta.InstanceofToken) + io.WriteString(p.w, "instanceof") p.Print(nn.Class) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprIsset(n node.Node) { nn := n.(*expr.Isset) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "isset(") - p.joinPrint(", ", nn.Variables) + p.printMeta(nn, meta.IssetToken) + io.WriteString(p.w, "isset") + p.printMeta(nn, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") + p.joinPrint(",", nn.Variables) + p.printMeta(nn, meta.CloseParenthesisToken) io.WriteString(p.w, ")") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprList(n node.Node) { nn := n.(*expr.List) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "list(") - p.joinPrint(", ", nn.Items) + p.printMeta(nn, meta.ListToken) + io.WriteString(p.w, "list") + p.printMeta(nn, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") + p.joinPrint(",", nn.Items) + p.printMeta(nn, meta.CloseParenthesisToken) io.WriteString(p.w, ")") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprMethodCall(n node.Node) { nn := n.(*expr.MethodCall) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) + p.printMeta(nn, meta.ObjectOperatorToken) io.WriteString(p.w, "->") p.Print(nn.Method) + p.printMeta(nn.ArgumentList, meta.OpenParenthesisToken) io.WriteString(p.w, "(") - p.joinPrint(", ", nn.ArgumentList.Arguments) + p.joinPrint(",", nn.ArgumentList.Arguments) + p.printMeta(nn.ArgumentList, meta.CloseParenthesisToken) io.WriteString(p.w, ")") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprNew(n node.Node) { nn := n.(*expr.New) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "new ") + p.printMeta(nn, meta.NewToken) + io.WriteString(p.w, "new") p.Print(nn.Class) if nn.ArgumentList != nil { + p.printMeta(nn.ArgumentList, meta.OpenParenthesisToken) io.WriteString(p.w, "(") - p.joinPrint(", ", nn.ArgumentList.Arguments) + p.joinPrint(",", nn.ArgumentList.Arguments) + p.printMeta(nn.ArgumentList, meta.CloseParenthesisToken) io.WriteString(p.w, ")") } + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprPostDec(n node.Node) { nn := n.(*expr.PostDec) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) + p.printMeta(nn, meta.DecToken) io.WriteString(p.w, "--") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprPostInc(n node.Node) { nn := n.(*expr.PostInc) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) + p.printMeta(nn, meta.IncToken) io.WriteString(p.w, "++") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprPreDec(n node.Node) { nn := n.(*expr.PreDec) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.DecToken) io.WriteString(p.w, "--") p.Print(nn.Variable) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprPreInc(n node.Node) { nn := n.(*expr.PreInc) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.IncToken) io.WriteString(p.w, "++") p.Print(nn.Variable) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprPrint(n node.Node) { nn := n.(*expr.Print) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "print(") + p.printMeta(nn, meta.PrintToken) + io.WriteString(p.w, "print") + p.printMeta(nn.Expr, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") p.Print(nn.Expr) + p.printMeta(nn.Expr, meta.CloseParenthesisToken) io.WriteString(p.w, ")") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprPropertyFetch(n node.Node) { nn := n.(*expr.PropertyFetch) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Variable) + p.printMeta(nn, meta.ObjectOperatorToken) io.WriteString(p.w, "->") p.Print(nn.Property) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprReference(n node.Node) { nn := n.(*expr.Reference) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.AmpersandToken) io.WriteString(p.w, "&") p.Print(nn.Variable) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprRequire(n node.Node) { nn := n.(*expr.Require) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "require ") + p.printMeta(nn, meta.RequireToken) + io.WriteString(p.w, "require") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprRequireOnce(n node.Node) { nn := n.(*expr.RequireOnce) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "require_once ") + p.printMeta(nn, meta.RequireOnceToken) + io.WriteString(p.w, "require_once") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprShellExec(n node.Node) { nn := n.(*expr.ShellExec) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.BackquoteToken) io.WriteString(p.w, "`") for _, part := range nn.Parts { p.Print(part) } io.WriteString(p.w, "`") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprShortArray(n node.Node) { nn := n.(*expr.ShortArray) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.OpenSquareBracket) io.WriteString(p.w, "[") - p.joinPrint(", ", nn.Items) + p.joinPrint(",", nn.Items) + p.printMeta(nn, meta.CloseSquareBracket) io.WriteString(p.w, "]") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprShortList(n node.Node) { nn := n.(*expr.ShortList) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.OpenSquareBracket) io.WriteString(p.w, "[") - p.joinPrint(", ", nn.Items) + p.joinPrint(",", nn.Items) + p.printMeta(nn, meta.CloseSquareBracket) io.WriteString(p.w, "]") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprStaticCall(n node.Node) { nn := n.(*expr.StaticCall) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Class) + p.printMeta(nn, meta.PaamayimNekudotayimToken) io.WriteString(p.w, "::") p.Print(nn.Call) + p.printMeta(nn.ArgumentList, meta.OpenParenthesisToken) io.WriteString(p.w, "(") - p.joinPrint(", ", nn.ArgumentList.Arguments) + p.joinPrint(",", nn.ArgumentList.Arguments) + p.printMeta(nn.ArgumentList, meta.CloseParenthesisToken) io.WriteString(p.w, ")") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprStaticPropertyFetch(n node.Node) { nn := n.(*expr.StaticPropertyFetch) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Class) + p.printMeta(nn, meta.PaamayimNekudotayimToken) io.WriteString(p.w, "::") p.Print(nn.Property) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprTernary(n node.Node) { nn := n.(*expr.Ternary) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Condition) - io.WriteString(p.w, " ?") + p.printMeta(nn, meta.QuestionMarkToken) + io.WriteString(p.w, "?") if nn.IfTrue != nil { - io.WriteString(p.w, " ") p.Print(nn.IfTrue) - io.WriteString(p.w, " ") } - io.WriteString(p.w, ": ") + p.printMeta(nn, meta.ColonToken) + io.WriteString(p.w, ":") p.Print(nn.IfFalse) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprUnaryMinus(n node.Node) { nn := n.(*expr.UnaryMinus) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.MinusToken) io.WriteString(p.w, "-") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprUnaryPlus(n node.Node) { nn := n.(*expr.UnaryPlus) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.PlusToken) io.WriteString(p.w, "+") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprVariable(n node.Node) { + nn := n.(*expr.Variable) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.VariableToken) io.WriteString(p.w, "$") - p.Print(n.(*expr.Variable).VarName) + p.Print(nn.VarName) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprYieldFrom(n node.Node) { nn := n.(*expr.YieldFrom) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "yield from ") + p.printMeta(nn, meta.YieldFromToken) + io.WriteString(p.w, "yield from") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printExprYield(n node.Node) { nn := n.(*expr.Yield) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "yield ") + p.printMeta(nn, meta.YieldToken) + io.WriteString(p.w, "yield") if nn.Key != nil { p.Print(nn.Key) - io.WriteString(p.w, " => ") + p.printMeta(nn, meta.DoubleArrowToken) + io.WriteString(p.w, "=>") } p.Print(nn.Value) + + p.printMeta(nn, meta.NodeEnd) } // smtm func (p *Printer) printStmtAltElseIf(n node.Node) { nn := n.(*stmt.AltElseIf) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "elseif (") + p.printMeta(nn, meta.ElseifToken) + io.WriteString(p.w, "elseif") + p.printMeta(nn, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") p.Print(nn.Cond) - io.WriteString(p.w, ") :") + p.printMeta(nn, meta.CloseParenthesisToken) + io.WriteString(p.w, ")") + p.printMeta(nn, meta.ColonToken) + io.WriteString(p.w, ":") if s := nn.Stmt.(*stmt.StmtList).Stmts; len(s) > 0 { - io.WriteString(p.w, "\n") p.printNodes(s) } + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtAltElse(n node.Node) { nn := n.(*stmt.AltElse) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "else :") + p.printMeta(nn, meta.ElseToken) + io.WriteString(p.w, "else") + p.printMeta(nn, meta.ColonToken) + io.WriteString(p.w, ":") if s := nn.Stmt.(*stmt.StmtList).Stmts; len(s) > 0 { - io.WriteString(p.w, "\n") p.printNodes(s) } + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtAltFor(n node.Node) { nn := n.(*stmt.AltFor) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "for (") - p.joinPrint(", ", nn.Init) - io.WriteString(p.w, "; ") - p.joinPrint(", ", nn.Cond) - io.WriteString(p.w, "; ") - p.joinPrint(", ", nn.Loop) - io.WriteString(p.w, ") :\n") + p.printMeta(nn, meta.ForToken) + io.WriteString(p.w, "for") + p.printMeta(nn, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") + p.joinPrint(",", nn.Init) + p.printMeta(nn, meta.ForInitSemicolonToken) + io.WriteString(p.w, ";") + p.joinPrint(",", nn.Cond) + p.printMeta(nn, meta.ForCondSemicolonToken) + io.WriteString(p.w, ";") + p.joinPrint(",", nn.Loop) + p.printMeta(nn, meta.CloseParenthesisToken) + io.WriteString(p.w, ")") + p.printMeta(nn, meta.ColonToken) + io.WriteString(p.w, ":") s := nn.Stmt.(*stmt.StmtList) p.printNodes(s.Stmts) - io.WriteString(p.w, "\n") - p.printIndent() - io.WriteString(p.w, "endfor;") + p.printMeta(nn, meta.EndforToken) + io.WriteString(p.w, "endfor") + p.printMeta(nn, meta.SemiColonToken) + io.WriteString(p.w, ";") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtAltForeach(n node.Node) { nn := n.(*stmt.AltForeach) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "foreach (") + p.printMeta(nn, meta.ForeachToken) + io.WriteString(p.w, "foreach") + p.printMeta(nn, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") p.Print(nn.Expr) - io.WriteString(p.w, " as ") + p.printMeta(nn, meta.AsToken) + io.WriteString(p.w, "as") if nn.Key != nil { p.Print(nn.Key) - io.WriteString(p.w, " => ") + p.printMeta(nn, meta.DoubleArrowToken) + io.WriteString(p.w, "=>") } p.Print(nn.Variable) - io.WriteString(p.w, ") :\n") + p.printMeta(nn, meta.CloseParenthesisToken) + io.WriteString(p.w, ")") + p.printMeta(nn, meta.ColonToken) + io.WriteString(p.w, ":") s := nn.Stmt.(*stmt.StmtList) p.printNodes(s.Stmts) - io.WriteString(p.w, "\n") - p.printIndent() - io.WriteString(p.w, "endforeach;") + p.printMeta(nn, meta.EndforeachToken) + io.WriteString(p.w, "endforeach") + p.printMeta(nn, meta.SemiColonToken) + io.WriteString(p.w, ";") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtAltIf(n node.Node) { nn := n.(*stmt.AltIf) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "if (") + p.printMeta(nn, meta.IfToken) + io.WriteString(p.w, "if") + p.printMeta(nn, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") p.Print(nn.Cond) - io.WriteString(p.w, ") :\n") + p.printMeta(nn, meta.CloseParenthesisToken) + io.WriteString(p.w, ")") + p.printMeta(nn, meta.ColonToken) + io.WriteString(p.w, ":") s := nn.Stmt.(*stmt.StmtList) p.printNodes(s.Stmts) for _, elseif := range nn.ElseIf { - io.WriteString(p.w, "\n") - p.printIndent() p.Print(elseif) } if nn.Else != nil { - io.WriteString(p.w, "\n") - p.printIndent() p.Print(nn.Else) } - io.WriteString(p.w, "\n") - p.printIndent() - io.WriteString(p.w, "endif;") + p.printMeta(nn, meta.EndifToken) + io.WriteString(p.w, "endif") + p.printMeta(nn, meta.SemiColonToken) + io.WriteString(p.w, ";") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtAltSwitch(n node.Node) { nn := n.(*stmt.AltSwitch) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "switch (") + p.printMeta(nn, meta.SwitchToken) + io.WriteString(p.w, "switch") + p.printMeta(nn, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") p.Print(nn.Cond) - io.WriteString(p.w, ") :\n") + p.printMeta(nn, meta.CloseParenthesisToken) + io.WriteString(p.w, ")") + p.printMeta(nn, meta.ColonToken) + io.WriteString(p.w, ":") + p.printMeta(nn, meta.SwitchSemicolonToken) + io.WriteString(p.w, ";") s := nn.CaseList.Cases p.printNodes(s) - io.WriteString(p.w, "\n") - p.printIndent() - io.WriteString(p.w, "endswitch;") + p.printMeta(nn, meta.EndswitchToken) + io.WriteString(p.w, "endswitch") + p.printMeta(nn, meta.SemiColonToken) + io.WriteString(p.w, ";") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtAltWhile(n node.Node) { nn := n.(*stmt.AltWhile) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "while (") + p.printMeta(nn, meta.WhileToken) + io.WriteString(p.w, "while") + p.printMeta(nn, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") p.Print(nn.Cond) - io.WriteString(p.w, ") :\n") + p.printMeta(nn, meta.CloseParenthesisToken) + io.WriteString(p.w, ")") + p.printMeta(nn, meta.ColonToken) + io.WriteString(p.w, ":") s := nn.Stmt.(*stmt.StmtList) p.printNodes(s.Stmts) - io.WriteString(p.w, "\n") - p.printIndent() - io.WriteString(p.w, "endwhile;") + p.printMeta(nn, meta.EndwhileToken) + io.WriteString(p.w, "endwhile") + p.printMeta(nn, meta.SemiColonToken) + io.WriteString(p.w, ";") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtBreak(n node.Node) { nn := n.(*stmt.Break) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.BreakToken) io.WriteString(p.w, "break") if nn.Expr != nil { - io.WriteString(p.w, " ") + p.printMeta(nn.Expr, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") p.Print(nn.Expr) + p.printMeta(nn.Expr, meta.CloseParenthesisToken) + io.WriteString(p.w, ")") } + p.printMeta(nn, meta.SemiColonToken) io.WriteString(p.w, ";") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtCase(n node.Node) { nn := n.(*stmt.Case) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "case ") + p.printMeta(nn, meta.CaseToken) + io.WriteString(p.w, "case") p.Print(nn.Cond) + p.printMeta(nn, meta.CaseSeparatorToken) io.WriteString(p.w, ":") if len(nn.Stmts) > 0 { - io.WriteString(p.w, "\n") p.printNodes(nn.Stmts) } + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtCatch(n node.Node) { nn := n.(*stmt.Catch) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "catch (") - p.joinPrint(" | ", nn.Types) - io.WriteString(p.w, " ") + p.printMeta(nn, meta.CatchToken) + io.WriteString(p.w, "catch") + p.printMeta(nn, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") + p.joinPrint("|", nn.Types) p.Print(nn.Variable) - io.WriteString(p.w, ") {\n") + p.printMeta(nn, meta.CloseParenthesisToken) + io.WriteString(p.w, ")") + p.printMeta(nn, meta.OpenCurlyBracesToken) + io.WriteString(p.w, "{") p.printNodes(nn.Stmts) - io.WriteString(p.w, "\n") - p.printIndent() + p.printMeta(nn, meta.CloseCurlyBracesToken) io.WriteString(p.w, "}") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtClassMethod(n node.Node) { nn := n.(*stmt.ClassMethod) + p.printMeta(nn, meta.NodeStart) if nn.Modifiers != nil { - p.joinPrint(" ", nn.Modifiers) - io.WriteString(p.w, " ") + p.joinPrint("", nn.Modifiers) } - io.WriteString(p.w, "function ") + p.printMeta(nn, meta.FunctionToken) + io.WriteString(p.w, "function") if nn.ReturnsRef { + p.printMeta(nn, meta.AmpersandToken) io.WriteString(p.w, "&") } p.Print(nn.MethodName) + p.printMeta(nn, meta.OpenParenthesisToken) io.WriteString(p.w, "(") - p.joinPrint(", ", nn.Params) + p.joinPrint(",", nn.Params) + p.printMeta(nn, meta.CloseParenthesisToken) io.WriteString(p.w, ")") if nn.ReturnType != nil { - io.WriteString(p.w, ": ") + p.printMeta(nn.ReturnType, meta.ColonToken) + io.WriteString(p.w, ":") p.Print(nn.ReturnType) } - switch s := nn.Stmt.(type) { - case *stmt.StmtList: - io.WriteString(p.w, "\n") - p.printIndent() - io.WriteString(p.w, "{\n") - p.printNodes(s.Stmts) - io.WriteString(p.w, "\n") - p.printIndent() - io.WriteString(p.w, "}") - default: - p.Print(s) - } + p.Print(nn.Stmt) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtClass(n node.Node) { nn := n.(*stmt.Class) + p.printMeta(nn, meta.NodeStart) if nn.Modifiers != nil { - p.joinPrint(" ", nn.Modifiers) - io.WriteString(p.w, " ") + p.joinPrint("", nn.Modifiers) } + p.printMeta(nn, meta.ClassToken) io.WriteString(p.w, "class") if nn.ClassName != nil { - io.WriteString(p.w, " ") p.Print(nn.ClassName) } if nn.ArgumentList != nil { + p.printMeta(nn.ArgumentList, meta.OpenParenthesisToken) io.WriteString(p.w, "(") - p.joinPrint(", ", nn.ArgumentList.Arguments) + p.joinPrint(",", nn.ArgumentList.Arguments) + p.printMeta(nn.ArgumentList, meta.CloseParenthesisToken) io.WriteString(p.w, ")") } if nn.Extends != nil { - io.WriteString(p.w, " extends ") + p.printMeta(nn.Extends, meta.ExtendsToken) + io.WriteString(p.w, "extends") p.Print(nn.Extends.ClassName) } if nn.Implements != nil { - io.WriteString(p.w, " implements ") - p.joinPrint(", ", nn.Implements.InterfaceNames) + p.printMeta(nn.Implements, meta.ImplementsToken) + io.WriteString(p.w, "implements") + p.joinPrint(",", nn.Implements.InterfaceNames) } - io.WriteString(p.w, "\n") - p.printIndent() - io.WriteString(p.w, "{\n") + p.printMeta(nn, meta.OpenCurlyBracesToken) + io.WriteString(p.w, "{") p.printNodes(nn.Stmts) - io.WriteString(p.w, "\n") - p.printIndent() + p.printMeta(nn, meta.CloseCurlyBracesToken) io.WriteString(p.w, "}") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtClassConstList(n node.Node) { nn := n.(*stmt.ClassConstList) + p.printMeta(nn, meta.NodeStart) if nn.Modifiers != nil { - p.joinPrint(" ", nn.Modifiers) - io.WriteString(p.w, " ") + p.joinPrint("", nn.Modifiers) } - io.WriteString(p.w, "const ") + p.printMeta(nn, meta.ConstToken) + io.WriteString(p.w, "const") - p.joinPrint(", ", nn.Consts) + p.joinPrint(",", nn.Consts) + p.printMeta(nn, meta.SemiColonToken) io.WriteString(p.w, ";") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtConstant(n node.Node) { nn := n.(*stmt.Constant) + p.printMeta(nn, meta.NodeStart) p.Print(nn.ConstantName) - io.WriteString(p.w, " = ") + p.printMeta(nn, meta.EqualToken) + io.WriteString(p.w, "=") p.Print(nn.Expr) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtContinue(n node.Node) { nn := n.(*stmt.Continue) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.ContinueToken) io.WriteString(p.w, "continue") + if nn.Expr != nil { - io.WriteString(p.w, " ") + p.printMeta(nn.Expr, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") p.Print(nn.Expr) + p.printMeta(nn.Expr, meta.CloseParenthesisToken) + io.WriteString(p.w, ")") } + p.printMeta(nn, meta.SemiColonToken) io.WriteString(p.w, ";") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtDeclare(n node.Node) { nn := n.(*stmt.Declare) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "declare(") - p.joinPrint(", ", nn.Consts) + p.printMeta(nn, meta.DeclareToken) + io.WriteString(p.w, "declare") + p.printMeta(nn, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") + p.joinPrint(",", nn.Consts) + p.printMeta(nn, meta.CloseParenthesisToken) io.WriteString(p.w, ")") - switch s := nn.Stmt.(type) { - case *stmt.Nop: - p.Print(s) - break - case *stmt.StmtList: - io.WriteString(p.w, " ") - p.Print(s) - default: - io.WriteString(p.w, "\n") - p.indentDepth++ - p.printIndent() - p.Print(s) - p.indentDepth-- - } + p.Print(nn.Stmt) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtDefault(n node.Node) { nn := n.(*stmt.Default) - io.WriteString(p.w, "default:") + p.printMeta(nn, meta.NodeStart) + + p.printMeta(nn, meta.DefaultToken) + io.WriteString(p.w, "default") + p.printMeta(nn, meta.CaseSeparatorToken) + io.WriteString(p.w, ":") if len(nn.Stmts) > 0 { - io.WriteString(p.w, "\n") p.printNodes(nn.Stmts) } + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtDo(n node.Node) { nn := n.(*stmt.Do) + p.printMeta(nn, meta.NodeStart) + + p.printMeta(nn, meta.DoToken) io.WriteString(p.w, "do") - switch s := nn.Stmt.(type) { - case *stmt.StmtList: - io.WriteString(p.w, " ") - p.Print(s) - io.WriteString(p.w, " ") - default: - io.WriteString(p.w, "\n") - p.indentDepth++ - p.printIndent() - p.Print(s) - p.indentDepth-- - io.WriteString(p.w, "\n") - p.printIndent() - } + p.Print(nn.Stmt) - io.WriteString(p.w, "while (") + p.printMeta(nn, meta.WhileToken) + io.WriteString(p.w, "while") + p.printMeta(nn, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") p.Print(nn.Cond) - io.WriteString(p.w, ");") + p.printMeta(nn, meta.CloseParenthesisToken) + io.WriteString(p.w, ")") + p.printMeta(nn, meta.SemiColonToken) + io.WriteString(p.w, ";") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtEcho(n node.Node) { nn := n.(*stmt.Echo) - io.WriteString(p.w, "echo ") - p.joinPrint(", ", nn.Exprs) + p.printMeta(nn, meta.NodeStart) + + p.printMeta(nn, meta.EchoToken) + io.WriteString(p.w, "echo") + p.joinPrint(",", nn.Exprs) + p.printMeta(nn, meta.SemiColonToken) io.WriteString(p.w, ";") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtElseif(n node.Node) { nn := n.(*stmt.ElseIf) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "elseif (") + p.printMeta(nn, meta.ElseifToken) + io.WriteString(p.w, "elseif") + p.printMeta(nn, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") p.Print(nn.Cond) + p.printMeta(nn, meta.CloseParenthesisToken) io.WriteString(p.w, ")") - switch s := nn.Stmt.(type) { - case *stmt.Nop: - p.Print(s) - break - case *stmt.StmtList: - io.WriteString(p.w, " ") - p.Print(s) - default: - io.WriteString(p.w, "\n") - p.indentDepth++ - p.printIndent() - p.Print(s) - p.indentDepth-- - } + p.Print(nn.Stmt) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtElse(n node.Node) { nn := n.(*stmt.Else) + p.printMeta(nn, meta.NodeStart) + p.printMeta(nn, meta.ElseToken) io.WriteString(p.w, "else") - switch s := nn.Stmt.(type) { - case *stmt.Nop: - p.Print(s) - break - case *stmt.StmtList: - io.WriteString(p.w, " ") - p.Print(s) - default: - io.WriteString(p.w, "\n") - p.indentDepth++ - p.printIndent() - p.Print(s) - p.indentDepth-- - } + p.Print(nn.Stmt) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtExpression(n node.Node) { nn := n.(*stmt.Expression) + p.printMeta(nn, meta.NodeStart) p.Print(nn.Expr) + p.printMeta(nn, meta.SemiColonToken) io.WriteString(p.w, ";") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtFinally(n node.Node) { nn := n.(*stmt.Finally) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "finally {\n") + p.printMeta(nn, meta.FinallyToken) + io.WriteString(p.w, "finally") + p.printMeta(nn, meta.OpenCurlyBracesToken) + io.WriteString(p.w, "{") p.printNodes(nn.Stmts) - io.WriteString(p.w, "\n") - p.printIndent() + p.printMeta(nn, meta.CloseCurlyBracesToken) io.WriteString(p.w, "}") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtFor(n node.Node) { nn := n.(*stmt.For) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "for (") - p.joinPrint(", ", nn.Init) - io.WriteString(p.w, "; ") - p.joinPrint(", ", nn.Cond) - io.WriteString(p.w, "; ") - p.joinPrint(", ", nn.Loop) + p.printMeta(nn, meta.ForToken) + io.WriteString(p.w, "for") + p.printMeta(nn, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") + p.joinPrint(",", nn.Init) + p.printMeta(nn, meta.ForInitSemicolonToken) + io.WriteString(p.w, ";") + p.joinPrint(",", nn.Cond) + p.printMeta(nn, meta.ForCondSemicolonToken) + io.WriteString(p.w, ";") + p.joinPrint(",", nn.Loop) + p.printMeta(nn, meta.CloseParenthesisToken) io.WriteString(p.w, ")") - switch s := nn.Stmt.(type) { - case *stmt.Nop: - p.Print(s) - break - case *stmt.StmtList: - io.WriteString(p.w, " ") - p.Print(s) - default: - io.WriteString(p.w, "\n") - p.indentDepth++ - p.printIndent() - p.Print(s) - p.indentDepth-- - } + p.Print(nn.Stmt) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtForeach(n node.Node) { nn := n.(*stmt.Foreach) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "foreach (") + p.printMeta(nn, meta.ForeachToken) + io.WriteString(p.w, "foreach") + p.printMeta(nn, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") p.Print(nn.Expr) - io.WriteString(p.w, " as ") + p.printMeta(nn, meta.AsToken) + io.WriteString(p.w, "as") if nn.Key != nil { p.Print(nn.Key) - io.WriteString(p.w, " => ") + p.printMeta(nn, meta.DoubleArrowToken) + io.WriteString(p.w, "=>") } p.Print(nn.Variable) + p.printMeta(nn, meta.CloseParenthesisToken) io.WriteString(p.w, ")") - switch s := nn.Stmt.(type) { - case *stmt.Nop: - p.Print(s) - break - case *stmt.StmtList: - io.WriteString(p.w, " ") - p.Print(s) - default: - io.WriteString(p.w, "\n") - p.indentDepth++ - p.printIndent() - p.Print(s) - p.indentDepth-- - } + p.Print(nn.Stmt) + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtFunction(n node.Node) { nn := n.(*stmt.Function) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "function ") + p.printMeta(nn, meta.FunctionToken) + io.WriteString(p.w, "function") if nn.ReturnsRef { + p.printMeta(nn, meta.AmpersandToken) io.WriteString(p.w, "&") } p.Print(nn.FunctionName) + p.printMeta(nn, meta.OpenParenthesisToken) io.WriteString(p.w, "(") - p.joinPrint(", ", nn.Params) + p.joinPrint(",", nn.Params) + p.printMeta(nn, meta.CloseParenthesisToken) io.WriteString(p.w, ")") if nn.ReturnType != nil { - io.WriteString(p.w, ": ") + p.printMeta(nn.ReturnType, meta.ColonToken) + io.WriteString(p.w, ":") p.Print(nn.ReturnType) } - io.WriteString(p.w, " {\n") + p.printMeta(nn, meta.OpenCurlyBracesToken) + io.WriteString(p.w, "{") p.printNodes(nn.Stmts) - io.WriteString(p.w, "\n") - p.printIndent() + p.printMeta(nn, meta.CloseCurlyBracesToken) io.WriteString(p.w, "}") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtGlobal(n node.Node) { nn := n.(*stmt.Global) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "global ") - p.joinPrint(", ", nn.Vars) + p.printMeta(nn, meta.GlobalToken) + io.WriteString(p.w, "global") + p.joinPrint(",", nn.Vars) + p.printMeta(nn, meta.SemiColonToken) io.WriteString(p.w, ";") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtGoto(n node.Node) { nn := n.(*stmt.Goto) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "goto ") + p.printMeta(nn, meta.GotoToken) + io.WriteString(p.w, "goto") p.Print(nn.Label) + p.printMeta(nn, meta.SemiColonToken) io.WriteString(p.w, ";") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtGroupUse(n node.Node) { nn := n.(*stmt.GroupUse) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "use ") + p.printMeta(nn, meta.UseToken) + io.WriteString(p.w, "use") if nn.UseType != nil { p.Print(nn.UseType) - io.WriteString(p.w, " ") } p.Print(nn.Prefix) - io.WriteString(p.w, "\\{") - p.joinPrint(", ", nn.UseList) - io.WriteString(p.w, "};") + p.printMeta(nn, meta.NsSeparatorToken) + io.WriteString(p.w, "\\") + p.printMeta(nn, meta.OpenCurlyBracesToken) + io.WriteString(p.w, "{") + p.joinPrint(",", nn.UseList) + p.printMeta(nn, meta.CloseCurlyBracesToken) + io.WriteString(p.w, "}") + p.printMeta(nn, meta.SemiColonToken) + io.WriteString(p.w, ";") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtHaltCompiler(n node.Node) { - io.WriteString(p.w, "__halt_compiler();") + nn := n.(*stmt.HaltCompiler) + p.printMeta(nn, meta.NodeStart) + + p.printMeta(n, meta.HaltCompilerToken) + io.WriteString(p.w, "__halt_compiler") + p.printMeta(n, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") + p.printMeta(n, meta.CloseParenthesisToken) + io.WriteString(p.w, ")") + p.printMeta(n, meta.SemiColonToken) + io.WriteString(p.w, ";") + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtIf(n node.Node) { nn := n.(*stmt.If) + p.printMeta(nn, meta.NodeStart) - io.WriteString(p.w, "if (") + p.printMeta(n, meta.IfToken) + io.WriteString(p.w, "if") + p.printMeta(n, meta.OpenParenthesisToken) + io.WriteString(p.w, "(") p.Print(nn.Cond) + p.printMeta(n, meta.CloseParenthesisToken) io.WriteString(p.w, ")") - switch s := nn.Stmt.(type) { - case *stmt.Nop: - p.Print(s) - break - case *stmt.StmtList: - io.WriteString(p.w, " ") - p.Print(s) - default: - io.WriteString(p.w, "\n") - p.indentDepth++ - p.printIndent() - p.Print(s) - p.indentDepth-- - } + p.Print(nn.Stmt) if nn.ElseIf != nil { - io.WriteString(p.w, "\n") - p.indentDepth-- p.printNodes(nn.ElseIf) - p.indentDepth++ } if nn.Else != nil { - io.WriteString(p.w, "\n") - p.printIndent() p.Print(nn.Else) } + + p.printMeta(nn, meta.NodeEnd) } func (p *Printer) printStmtInlineHTML(n node.Node) { nn := n.(*stmt.InlineHtml) + p.printMeta(nn, meta.NodeStart) + p.printMeta(n, meta.InlineHTMLToken) io.WriteString(p.w, "?>") io.WriteString(p.w, nn.Value) io.WriteString(p.w, "Hello + 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 := ` 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 := ` & $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 := ` $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 := ` & $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 := `test>= $b ; + ` + + actual := print(parse(src)) + + if src != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", src, actual) + } +} + +func TestParseAndPrintBinary(t *testing.T) { + src := `= $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 := ` 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 := `HTML"}, &stmt.Expression{ - Expr: &scalar.Heredoc{ - Label: "\"LBL\"", - Parts: []node.Node{ - &scalar.EncapsedStringPart{Value: "hello world\n"}, + Expr: &expr.Variable{ + VarName: &node.Identifier{ + Value: "a", }, }, }, }, }) - expected := `
HTML
HTML>= $b` + expected := `$a >>=$b` actual := o.String() if expected != actual { @@ -648,16 +989,22 @@ func TestPrintAssignShiftRight(t *testing.T) { // binary -func TestPrintBinaryBitwiseAnd(t *testing.T) { +func TestPrinterPrintBinaryBitwiseAnd(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.BitwiseAnd{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.AmpersandToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a & $b` + expected := `$a &$b` actual := o.String() if expected != actual { @@ -665,16 +1012,22 @@ func TestPrintBinaryBitwiseAnd(t *testing.T) { } } -func TestPrintBinaryBitwiseOr(t *testing.T) { +func TestPrinterPrintBinaryBitwiseOr(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.BitwiseOr{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.VerticalBarToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a | $b` + expected := `$a |$b` actual := o.String() if expected != actual { @@ -682,16 +1035,22 @@ func TestPrintBinaryBitwiseOr(t *testing.T) { } } -func TestPrintBinaryBitwiseXor(t *testing.T) { +func TestPrinterPrintBinaryBitwiseXor(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.BitwiseXor{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CaretToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a ^ $b` + expected := `$a ^$b` actual := o.String() if expected != actual { @@ -699,16 +1058,22 @@ func TestPrintBinaryBitwiseXor(t *testing.T) { } } -func TestPrintBinaryBooleanAnd(t *testing.T) { +func TestPrinterPrintBinaryBooleanAnd(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.BooleanAnd{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.BooleanAndToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a && $b` + expected := `$a &&$b` actual := o.String() if expected != actual { @@ -716,16 +1081,22 @@ func TestPrintBinaryBooleanAnd(t *testing.T) { } } -func TestPrintBinaryBooleanOr(t *testing.T) { +func TestPrinterPrintBinaryBooleanOr(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.BooleanOr{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.BooleanOrToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a || $b` + expected := `$a ||$b` actual := o.String() if expected != actual { @@ -733,16 +1104,22 @@ func TestPrintBinaryBooleanOr(t *testing.T) { } } -func TestPrintBinaryCoalesce(t *testing.T) { +func TestPrinterPrintBinaryCoalesce(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.Coalesce{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CoalesceToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a ?? $b` + expected := `$a ??$b` actual := o.String() if expected != actual { @@ -750,16 +1127,22 @@ func TestPrintBinaryCoalesce(t *testing.T) { } } -func TestPrintBinaryConcat(t *testing.T) { +func TestPrinterPrintBinaryConcat(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.Concat{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.DotToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a . $b` + expected := `$a .$b` actual := o.String() if expected != actual { @@ -767,16 +1150,22 @@ func TestPrintBinaryConcat(t *testing.T) { } } -func TestPrintBinaryDiv(t *testing.T) { +func TestPrinterPrintBinaryDiv(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.Div{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SlashToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a / $b` + expected := `$a /$b` actual := o.String() if expected != actual { @@ -784,16 +1173,22 @@ func TestPrintBinaryDiv(t *testing.T) { } } -func TestPrintBinaryEqual(t *testing.T) { +func TestPrinterPrintBinaryEqual(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.Equal{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.IsEqualToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a == $b` + expected := `$a ==$b` actual := o.String() if expected != actual { @@ -801,16 +1196,22 @@ func TestPrintBinaryEqual(t *testing.T) { } } -func TestPrintBinaryGreaterOrEqual(t *testing.T) { +func TestPrinterPrintBinaryGreaterOrEqual(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.GreaterOrEqual{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.IsGreaterOrEqualToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a >= $b` + expected := `$a >=$b` actual := o.String() if expected != actual { @@ -818,16 +1219,22 @@ func TestPrintBinaryGreaterOrEqual(t *testing.T) { } } -func TestPrintBinaryGreater(t *testing.T) { +func TestPrinterPrintBinaryGreater(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.Greater{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.GreaterToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a > $b` + expected := `$a >$b` actual := o.String() if expected != actual { @@ -835,16 +1242,22 @@ func TestPrintBinaryGreater(t *testing.T) { } } -func TestPrintBinaryIdentical(t *testing.T) { +func TestPrinterPrintBinaryIdentical(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.Identical{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.IsIdenticalToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a === $b` + expected := `$a ===$b` actual := o.String() if expected != actual { @@ -852,16 +1265,22 @@ func TestPrintBinaryIdentical(t *testing.T) { } } -func TestPrintBinaryLogicalAnd(t *testing.T) { +func TestPrinterPrintBinaryLogicalAnd(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.LogicalAnd{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.LogicalAndToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a and $b` + expected := `$a and$b` actual := o.String() if expected != actual { @@ -869,16 +1288,22 @@ func TestPrintBinaryLogicalAnd(t *testing.T) { } } -func TestPrintBinaryLogicalOr(t *testing.T) { +func TestPrinterPrintBinaryLogicalOr(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.LogicalOr{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.LogicalOrToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a or $b` + expected := `$a or$b` actual := o.String() if expected != actual { @@ -886,16 +1311,22 @@ func TestPrintBinaryLogicalOr(t *testing.T) { } } -func TestPrintBinaryLogicalXor(t *testing.T) { +func TestPrinterPrintBinaryLogicalXor(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.LogicalXor{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.LogicalXorToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a xor $b` + expected := `$a xor$b` actual := o.String() if expected != actual { @@ -903,16 +1334,22 @@ func TestPrintBinaryLogicalXor(t *testing.T) { } } -func TestPrintBinaryMinus(t *testing.T) { +func TestPrinterPrintBinaryMinus(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.Minus{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.MinusToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a - $b` + expected := `$a -$b` actual := o.String() if expected != actual { @@ -920,16 +1357,22 @@ func TestPrintBinaryMinus(t *testing.T) { } } -func TestPrintBinaryMod(t *testing.T) { +func TestPrinterPrintBinaryMod(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.Mod{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.PercentToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a % $b` + expected := `$a %$b` actual := o.String() if expected != actual { @@ -937,16 +1380,22 @@ func TestPrintBinaryMod(t *testing.T) { } } -func TestPrintBinaryMul(t *testing.T) { +func TestPrinterPrintBinaryMul(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.Mul{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.AsteriskToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a * $b` + expected := `$a *$b` actual := o.String() if expected != actual { @@ -954,16 +1403,22 @@ func TestPrintBinaryMul(t *testing.T) { } } -func TestPrintBinaryNotEqual(t *testing.T) { +func TestPrinterPrintBinaryNotEqual(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.NotEqual{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.IsNotEqualToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a != $b` + expected := `$a !=$b` actual := o.String() if expected != actual { @@ -971,16 +1426,22 @@ func TestPrintBinaryNotEqual(t *testing.T) { } } -func TestPrintBinaryNotIdentical(t *testing.T) { +func TestPrinterPrintBinaryNotIdentical(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.NotIdentical{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.IsNotIdenticalToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a !== $b` + expected := `$a !==$b` actual := o.String() if expected != actual { @@ -988,16 +1449,22 @@ func TestPrintBinaryNotIdentical(t *testing.T) { } } -func TestPrintBinaryPlus(t *testing.T) { +func TestPrinterPrintBinaryPlus(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.Plus{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.PlusToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a + $b` + expected := `$a +$b` actual := o.String() if expected != actual { @@ -1005,16 +1472,22 @@ func TestPrintBinaryPlus(t *testing.T) { } } -func TestPrintBinaryPow(t *testing.T) { +func TestPrinterPrintBinaryPow(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.Pow{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.PowToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a ** $b` + expected := `$a **$b` actual := o.String() if expected != actual { @@ -1022,16 +1495,22 @@ func TestPrintBinaryPow(t *testing.T) { } } -func TestPrintBinaryShiftLeft(t *testing.T) { +func TestPrinterPrintBinaryShiftLeft(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.ShiftLeft{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SlToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a << $b` + expected := `$a <<$b` actual := o.String() if expected != actual { @@ -1039,16 +1518,22 @@ func TestPrintBinaryShiftLeft(t *testing.T) { } } -func TestPrintBinaryShiftRight(t *testing.T) { +func TestPrinterPrintBinaryShiftRight(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.ShiftRight{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SrToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a >> $b` + expected := `$a >>$b` actual := o.String() if expected != actual { @@ -1056,16 +1541,22 @@ func TestPrintBinaryShiftRight(t *testing.T) { } } -func TestPrintBinarySmallerOrEqual(t *testing.T) { +func TestPrinterPrintBinarySmallerOrEqual(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.SmallerOrEqual{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.IsSmallerOrEqualToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a <= $b` + expected := `$a <=$b` actual := o.String() if expected != actual { @@ -1073,16 +1564,22 @@ func TestPrintBinarySmallerOrEqual(t *testing.T) { } } -func TestPrintBinarySmaller(t *testing.T) { +func TestPrinterPrintBinarySmaller(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.Smaller{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.LessToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a < $b` + expected := `$a <$b` actual := o.String() if expected != actual { @@ -1090,16 +1587,22 @@ func TestPrintBinarySmaller(t *testing.T) { } } -func TestPrintBinarySpaceship(t *testing.T) { +func TestPrinterPrintBinarySpaceship(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&binary.Spaceship{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SpaceshipToken, + }, + }, Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a <=> $b` + expected := `$a <=>$b` actual := o.String() if expected != actual { @@ -1109,15 +1612,21 @@ func TestPrintBinarySpaceship(t *testing.T) { // cast -func TestPrintArray(t *testing.T) { +func TestPrinterPrintArray(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&cast.Array{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ArrayCastToken, + }, + }, Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `(array)$var` + expected := ` (array)$var` actual := o.String() if expected != actual { @@ -1125,15 +1634,21 @@ func TestPrintArray(t *testing.T) { } } -func TestPrintBool(t *testing.T) { +func TestPrinterPrintBool(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&cast.Bool{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.BoolCastToken, + }, + }, Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `(bool)$var` + expected := ` (bool)$var` actual := o.String() if expected != actual { @@ -1141,15 +1656,21 @@ func TestPrintBool(t *testing.T) { } } -func TestPrintDouble(t *testing.T) { +func TestPrinterPrintDouble(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&cast.Double{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.DoubleCastToken, + }, + }, Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `(float)$var` + expected := ` (float)$var` actual := o.String() if expected != actual { @@ -1157,15 +1678,21 @@ func TestPrintDouble(t *testing.T) { } } -func TestPrintInt(t *testing.T) { +func TestPrinterPrintInt(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&cast.Int{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.IntCastToken, + }, + }, Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `(int)$var` + expected := ` (int)$var` actual := o.String() if expected != actual { @@ -1173,15 +1700,21 @@ func TestPrintInt(t *testing.T) { } } -func TestPrintObject(t *testing.T) { +func TestPrinterPrintObject(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&cast.Object{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ObjectCastToken, + }, + }, Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `(object)$var` + expected := ` (object)$var` actual := o.String() if expected != actual { @@ -1189,15 +1722,21 @@ func TestPrintObject(t *testing.T) { } } -func TestPrintString(t *testing.T) { +func TestPrinterPrintString(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&cast.String{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.StringCastToken, + }, + }, Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `(string)$var` + expected := ` (string)$var` actual := o.String() if expected != actual { @@ -1205,15 +1744,21 @@ func TestPrintString(t *testing.T) { } } -func TestPrintUnset(t *testing.T) { +func TestPrinterPrintUnset(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&cast.Unset{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.UnsetCastToken, + }, + }, Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `(unset)$var` + expected := ` (unset)$var` actual := o.String() if expected != actual { @@ -1223,16 +1768,26 @@ func TestPrintUnset(t *testing.T) { // expr -func TestPrintExprArrayDimFetch(t *testing.T) { +func TestPrinterPrintExprArrayDimFetch(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.ArrayDimFetch{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenSquareBracket, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseSquareBracket, + }, + }, Variable: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, Dim: &scalar.Lnumber{Value: "1"}, }) - expected := `$var[1]` + expected := `$var [1 ]` actual := o.String() if expected != actual { @@ -1240,13 +1795,27 @@ func TestPrintExprArrayDimFetch(t *testing.T) { } } -func TestPrintExprArrayItemWithKey(t *testing.T) { +func TestPrinterPrintExprArrayItemWithKey(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.ArrayItem{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.DoubleArrowToken, + }, + }, Key: &scalar.String{Value: "'Hello'"}, - Val: &expr.Variable{VarName: &node.Identifier{Value: "world"}}, + Val: &expr.Variable{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.VariableToken, + }, + }, + VarName: &node.Identifier{Value: "world"}, + }, }) expected := `'Hello' => $world` @@ -1257,10 +1826,10 @@ func TestPrintExprArrayItemWithKey(t *testing.T) { } } -func TestPrintExprArrayItem(t *testing.T) { +func TestPrinterPrintExprArrayItem(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.ArrayItem{ Val: &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "world"}}}, }) @@ -1273,11 +1842,25 @@ func TestPrintExprArrayItem(t *testing.T) { } } -func TestPrintExprArray(t *testing.T) { +func TestPrinterPrintExprArray(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.Array{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ArrayToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, Items: []node.Node{ &expr.ArrayItem{ Key: &scalar.String{Value: "'Hello'"}, @@ -1293,7 +1876,7 @@ func TestPrintExprArray(t *testing.T) { }, }) - expected := `array('Hello' => $world, 2 => &$var, $var)` + expected := ` array ('Hello'=>$world,2=>&$var,$var )` actual := o.String() if expected != actual { @@ -1301,15 +1884,21 @@ func TestPrintExprArray(t *testing.T) { } } -func TestPrintExprBitwiseNot(t *testing.T) { +func TestPrinterPrintExprBitwiseNot(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.BitwiseNot{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.TildeToken, + }, + }, Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `~$var` + expected := ` ~$var` actual := o.String() if expected != actual { @@ -1317,15 +1906,21 @@ func TestPrintExprBitwiseNot(t *testing.T) { } } -func TestPrintExprBooleanNot(t *testing.T) { +func TestPrinterPrintExprBooleanNot(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.BooleanNot{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ExclamationMarkToken, + }, + }, Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `!$var` + expected := ` !$var` actual := o.String() if expected != actual { @@ -1333,16 +1928,30 @@ func TestPrintExprBooleanNot(t *testing.T) { } } -func TestPrintExprClassConstFetch(t *testing.T) { +func TestPrinterPrintExprClassConstFetch(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.ClassConstFetch{ - Class: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, - ConstantName: &node.Identifier{Value: "CONST"}, + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.PaamayimNekudotayimToken, + }, + }, + Class: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + ConstantName: &node.Identifier{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.IdentifierToken, + }, + }, + Value: "CONST", + }, }) - expected := `$var::CONST` + expected := `$var :: CONST` actual := o.String() if expected != actual { @@ -1350,15 +1959,21 @@ func TestPrintExprClassConstFetch(t *testing.T) { } } -func TestPrintExprClone(t *testing.T) { +func TestPrinterPrintExprClone(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.Clone{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloneToken, + }, + }, Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `clone $var` + expected := ` clone$var` actual := o.String() if expected != actual { @@ -1366,18 +1981,32 @@ func TestPrintExprClone(t *testing.T) { } } -func TestPrintExprClosureUse(t *testing.T) { +func TestPrinterPrintExprClosureUse(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.ClosureUse{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.UseToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, Uses: []node.Node{ &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "foo"}}}, &expr.Variable{VarName: &node.Identifier{Value: "bar"}}, }, }) - expected := `use (&$foo, $bar)` + expected := ` use (&$foo,$bar )` actual := o.String() if expected != actual { @@ -1385,41 +2014,71 @@ func TestPrintExprClosureUse(t *testing.T) { } } -func TestPrintExprClosure(t *testing.T) { +func TestPrinterPrintExprClosure(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ - Stmts: []node.Node{ - &expr.Closure{ - Static: true, - ReturnsRef: true, - Params: []node.Node{ - &node.Parameter{ - ByRef: true, - Variadic: false, - Variable: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, - }, - }, - ClosureUse: &expr.ClosureUse{ - Uses: []node.Node{ - &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, - &expr.Variable{VarName: &node.Identifier{Value: "b"}}, - }, - }, - ReturnType: &name.FullyQualified{Parts: []node.Node{&name.NamePart{Value: "Foo"}}}, - Stmts: []node.Node{ - &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, + p := printer.NewPrinter(o) + p.Print(&expr.Closure{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.StaticToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.FunctionToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.AmpersandToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenCurlyBracesToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseCurlyBracesToken, + }, + }, + Static: true, + ReturnsRef: true, + Params: []node.Node{ + &node.Parameter{ + ByRef: true, + Variadic: false, + Variable: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }, + }, + ClosureUse: &expr.ClosureUse{ + Uses: []node.Node{ + &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, + &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + }, + ReturnType: &name.FullyQualified{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ColonToken, }, }, + Parts: []node.Node{&name.NamePart{Value: "Foo"}}, + }, + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, }, }) - expected := `namespace { - static function &(&$var) use (&$a, $b): \Foo { - $a; - } -}` + expected := ` static function & (&$var )use(&$a,$b) :\Foo {$a; }` actual := o.String() if expected != actual { @@ -1427,10 +2086,10 @@ func TestPrintExprClosure(t *testing.T) { } } -func TestPrintExprConstFetch(t *testing.T) { +func TestPrinterPrintExprConstFetch(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.ConstFetch{ Constant: &name.Name{Parts: []node.Node{&name.NamePart{Value: "null"}}}, }) @@ -1443,13 +2102,33 @@ func TestPrintExprConstFetch(t *testing.T) { } } -func TestPrintDie(t *testing.T) { +func TestPrinterPrintDie(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&expr.Die{Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}}) + p := printer.NewPrinter(o) + p.Print(&expr.Die{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ExitToken, + }, + }, + Expr: &expr.Variable{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, + VarName: &node.Identifier{Value: "var"}, + }, + }) - expected := `die($var)` + expected := ` die ($var )` actual := o.String() if expected != actual { @@ -1457,13 +2136,29 @@ func TestPrintDie(t *testing.T) { } } -func TestPrintEmpty(t *testing.T) { +func TestPrinterPrintEmpty(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&expr.Empty{Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}}) + p := printer.NewPrinter(o) + p.Print(&expr.Empty{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.EmptyToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) - expected := `empty($var)` + expected := ` empty ($var )` actual := o.String() if expected != actual { @@ -1471,13 +2166,21 @@ func TestPrintEmpty(t *testing.T) { } } -func TestPrintErrorSuppress(t *testing.T) { +func TestPrinterPrettyPrinterrorSuppress(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&expr.ErrorSuppress{Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}}) + p := printer.NewPrinter(o) + p.Print(&expr.ErrorSuppress{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.AtToken, + }, + }, + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) - expected := `@$var` + expected := ` @$var` actual := o.String() if expected != actual { @@ -1485,13 +2188,29 @@ func TestPrintErrorSuppress(t *testing.T) { } } -func TestPrintEval(t *testing.T) { +func TestPrinterPrintEval(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&expr.Eval{Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}}) + p := printer.NewPrinter(o) + p.Print(&expr.Eval{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.EvalToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }) - expected := `eval($var)` + expected := ` eval ($var )` actual := o.String() if expected != actual { @@ -1499,13 +2218,33 @@ func TestPrintEval(t *testing.T) { } } -func TestPrintExit(t *testing.T) { +func TestPrinterPrintExit(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&expr.Exit{Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}}) + p := printer.NewPrinter(o) + p.Print(&expr.Exit{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ExitToken, + }, + }, + Expr: &expr.Variable{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, + VarName: &node.Identifier{Value: "var"}, + }, + }) - expected := `exit($var)` + expected := ` exit ($var )` actual := o.String() if expected != actual { @@ -1513,13 +2252,23 @@ func TestPrintExit(t *testing.T) { } } -func TestPrintFunctionCall(t *testing.T) { +func TestPrinterPrintFunctionCall(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.FunctionCall{ Function: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, ArgumentList: &node.ArgumentList{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, Arguments: []node.Node{ &node.Argument{ IsReference: true, @@ -1536,7 +2285,7 @@ func TestPrintFunctionCall(t *testing.T) { }, }) - expected := `$var(&$a, ...$b, $c)` + expected := `$var (&$a,...$b,$c )` actual := o.String() if expected != actual { @@ -1544,13 +2293,21 @@ func TestPrintFunctionCall(t *testing.T) { } } -func TestPrintInclude(t *testing.T) { +func TestPrinterPrintInclude(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&expr.Include{Expr: &scalar.String{Value: "'path'"}}) + p := printer.NewPrinter(o) + p.Print(&expr.Include{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.IncludeToken, + }, + }, + Expr: &scalar.String{Value: "'path'"}, + }) - expected := `include 'path'` + expected := ` include'path'` actual := o.String() if expected != actual { @@ -1558,13 +2315,20 @@ func TestPrintInclude(t *testing.T) { } } -func TestPrintIncludeOnce(t *testing.T) { +func TestPrinterPrintIncludeOnce(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&expr.IncludeOnce{Expr: &scalar.String{Value: "'path'"}}) + p := printer.NewPrinter(o) + p.Print(&expr.IncludeOnce{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.IncludeOnceToken, + }, + }, Expr: &scalar.String{Value: "'path'"}, + }) - expected := `include_once 'path'` + expected := ` include_once'path'` actual := o.String() if expected != actual { @@ -1572,16 +2336,22 @@ func TestPrintIncludeOnce(t *testing.T) { } } -func TestPrintInstanceOf(t *testing.T) { +func TestPrinterPrintInstanceOf(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.InstanceOf{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.InstanceofToken, + }, + }, Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, Class: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}}, }) - expected := `$var instanceof Foo` + expected := `$var instanceofFoo` actual := o.String() if expected != actual { @@ -1589,18 +2359,32 @@ func TestPrintInstanceOf(t *testing.T) { } } -func TestPrintIsset(t *testing.T) { +func TestPrinterPrintIsset(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.Isset{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.IssetToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, Variables: []node.Node{ &expr.Variable{VarName: &node.Identifier{Value: "a"}}, &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }, }) - expected := `isset($a, $b)` + expected := ` isset ($a,$b )` actual := o.String() if expected != actual { @@ -1608,11 +2392,25 @@ func TestPrintIsset(t *testing.T) { } } -func TestPrintList(t *testing.T) { +func TestPrinterPrintList(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.List{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ListToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, Items: []node.Node{ &expr.ArrayItem{ Val: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, @@ -1632,7 +2430,7 @@ func TestPrintList(t *testing.T) { }, }) - expected := `list($a, list($b, $c))` + expected := ` list ($a,list($b,$c) )` actual := o.String() if expected != actual { @@ -1640,14 +2438,30 @@ func TestPrintList(t *testing.T) { } } -func TestPrintMethodCall(t *testing.T) { +func TestPrinterPrintMethodCall(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.MethodCall{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ObjectOperatorToken, + }, + }, Variable: &expr.Variable{VarName: &node.Identifier{Value: "foo"}}, Method: &node.Identifier{Value: "bar"}, ArgumentList: &node.ArgumentList{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, Arguments: []node.Node{ &node.Argument{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, @@ -1659,7 +2473,7 @@ func TestPrintMethodCall(t *testing.T) { }, }) - expected := `$foo->bar($a, $b)` + expected := `$foo ->bar ($a,$b )` actual := o.String() if expected != actual { @@ -1667,13 +2481,41 @@ func TestPrintMethodCall(t *testing.T) { } } -func TestPrintNew(t *testing.T) { +func TestPrinterPrintNew(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.New{ - Class: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}}, + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.NewToken, + }, + }, + Class: &name.Name{ + Parts: []node.Node{ + &name.NamePart{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.StringToken, + }, + }, + Value: "Foo", + }, + }, + }, ArgumentList: &node.ArgumentList{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, Arguments: []node.Node{ &node.Argument{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, @@ -1685,7 +2527,7 @@ func TestPrintNew(t *testing.T) { }, }) - expected := `new Foo($a, $b)` + expected := ` new Foo ($a,$b )` actual := o.String() if expected != actual { @@ -1693,15 +2535,21 @@ func TestPrintNew(t *testing.T) { } } -func TestPrintPostDec(t *testing.T) { +func TestPrinterPrintPostDec(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.PostDec{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.DecToken, + }, + }, Variable: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `$var--` + expected := `$var --` actual := o.String() if expected != actual { @@ -1709,15 +2557,21 @@ func TestPrintPostDec(t *testing.T) { } } -func TestPrintPostInc(t *testing.T) { +func TestPrinterPrintPostInc(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.PostInc{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.IncToken, + }, + }, Variable: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `$var++` + expected := `$var ++` actual := o.String() if expected != actual { @@ -1725,15 +2579,21 @@ func TestPrintPostInc(t *testing.T) { } } -func TestPrintPreDec(t *testing.T) { +func TestPrinterPrintPreDec(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.PreDec{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.DecToken, + }, + }, Variable: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `--$var` + expected := ` --$var` actual := o.String() if expected != actual { @@ -1741,15 +2601,21 @@ func TestPrintPreDec(t *testing.T) { } } -func TestPrintPreInc(t *testing.T) { +func TestPrinterPrintPreInc(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.PreInc{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.IncToken, + }, + }, Variable: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `++$var` + expected := ` ++$var` actual := o.String() if expected != actual { @@ -1757,13 +2623,33 @@ func TestPrintPreInc(t *testing.T) { } } -func TestPrintPrint(t *testing.T) { +func TestPrinterPrintPrint(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&expr.Print{Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}}) + p := printer.NewPrinter(o) + p.Print(&expr.Print{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.PrintToken, + }, + }, + Expr: &expr.Variable{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, + VarName: &node.Identifier{Value: "var"}, + }, + }) - expected := `print($var)` + expected := ` print ($var )` actual := o.String() if expected != actual { @@ -1771,16 +2657,22 @@ func TestPrintPrint(t *testing.T) { } } -func TestPrintPropertyFetch(t *testing.T) { +func TestPrinterPrintPropertyFetch(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.PropertyFetch{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ObjectOperatorToken, + }, + }, Variable: &expr.Variable{VarName: &node.Identifier{Value: "foo"}}, Property: &node.Identifier{Value: "bar"}, }) - expected := `$foo->bar` + expected := `$foo ->bar` actual := o.String() if expected != actual { @@ -1788,15 +2680,21 @@ func TestPrintPropertyFetch(t *testing.T) { } } -func TestPrintExprReference(t *testing.T) { +func TestPrinterPrintExprReference(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.Reference{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.AmpersandToken, + }, + }, Variable: &expr.Variable{VarName: &node.Identifier{Value: "foo"}}, }) - expected := `&$foo` + expected := ` &$foo` actual := o.String() if expected != actual { @@ -1804,13 +2702,21 @@ func TestPrintExprReference(t *testing.T) { } } -func TestPrintRequire(t *testing.T) { +func TestPrinterPrintRequire(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&expr.Require{Expr: &scalar.String{Value: "'path'"}}) + p := printer.NewPrinter(o) + p.Print(&expr.Require{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.RequireToken, + }, + }, + Expr: &scalar.String{Value: "'path'"}, + }) - expected := `require 'path'` + expected := ` require'path'` actual := o.String() if expected != actual { @@ -1818,13 +2724,21 @@ func TestPrintRequire(t *testing.T) { } } -func TestPrintRequireOnce(t *testing.T) { +func TestPrinterPrintRequireOnce(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&expr.RequireOnce{Expr: &scalar.String{Value: "'path'"}}) + p := printer.NewPrinter(o) + p.Print(&expr.RequireOnce{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.RequireOnceToken, + }, + }, + Expr: &scalar.String{Value: "'path'"}, + }) - expected := `require_once 'path'` + expected := ` require_once'path'` actual := o.String() if expected != actual { @@ -1832,11 +2746,17 @@ func TestPrintRequireOnce(t *testing.T) { } } -func TestPrintShellExec(t *testing.T) { +func TestPrinterPrintShellExec(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.ShellExec{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.BackquoteToken, + }, + }, Parts: []node.Node{ &scalar.EncapsedStringPart{Value: "hello "}, &expr.Variable{VarName: &node.Identifier{Value: "world"}}, @@ -1844,7 +2764,7 @@ func TestPrintShellExec(t *testing.T) { }, }) - expected := "`hello $world!`" + expected := " `hello $world!`" actual := o.String() if expected != actual { @@ -1852,11 +2772,21 @@ func TestPrintShellExec(t *testing.T) { } } -func TestPrintExprShortArray(t *testing.T) { +func TestPrinterPrintExprShortArray(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.ShortArray{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenSquareBracket, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseSquareBracket, + }, + }, Items: []node.Node{ &expr.ArrayItem{ Key: &scalar.String{Value: "'Hello'"}, @@ -1872,7 +2802,7 @@ func TestPrintExprShortArray(t *testing.T) { }, }) - expected := `['Hello' => $world, 2 => &$var, $var]` + expected := ` ['Hello'=>$world,2=>&$var,$var ]` actual := o.String() if expected != actual { @@ -1880,11 +2810,21 @@ func TestPrintExprShortArray(t *testing.T) { } } -func TestPrintShortList(t *testing.T) { +func TestPrinterPrintShortList(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.ShortList{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenSquareBracket, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseSquareBracket, + }, + }, Items: []node.Node{ &expr.ArrayItem{ Val: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, @@ -1904,7 +2844,7 @@ func TestPrintShortList(t *testing.T) { }, }) - expected := `[$a, list($b, $c)]` + expected := ` [$a,list($b,$c) ]` actual := o.String() if expected != actual { @@ -1912,14 +2852,30 @@ func TestPrintShortList(t *testing.T) { } } -func TestPrintStaticCall(t *testing.T) { +func TestPrinterPrintStaticCall(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.StaticCall{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.PaamayimNekudotayimToken, + }, + }, Class: &node.Identifier{Value: "Foo"}, Call: &node.Identifier{Value: "bar"}, ArgumentList: &node.ArgumentList{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, Arguments: []node.Node{ &node.Argument{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, @@ -1931,7 +2887,7 @@ func TestPrintStaticCall(t *testing.T) { }, }) - expected := `Foo::bar($a, $b)` + expected := `Foo ::bar ($a,$b )` actual := o.String() if expected != actual { @@ -1939,16 +2895,22 @@ func TestPrintStaticCall(t *testing.T) { } } -func TestPrintStaticPropertyFetch(t *testing.T) { +func TestPrinterPrintStaticPropertyFetch(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.StaticPropertyFetch{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.PaamayimNekudotayimToken, + }, + }, Class: &node.Identifier{Value: "Foo"}, Property: &expr.Variable{VarName: &node.Identifier{Value: "bar"}}, }) - expected := `Foo::$bar` + expected := `Foo ::$bar` actual := o.String() if expected != actual { @@ -1956,16 +2918,26 @@ func TestPrintStaticPropertyFetch(t *testing.T) { } } -func TestPrintTernary(t *testing.T) { +func TestPrinterPrintTernary(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.Ternary{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.QuestionMarkToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ColonToken, + }, + }, Condition: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, IfFalse: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }) - expected := `$a ?: $b` + expected := `$a ? :$b` actual := o.String() if expected != actual { @@ -1973,17 +2945,27 @@ func TestPrintTernary(t *testing.T) { } } -func TestPrintTernaryFull(t *testing.T) { +func TestPrinterPrintTernaryFull(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.Ternary{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.QuestionMarkToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ColonToken, + }, + }, Condition: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, IfTrue: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, IfFalse: &expr.Variable{VarName: &node.Identifier{Value: "c"}}, }) - expected := `$a ? $b : $c` + expected := `$a ?$b :$c` actual := o.String() if expected != actual { @@ -1991,15 +2973,21 @@ func TestPrintTernaryFull(t *testing.T) { } } -func TestPrintUnaryMinus(t *testing.T) { +func TestPrinterPrintUnaryMinus(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.UnaryMinus{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.MinusToken, + }, + }, Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `-$var` + expected := ` -$var` actual := o.String() if expected != actual { @@ -2007,15 +2995,21 @@ func TestPrintUnaryMinus(t *testing.T) { } } -func TestPrintUnaryPlus(t *testing.T) { +func TestPrinterPrintUnaryPlus(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.UnaryPlus{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.PlusToken, + }, + }, Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `+$var` + expected := ` +$var` actual := o.String() if expected != actual { @@ -2023,13 +3017,23 @@ func TestPrintUnaryPlus(t *testing.T) { } } -func TestPrintVariable(t *testing.T) { +func TestPrinterPrintVariable(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&expr.Variable{VarName: &expr.Variable{VarName: &node.Identifier{Value: "var"}}}) + p := printer.NewPrinter(o) + p.Print(&expr.Variable{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.VariableToken, + }, + }, + VarName: &expr.Variable{ + VarName: &node.Identifier{Value: "var"}, + }, + }) - expected := `$$var` + expected := ` $$var` actual := o.String() if expected != actual { @@ -2037,15 +3041,21 @@ func TestPrintVariable(t *testing.T) { } } -func TestPrintYieldFrom(t *testing.T) { +func TestPrinterPrintYieldFrom(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.YieldFrom{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.YieldFromToken, + }, + }, Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `yield from $var` + expected := ` yield from$var` actual := o.String() if expected != actual { @@ -2053,15 +3063,21 @@ func TestPrintYieldFrom(t *testing.T) { } } -func TestPrintYield(t *testing.T) { +func TestPrinterPrintYield(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.Yield{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.YieldToken, + }, + }, Value: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `yield $var` + expected := ` yield$var` actual := o.String() if expected != actual { @@ -2069,16 +3085,26 @@ func TestPrintYield(t *testing.T) { } } -func TestPrintYieldFull(t *testing.T) { +func TestPrinterPrintYieldFull(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&expr.Yield{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.YieldToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.DoubleArrowToken, + }, + }, Key: &expr.Variable{VarName: &node.Identifier{Value: "k"}}, Value: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, }) - expected := `yield $k => $var` + expected := ` yield$k =>$var` actual := o.String() if expected != actual { @@ -2088,11 +3114,29 @@ func TestPrintYieldFull(t *testing.T) { // stmt -func TestPrintAltElseIf(t *testing.T) { +func TestPrinterPrintAltElseIf(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.AltElseIf{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ElseifToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ColonToken, + }, + }, Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Stmt: &stmt.StmtList{ Stmts: []node.Node{ @@ -2101,8 +3145,7 @@ func TestPrintAltElseIf(t *testing.T) { }, }) - expected := `elseif ($a) : - $b;` + expected := ` elseif ($a ) :$b;` actual := o.String() if expected != actual { @@ -2110,16 +3153,34 @@ func TestPrintAltElseIf(t *testing.T) { } } -func TestPrintAltElseIfEmpty(t *testing.T) { +func TestPrinterPrintAltElseIfEmpty(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.AltElseIf{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ElseifToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ColonToken, + }, + }, Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Stmt: &stmt.StmtList{}, }) - expected := `elseif ($a) :` + expected := ` elseif ($a ) :` actual := o.String() if expected != actual { @@ -2127,11 +3188,21 @@ func TestPrintAltElseIfEmpty(t *testing.T) { } } -func TestPrintAltElse(t *testing.T) { +func TestPrinterPrintAltElse(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.AltElse{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ElseToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ColonToken, + }, + }, Stmt: &stmt.StmtList{ Stmts: []node.Node{ &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}}, @@ -2139,8 +3210,7 @@ func TestPrintAltElse(t *testing.T) { }, }) - expected := `else : - $b;` + expected := ` else :$b;` actual := o.String() if expected != actual { @@ -2148,15 +3218,25 @@ func TestPrintAltElse(t *testing.T) { } } -func TestPrintAltElseEmpty(t *testing.T) { +func TestPrinterPrintAltElseEmpty(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.AltElse{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ElseToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ColonToken, + }, + }, Stmt: &stmt.StmtList{}, }) - expected := `else :` + expected := ` else :` actual := o.String() if expected != actual { @@ -2164,36 +3244,187 @@ func TestPrintAltElseEmpty(t *testing.T) { } } -func TestPrintAltFor(t *testing.T) { +func TestPrinterPrintAltFor(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ - Stmts: []node.Node{ - &stmt.AltFor{ - Init: []node.Node{ - &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - }, - Cond: []node.Node{ - &expr.Variable{VarName: &node.Identifier{Value: "b"}}, - }, - Loop: []node.Node{ - &expr.Variable{VarName: &node.Identifier{Value: "c"}}, - }, + p := printer.NewPrinter(o) + p.Print(&stmt.AltFor{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ForToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ForInitSemicolonToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ForCondSemicolonToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ColonToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.EndforToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SemiColonToken, + }, + }, + Init: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + }, + Cond: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + Loop: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "c"}}, + }, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "d"}}}, + }, + }, + }) + + expected := ` for ($a ;$b ;$c ) :$d; endfor ;` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrinterPrintAltForeach(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrinter(o) + p.Print(&stmt.AltForeach{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ForeachToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.AsToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.DoubleArrowToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ColonToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.EndforeachToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SemiColonToken, + }, + }, + Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + Key: &expr.Variable{VarName: &node.Identifier{Value: "key"}}, + Variable: &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "val"}}}, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "d"}}}, + }, + }, + }) + + expected := ` foreach ($var as$key =>&$val ) :$d; endforeach ;` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrinterPrintAltIf(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrinter(o) + p.Print(&stmt.AltIf{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.IfToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ColonToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.EndifToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SemiColonToken, + }, + }, + Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "d"}}}, + }, + }, + ElseIf: []node.Node{ + &stmt.AltElseIf{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Stmt: &stmt.StmtList{ Stmts: []node.Node{ - &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "d"}}}, + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}}, }, }, }, + &stmt.AltElseIf{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "c"}}, + Stmt: &stmt.StmtList{}, + }, + }, + Else: &stmt.AltElse{ + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}}, + }, + }, }, }) - expected := `namespace { - for ($a; $b; $c) : - $d; - endfor; -}` + expected := ` if ($a ) :$d;elseif($b):$b;elseif($c):else:$b; endif ;` actual := o.String() if expected != actual { @@ -2201,144 +3432,52 @@ func TestPrintAltFor(t *testing.T) { } } -func TestPrintAltForeach(t *testing.T) { +func TestPrinterPrintStmtAltSwitch(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ - Stmts: []node.Node{ - &stmt.AltForeach{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, - Key: &expr.Variable{VarName: &node.Identifier{Value: "key"}}, - Variable: &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "val"}}}, - Stmt: &stmt.StmtList{ + p := printer.NewPrinter(o) + p.Print(&stmt.AltSwitch{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SwitchToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ColonToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SwitchSemicolonToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.EndswitchToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SemiColonToken, + }, + }, + Cond: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + CaseList: &stmt.CaseList{ + Cases: []node.Node{ + &stmt.Case{ + Cond: &scalar.String{Value: "'a'"}, Stmts: []node.Node{ - &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "d"}}}, + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, }, }, - }, - }, - }) - - expected := `namespace { - foreach ($var as $key => &$val) : - $d; - endforeach; -}` - actual := o.String() - - if expected != actual { - t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) - } -} - -func TestPrintAltIf(t *testing.T) { - o := bytes.NewBufferString("") - - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ - Stmts: []node.Node{ - &stmt.AltIf{ - Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Stmt: &stmt.StmtList{ - Stmts: []node.Node{ - &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "d"}}}, - }, - }, - ElseIf: []node.Node{ - &stmt.AltElseIf{ - Cond: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, - Stmt: &stmt.StmtList{ - Stmts: []node.Node{ - &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}}, - }, - }, - }, - &stmt.AltElseIf{ - Cond: &expr.Variable{VarName: &node.Identifier{Value: "c"}}, - Stmt: &stmt.StmtList{}, - }, - }, - Else: &stmt.AltElse{ - Stmt: &stmt.StmtList{ - Stmts: []node.Node{ - &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}}, - }, - }, - }, - }, - }, - }) - - expected := `namespace { - if ($a) : - $d; - elseif ($b) : - $b; - elseif ($c) : - else : - $b; - endif; -}` - actual := o.String() - - if expected != actual { - t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) - } -} - -func TestPrintStmtAltSwitch(t *testing.T) { - o := bytes.NewBufferString("") - - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ - Stmts: []node.Node{ - &stmt.AltSwitch{ - Cond: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, - CaseList: &stmt.CaseList{ - Cases: []node.Node{ - &stmt.Case{ - Cond: &scalar.String{Value: "'a'"}, - Stmts: []node.Node{ - &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, - }, - }, - &stmt.Case{ - Cond: &scalar.String{Value: "'b'"}, - Stmts: []node.Node{ - &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}}, - }, - }, - }, - }, - }, - }, - }) - - expected := `namespace { - switch ($var) : - case 'a': - $a; - case 'b': - $b; - endswitch; -}` - actual := o.String() - - if expected != actual { - t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) - } -} - -func TestPrintAltWhile(t *testing.T) { - o := bytes.NewBufferString("") - - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ - Stmts: []node.Node{ - &stmt.AltWhile{ - Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Stmt: &stmt.StmtList{ + &stmt.Case{ + Cond: &scalar.String{Value: "'b'"}, Stmts: []node.Node{ &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}}, }, @@ -2347,11 +3486,7 @@ func TestPrintAltWhile(t *testing.T) { }, }) - expected := `namespace { - while ($a) : - $b; - endwhile; -}` + expected := ` switch ($var ) : ;case'a':$a;case'b':$b; endswitch ;` actual := o.String() if expected != actual { @@ -2359,15 +3494,46 @@ func TestPrintAltWhile(t *testing.T) { } } -func TestPrintStmtBreak(t *testing.T) { +func TestPrinterPrintAltWhile(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Break{ - Expr: &scalar.Lnumber{Value: "1"}, + p := printer.NewPrinter(o) + p.Print(&stmt.AltWhile{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.WhileToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ColonToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.EndwhileToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SemiColonToken, + }, + }, + Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}}, + }, + }, }) - expected := "break 1;" + expected := ` while ($a ) :$b; endwhile ;` actual := o.String() if expected != actual { @@ -2375,19 +3541,66 @@ func TestPrintStmtBreak(t *testing.T) { } } -func TestPrintStmtCase(t *testing.T) { +func TestPrinterPrintStmtBreak(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) + p.Print(&stmt.Break{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.BreakToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SemiColonToken, + }, + }, + Expr: &scalar.Lnumber{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, + Value: "1", + }, + }) + + expected := " break (1 ) ;" + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrinterPrintStmtCase(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrinter(o) p.Print(&stmt.Case{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CaseToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CaseSeparatorToken, + }, + }, Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Stmts: []node.Node{ &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, }, }) - expected := `case $a: - $a;` + expected := ` case$a :$a;` actual := o.String() if expected != actual { @@ -2395,16 +3608,26 @@ func TestPrintStmtCase(t *testing.T) { } } -func TestPrintStmtCaseEmpty(t *testing.T) { +func TestPrinterPrintStmtCaseEmpty(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.Case{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CaseToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CaseSeparatorToken, + }, + }, Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Stmts: []node.Node{}, }) - expected := "case $a:" + expected := " case$a :" actual := o.String() if expected != actual { @@ -2412,30 +3635,44 @@ func TestPrintStmtCaseEmpty(t *testing.T) { } } -func TestPrintStmtCatch(t *testing.T) { +func TestPrinterPrintStmtCatch(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ - Stmts: []node.Node{ - &stmt.Catch{ - Types: []node.Node{ - &name.Name{Parts: []node.Node{&name.NamePart{Value: "Exception"}}}, - &name.FullyQualified{Parts: []node.Node{&name.NamePart{Value: "RuntimeException"}}}, - }, - Variable: &expr.Variable{VarName: &node.Identifier{Value: "e"}}, - Stmts: []node.Node{ - &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, - }, + p := printer.NewPrinter(o) + p.Print(&stmt.Catch{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CatchToken, }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenCurlyBracesToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseCurlyBracesToken, + }, + }, + Types: []node.Node{ + &name.Name{Parts: []node.Node{&name.NamePart{Value: "Exception"}}}, + &name.FullyQualified{Parts: []node.Node{&name.NamePart{Value: "RuntimeException"}}}, + }, + Variable: &expr.Variable{VarName: &node.Identifier{Value: "e"}}, + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, }, }) - expected := `namespace { - catch (Exception | \RuntimeException $e) { - $a; - } -}` + expected := ` catch (Exception|\RuntimeException$e ) {$a; }` actual := o.String() if expected != actual { @@ -2443,11 +3680,29 @@ func TestPrintStmtCatch(t *testing.T) { } } -func TestPrintStmtClassMethod(t *testing.T) { +func TestPrinterPrintStmtClassMethod(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.ClassMethod{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.FunctionToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.AmpersandToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, Modifiers: []node.Node{&node.Identifier{Value: "public"}}, ReturnsRef: true, MethodName: &node.Identifier{Value: "foo"}, @@ -2463,29 +3718,62 @@ func TestPrintStmtClassMethod(t *testing.T) { Variable: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }, }, - ReturnType: &name.Name{Parts: []node.Node{&name.NamePart{Value: "void"}}}, + ReturnType: &name.Name{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ColonToken, + }, + }, + Parts: []node.Node{&name.NamePart{Value: "void"}}, + }, Stmt: &stmt.StmtList{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenCurlyBracesToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseCurlyBracesToken, + }, + }, Stmts: []node.Node{ &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, }, }, }) - expected := `public function &foo(?int &$a = null, ...$b): void -{ - $a; -}` + expected := `public function &foo (?int&$a=null,...$b ) :void {$a; }` actual := o.String() if expected != actual { t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) } } -func TestPrintStmtAbstractClassMethod(t *testing.T) { +func TestPrinterPrintStmtAbstractClassMethod(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.ClassMethod{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.FunctionToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.AmpersandToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, Modifiers: []node.Node{&node.Identifier{Value: "public"}}, ReturnsRef: true, MethodName: &node.Identifier{Value: "foo"}, @@ -2501,11 +3789,19 @@ func TestPrintStmtAbstractClassMethod(t *testing.T) { Variable: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }, }, - ReturnType: &name.Name{Parts: []node.Node{&name.NamePart{Value: "void"}}}, - Stmt: &stmt.Nop{}, + ReturnType: &name.Name{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ColonToken, + }, + }, + Parts: []node.Node{&name.NamePart{Value: "void"}}, + }, + Stmt: &stmt.Nop{}, }) - expected := `public function &foo(?int &$a = null, ...$b): void;` + expected := `public function &foo (?int&$a=null,...$b ) :void;` actual := o.String() if expected != actual { @@ -2513,45 +3809,62 @@ func TestPrintStmtAbstractClassMethod(t *testing.T) { } } -func TestPrintStmtClass(t *testing.T) { +func TestPrinterPrintStmtClass(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ + p := printer.NewPrinter(o) + p.Print(&stmt.Class{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ClassToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenCurlyBracesToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseCurlyBracesToken, + }, + }, + Modifiers: []node.Node{&node.Identifier{Value: "abstract"}}, + ClassName: &node.Identifier{Value: "Foo"}, + Extends: &stmt.ClassExtends{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ExtendsToken, + }, + }, + ClassName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}}, + }, + Implements: &stmt.ClassImplements{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ImplementsToken, + }, + }, + InterfaceNames: []node.Node{ + &name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}}, + &name.Name{Parts: []node.Node{&name.NamePart{Value: "Quuz"}}}, + }, + }, Stmts: []node.Node{ - &stmt.Class{ - Modifiers: []node.Node{&node.Identifier{Value: "abstract"}}, - ClassName: &node.Identifier{Value: "Foo"}, - Extends: &stmt.ClassExtends{ - ClassName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}}, - }, - Implements: &stmt.ClassImplements{ - InterfaceNames: []node.Node{ - &name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}}, - &name.Name{Parts: []node.Node{&name.NamePart{Value: "Quuz"}}}, - }, - }, - Stmts: []node.Node{ - &stmt.ClassConstList{ - Modifiers: []node.Node{&node.Identifier{Value: "public"}}, - Consts: []node.Node{ - &stmt.Constant{ - ConstantName: &node.Identifier{Value: "FOO"}, - Expr: &scalar.String{Value: "'bar'"}, - }, - }, + &stmt.ClassConstList{ + Modifiers: []node.Node{&node.Identifier{Value: "public"}}, + Consts: []node.Node{ + &stmt.Constant{ + ConstantName: &node.Identifier{Value: "FOO"}, + Expr: &scalar.String{Value: "'bar'"}, }, }, }, }, }) - expected := `namespace { - abstract class Foo extends Bar implements Baz, Quuz - { - public const FOO = 'bar'; - } -}` + expected := `abstract classFoo extendsBar implementsBaz,Quuz {publicconstFOO='bar'; }` actual := o.String() if expected != actual { @@ -2559,54 +3872,81 @@ func TestPrintStmtClass(t *testing.T) { } } -func TestPrintStmtAnonymousClass(t *testing.T) { +func TestPrinterPrintStmtAnonymousClass(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ + p := printer.NewPrinter(o) + p.Print(&stmt.Class{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ClassToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenCurlyBracesToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseCurlyBracesToken, + }, + }, + Modifiers: []node.Node{&node.Identifier{Value: "abstract"}}, + ArgumentList: &node.ArgumentList{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, + Arguments: []node.Node{ + &node.Argument{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + }, + &node.Argument{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + }, + }, + Extends: &stmt.ClassExtends{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ExtendsToken, + }, + }, + ClassName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}}, + }, + Implements: &stmt.ClassImplements{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ImplementsToken, + }, + }, + InterfaceNames: []node.Node{ + &name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}}, + &name.Name{Parts: []node.Node{&name.NamePart{Value: "Quuz"}}}, + }, + }, Stmts: []node.Node{ - &stmt.Class{ - Modifiers: []node.Node{&node.Identifier{Value: "abstract"}}, - ArgumentList: &node.ArgumentList{ - Arguments: []node.Node{ - &node.Argument{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - }, - &node.Argument{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, - }, - }, - }, - Extends: &stmt.ClassExtends{ - ClassName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}}, - }, - Implements: &stmt.ClassImplements{ - InterfaceNames: []node.Node{ - &name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}}, - &name.Name{Parts: []node.Node{&name.NamePart{Value: "Quuz"}}}, - }, - }, - Stmts: []node.Node{ - &stmt.ClassConstList{ - Modifiers: []node.Node{&node.Identifier{Value: "public"}}, - Consts: []node.Node{ - &stmt.Constant{ - ConstantName: &node.Identifier{Value: "FOO"}, - Expr: &scalar.String{Value: "'bar'"}, - }, - }, + &stmt.ClassConstList{ + Modifiers: []node.Node{&node.Identifier{Value: "public"}}, + Consts: []node.Node{ + &stmt.Constant{ + ConstantName: &node.Identifier{Value: "FOO"}, + Expr: &scalar.String{Value: "'bar'"}, }, }, }, }, }) - expected := `namespace { - abstract class($a, $b) extends Bar implements Baz, Quuz - { - public const FOO = 'bar'; - } -}` + expected := `abstract class ($a,$b ) extendsBar implementsBaz,Quuz {publicconstFOO='bar'; }` actual := o.String() if expected != actual { @@ -2614,11 +3954,21 @@ func TestPrintStmtAnonymousClass(t *testing.T) { } } -func TestPrintStmtClassConstList(t *testing.T) { +func TestPrinterPrintStmtClassConstList(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.ClassConstList{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ConstToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SemiColonToken, + }, + }, Modifiers: []node.Node{&node.Identifier{Value: "public"}}, Consts: []node.Node{ &stmt.Constant{ @@ -2632,7 +3982,7 @@ func TestPrintStmtClassConstList(t *testing.T) { }, }) - expected := `public const FOO = 'a', BAR = 'b';` + expected := `public constFOO='a',BAR='b' ;` actual := o.String() if expected != actual { @@ -2640,16 +3990,22 @@ func TestPrintStmtClassConstList(t *testing.T) { } } -func TestPrintStmtConstant(t *testing.T) { +func TestPrinterPrintStmtConstant(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.Constant{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.EqualToken, + }, + }, ConstantName: &node.Identifier{Value: "FOO"}, Expr: &scalar.String{Value: "'BAR'"}, }) - expected := "FOO = 'BAR'" + expected := "FOO ='BAR'" actual := o.String() if expected != actual { @@ -2657,15 +4013,37 @@ func TestPrintStmtConstant(t *testing.T) { } } -func TestPrintStmtContinue(t *testing.T) { +func TestPrinterPrintStmtContinue(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.Continue{ - Expr: &scalar.Lnumber{Value: "1"}, + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ContinueToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SemiColonToken, + }, + }, + Expr: &scalar.Lnumber{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, + Value: "1", + }, }) - expected := `continue 1;` + expected := ` continue (1 ) ;` actual := o.String() if expected != actual { @@ -2673,33 +4051,39 @@ func TestPrintStmtContinue(t *testing.T) { } } -func TestPrintStmtDeclareStmts(t *testing.T) { +func TestPrinterPrintStmtDeclareStmts(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&stmt.StmtList{ - Stmts: []node.Node{ - &stmt.Declare{ - Consts: []node.Node{ - &stmt.Constant{ - ConstantName: &node.Identifier{Value: "FOO"}, - Expr: &scalar.String{Value: "'bar'"}, - }, - }, - Stmt: &stmt.StmtList{ - Stmts: []node.Node{ - &stmt.Nop{}, - }, - }, + p := printer.NewPrinter(o) + p.Print(&stmt.Declare{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.DeclareToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, + Consts: []node.Node{ + &stmt.Constant{ + ConstantName: &node.Identifier{Value: "FOO"}, + Expr: &scalar.String{Value: "'bar'"}, + }, + }, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Nop{}, }, }, }) - expected := `{ - declare(FOO = 'bar') { - ; - } -}` + expected := ` declare (FOO='bar' ){;}` actual := o.String() if expected != actual { @@ -2707,28 +4091,35 @@ func TestPrintStmtDeclareStmts(t *testing.T) { } } -func TestPrintStmtDeclareExpr(t *testing.T) { +func TestPrinterPrintStmtDeclareExpr(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&stmt.StmtList{ - Stmts: []node.Node{ - &stmt.Declare{ - Consts: []node.Node{ - &stmt.Constant{ - ConstantName: &node.Identifier{Value: "FOO"}, - Expr: &scalar.String{Value: "'bar'"}, - }, - }, - Stmt: &stmt.Expression{Expr: &scalar.String{Value: "'bar'"}}, + p := printer.NewPrinter(o) + p.Print(&stmt.Declare{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.DeclareToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, }, }, + Consts: []node.Node{ + &stmt.Constant{ + ConstantName: &node.Identifier{Value: "FOO"}, + Expr: &scalar.String{Value: "'bar'"}, + }, + }, + Stmt: &stmt.Expression{Expr: &scalar.String{Value: "'bar'"}}, }) - expected := `{ - declare(FOO = 'bar') - 'bar'; -}` + expected := ` declare (FOO='bar' )'bar';` actual := o.String() if expected != actual { @@ -2736,10 +4127,10 @@ func TestPrintStmtDeclareExpr(t *testing.T) { } } -func TestPrintStmtDeclareNop(t *testing.T) { +func TestPrinterPrintStmtDeclareNop(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.Declare{ Consts: []node.Node{ &stmt.Constant{ @@ -2750,7 +4141,7 @@ func TestPrintStmtDeclareNop(t *testing.T) { Stmt: &stmt.Nop{}, }) - expected := `declare(FOO = 'bar');` + expected := `declare(FOO='bar');` actual := o.String() if expected != actual { @@ -2758,18 +4149,27 @@ func TestPrintStmtDeclareNop(t *testing.T) { } } -func TestPrintStmtDefalut(t *testing.T) { +func TestPrinterPrintStmtDefalut(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.Default{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.DefaultToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CaseSeparatorToken, + }, + }, Stmts: []node.Node{ &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, }, }) - expected := `default: - $a;` + expected := ` default :$a;` actual := o.String() if expected != actual { @@ -2777,15 +4177,25 @@ func TestPrintStmtDefalut(t *testing.T) { } } -func TestPrintStmtDefalutEmpty(t *testing.T) { +func TestPrinterPrintStmtDefalutEmpty(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.Default{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.DefaultToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CaseSeparatorToken, + }, + }, Stmts: []node.Node{}, }) - expected := `default:` + expected := ` default :` actual := o.String() if expected != actual { @@ -2793,26 +4203,83 @@ func TestPrintStmtDefalutEmpty(t *testing.T) { } } -func TestPrintStmtDo_Expression(t *testing.T) { +func TestPrinterPrintStmtDo_Expression(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ - Stmts: []node.Node{ - &stmt.Do{ - Cond: &scalar.Lnumber{Value: "1"}, - Stmt: &stmt.Expression{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - }, + p := printer.NewPrinter(o) + p.Print(&stmt.Do{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.DoToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.WhileToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SemiColonToken, + }, + }, + Cond: &scalar.Lnumber{Value: "1"}, + Stmt: &stmt.Expression{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + }, + }) + + expected := ` do$a; while (1 ) ;` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrinterPrintStmtDo_StmtList(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrinter(o) + p.Print(&stmt.Do{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.DoToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.WhileToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SemiColonToken, + }, + }, + Cond: &scalar.Lnumber{Value: "1"}, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, }, }, }) - expected := `namespace { - do - $a; - while (1); -}` + expected := ` do{$a;} while (1 ) ;` actual := o.String() if expected != actual { @@ -2820,47 +4287,28 @@ func TestPrintStmtDo_Expression(t *testing.T) { } } -func TestPrintStmtDo_StmtList(t *testing.T) { +func TestPrinterPrintStmtEcho(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ - Stmts: []node.Node{ - &stmt.Do{ - Cond: &scalar.Lnumber{Value: "1"}, - Stmt: &stmt.StmtList{ - Stmts: []node.Node{ - &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}, - }, - }, - }, - }, - }) - - expected := `namespace { - do { - $a; - } while (1); -}` - actual := o.String() - - if expected != actual { - t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) - } -} - -func TestPrintStmtEcho(t *testing.T) { - o := bytes.NewBufferString("") - - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.Echo{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.EchoToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SemiColonToken, + }, + }, Exprs: []node.Node{ &expr.Variable{VarName: &node.Identifier{Value: "a"}}, &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }, }) - expected := `echo $a, $b;` + expected := ` echo$a,$b ;` actual := o.String() if expected != actual { @@ -2868,11 +4316,25 @@ func TestPrintStmtEcho(t *testing.T) { } } -func TestPrintStmtElseIfStmts(t *testing.T) { +func TestPrinterPrintStmtElseIfStmts(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.ElseIf{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ElseifToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Stmt: &stmt.StmtList{ Stmts: []node.Node{ @@ -2881,9 +4343,7 @@ func TestPrintStmtElseIfStmts(t *testing.T) { }, }) - expected := `elseif ($a) { - ; -}` + expected := ` elseif ($a ){;}` actual := o.String() if expected != actual { @@ -2891,17 +4351,30 @@ func TestPrintStmtElseIfStmts(t *testing.T) { } } -func TestPrintStmtElseIfExpr(t *testing.T) { +func TestPrinterPrintStmtElseIfExpr(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.ElseIf{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ElseifToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Stmt: &stmt.Expression{Expr: &scalar.String{Value: "'bar'"}}, }) - expected := `elseif ($a) - 'bar';` + expected := ` elseif ($a )'bar';` actual := o.String() if expected != actual { @@ -2909,16 +4382,16 @@ func TestPrintStmtElseIfExpr(t *testing.T) { } } -func TestPrintStmtElseIfNop(t *testing.T) { +func TestPrinterPrintStmtElseIfNop(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.ElseIf{ Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Stmt: &stmt.Nop{}, }) - expected := `elseif ($a);` + expected := `elseif($a);` actual := o.String() if expected != actual { @@ -2926,11 +4399,17 @@ func TestPrintStmtElseIfNop(t *testing.T) { } } -func TestPrintStmtElseStmts(t *testing.T) { +func TestPrinterPrintStmtElseStmts(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.Else{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ElseToken, + }, + }, Stmt: &stmt.StmtList{ Stmts: []node.Node{ &stmt.Nop{}, @@ -2938,9 +4417,7 @@ func TestPrintStmtElseStmts(t *testing.T) { }, }) - expected := `else { - ; -}` + expected := ` else{;}` actual := o.String() if expected != actual { @@ -2948,16 +4425,21 @@ func TestPrintStmtElseStmts(t *testing.T) { } } -func TestPrintStmtElseExpr(t *testing.T) { +func TestPrinterPrintStmtElseExpr(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.Else{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ElseToken, + }, + }, Stmt: &stmt.Expression{Expr: &scalar.String{Value: "'bar'"}}, }) - expected := `else - 'bar';` + expected := ` else'bar';` actual := o.String() if expected != actual { @@ -2965,10 +4447,10 @@ func TestPrintStmtElseExpr(t *testing.T) { } } -func TestPrintStmtElseNop(t *testing.T) { +func TestPrinterPrintStmtElseNop(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.Else{ Stmt: &stmt.Nop{}, }) @@ -2981,13 +4463,21 @@ func TestPrintStmtElseNop(t *testing.T) { } } -func TestPrintExpression(t *testing.T) { +func TestPrinterPrintExpression(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}}) + p := printer.NewPrinter(o) + p.Print(&stmt.Expression{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SemiColonToken, + }, + }, + Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + }) - expected := `$a;` + expected := `$a ;` actual := o.String() if expected != actual { @@ -2995,25 +4485,31 @@ func TestPrintExpression(t *testing.T) { } } -func TestPrintStmtFinally(t *testing.T) { +func TestPrinterPrintStmtFinally(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ - Stmts: []node.Node{ - &stmt.Finally{ - Stmts: []node.Node{ - &stmt.Nop{}, - }, + p := printer.NewPrinter(o) + p.Print(&stmt.Finally{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.FinallyToken, }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenCurlyBracesToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseCurlyBracesToken, + }, + }, + Stmts: []node.Node{ + &stmt.Nop{}, }, }) - expected := `namespace { - finally { - ; - } -}` + expected := ` finally {; }` actual := o.String() if expected != actual { @@ -3021,126 +4517,53 @@ func TestPrintStmtFinally(t *testing.T) { } } -func TestPrintStmtForStmts(t *testing.T) { +func TestPrinterPrintStmtFor(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ - Stmts: []node.Node{ - &stmt.For{ - Init: []node.Node{ - &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - &expr.Variable{VarName: &node.Identifier{Value: "b"}}, - }, - Cond: []node.Node{ - &expr.Variable{VarName: &node.Identifier{Value: "c"}}, - &expr.Variable{VarName: &node.Identifier{Value: "d"}}, - }, - Loop: []node.Node{ - &expr.Variable{VarName: &node.Identifier{Value: "e"}}, - &expr.Variable{VarName: &node.Identifier{Value: "f"}}, - }, - Stmt: &stmt.StmtList{ - Stmts: []node.Node{ - &stmt.Nop{}, - }, - }, - }, - }, - }) - - expected := `namespace { - for ($a, $b; $c, $d; $e, $f) { - ; - } -}` - actual := o.String() - - if expected != actual { - t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) - } -} - -func TestPrintStmtForExpr(t *testing.T) { - o := bytes.NewBufferString("") - - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ - Stmts: []node.Node{ - &stmt.For{ - Init: []node.Node{ - &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - }, - Cond: []node.Node{ - &expr.Variable{VarName: &node.Identifier{Value: "b"}}, - }, - Loop: []node.Node{ - &expr.Variable{VarName: &node.Identifier{Value: "c"}}, - }, - Stmt: &stmt.Expression{Expr: &scalar.String{Value: "'bar'"}}, - }, - }, - }) - - expected := `namespace { - for ($a; $b; $c) - 'bar'; -}` - actual := o.String() - - if expected != actual { - t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) - } -} - -func TestPrintStmtForNop(t *testing.T) { - o := bytes.NewBufferString("") - - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.For{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ForToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ForInitSemicolonToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ForCondSemicolonToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, Init: []node.Node{ &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - }, - Cond: []node.Node{ &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }, - Loop: []node.Node{ + Cond: []node.Node{ &expr.Variable{VarName: &node.Identifier{Value: "c"}}, + &expr.Variable{VarName: &node.Identifier{Value: "d"}}, }, - Stmt: &stmt.Nop{}, - }) - - expected := `for ($a; $b; $c);` - actual := o.String() - - if expected != actual { - t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) - } -} - -func TestPrintStmtForeachStmts(t *testing.T) { - o := bytes.NewBufferString("") - - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ - Stmts: []node.Node{ - &stmt.Foreach{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Variable: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, - Stmt: &stmt.StmtList{ - Stmts: []node.Node{ - &stmt.Nop{}, - }, - }, + Loop: []node.Node{ + &expr.Variable{VarName: &node.Identifier{Value: "e"}}, + &expr.Variable{VarName: &node.Identifier{Value: "f"}}, + }, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Nop{}, }, }, }) - expected := `namespace { - foreach ($a as $b) { - ; - } -}` + expected := ` for ($a,$b ;$c,$d ;$e,$f ){;}` actual := o.String() if expected != actual { @@ -3148,80 +4571,44 @@ func TestPrintStmtForeachStmts(t *testing.T) { } } -func TestPrintStmtForeachExpr(t *testing.T) { +func TestPrinterPrintStmtForeach(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ - Stmts: []node.Node{ - &stmt.Foreach{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Key: &expr.Variable{VarName: &node.Identifier{Value: "k"}}, - Variable: &expr.Variable{VarName: &node.Identifier{Value: "v"}}, - Stmt: &stmt.Expression{Expr: &scalar.String{Value: "'bar'"}}, - }, - }, - }) - - expected := `namespace { - foreach ($a as $k => $v) - 'bar'; -}` - actual := o.String() - - if expected != actual { - t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) - } -} - -func TestPrintStmtForeachNop(t *testing.T) { - o := bytes.NewBufferString("") - - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.Foreach{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ForeachToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.AsToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.DoubleArrowToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Key: &expr.Variable{VarName: &node.Identifier{Value: "k"}}, - Variable: &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "v"}}}, - Stmt: &stmt.Nop{}, - }) - - expected := `foreach ($a as $k => &$v);` - actual := o.String() - - if expected != actual { - t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) - } -} - -func TestPrintStmtFunction(t *testing.T) { - o := bytes.NewBufferString("") - - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ - Stmts: []node.Node{ - &stmt.Function{ - ReturnsRef: true, - FunctionName: &node.Identifier{Value: "foo"}, - Params: []node.Node{ - &node.Parameter{ - ByRef: true, - Variadic: false, - Variable: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, - }, - }, - ReturnType: &name.FullyQualified{Parts: []node.Node{&name.NamePart{Value: "Foo"}}}, - Stmts: []node.Node{ - &stmt.Nop{}, - }, + Variable: &expr.Variable{VarName: &node.Identifier{Value: "v"}}, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Nop{}, }, }, }) - expected := `namespace { - function &foo(&$var): \Foo { - ; - } -}` + expected := ` foreach ($a as$k =>$v ){;}` actual := o.String() if expected != actual { @@ -3229,18 +4616,90 @@ func TestPrintStmtFunction(t *testing.T) { } } -func TestPrintStmtGlobal(t *testing.T) { +func TestPrinterPrintStmtFunction(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) + p.Print(&stmt.Function{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.FunctionToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.AmpersandToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenCurlyBracesToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseCurlyBracesToken, + }, + }, + ReturnsRef: true, + FunctionName: &node.Identifier{Value: "foo"}, + Params: []node.Node{ + &node.Parameter{ + ByRef: true, + Variadic: false, + Variable: &expr.Variable{VarName: &node.Identifier{Value: "var"}}, + }, + }, + ReturnType: &name.FullyQualified{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.ColonToken, + }, + }, + Parts: []node.Node{&name.NamePart{Value: "Foo"}}, + }, + Stmts: []node.Node{ + &stmt.Nop{}, + }, + }) + + expected := ` function &foo (&$var ) :\Foo {; }` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrinterPrintStmtGlobal(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrinter(o) p.Print(&stmt.Global{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.GlobalToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SemiColonToken, + }, + }, Vars: []node.Node{ &expr.Variable{VarName: &node.Identifier{Value: "a"}}, &expr.Variable{VarName: &node.Identifier{Value: "b"}}, }, }) - expected := `global $a, $b;` + expected := ` global$a,$b ;` actual := o.String() if expected != actual { @@ -3248,15 +4707,25 @@ func TestPrintStmtGlobal(t *testing.T) { } } -func TestPrintStmtGoto(t *testing.T) { +func TestPrinterPrintStmtGoto(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.Goto{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.GotoToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SemiColonToken, + }, + }, Label: &node.Identifier{Value: "FOO"}, }) - expected := `goto FOO;` + expected := ` gotoFOO ;` actual := o.String() if expected != actual { @@ -3264,11 +4733,33 @@ func TestPrintStmtGoto(t *testing.T) { } } -func TestPrintStmtGroupUse(t *testing.T) { +func TestPrinterPrintStmtGroupUse(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.GroupUse{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.UseToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.NsSeparatorToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenCurlyBracesToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseCurlyBracesToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SemiColonToken, + }, + }, UseType: &node.Identifier{Value: "function"}, Prefix: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}}, UseList: []node.Node{ @@ -3282,7 +4773,7 @@ func TestPrintStmtGroupUse(t *testing.T) { }, }) - expected := `use function Foo\{Bar as Baz, Quuz};` + expected := ` usefunctionFoo \ {BarasBaz,Quuz } ;` actual := o.String() if expected != actual { @@ -3290,66 +4781,32 @@ func TestPrintStmtGroupUse(t *testing.T) { } } -func TestPrintHaltCompiler(t *testing.T) { +func TestPrinterPrintHaltCompiler(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&stmt.HaltCompiler{}) - - expected := `__halt_compiler();` - actual := o.String() - - if expected != actual { - t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) - } -} - -func TestPrintIfExpression(t *testing.T) { - o := bytes.NewBufferString("") - - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ - Stmts: []node.Node{ - &stmt.If{ - Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Stmt: &stmt.Expression{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, - }, - ElseIf: []node.Node{ - &stmt.ElseIf{ - Cond: &expr.Variable{VarName: &node.Identifier{Value: "c"}}, - Stmt: &stmt.StmtList{ - Stmts: []node.Node{ - &stmt.Expression{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "d"}}, - }, - }, - }, - }, - &stmt.ElseIf{ - Cond: &expr.Variable{VarName: &node.Identifier{Value: "e"}}, - Stmt: &stmt.Nop{}, - }, - }, - Else: &stmt.Else{ - Stmt: &stmt.Expression{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "f"}}, - }, - }, + p := printer.NewPrinter(o) + p.Print(&stmt.HaltCompiler{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.HaltCompilerToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.SemiColonToken, }, }, }) - expected := `namespace { - if ($a) - $b; - elseif ($c) { - $d; - } - elseif ($e); - else - $f; -}` + expected := ` __halt_compiler ( ) ;` actual := o.String() if expected != actual { @@ -3357,30 +4814,53 @@ func TestPrintIfExpression(t *testing.T) { } } -func TestPrintIfStmtList(t *testing.T) { +func TestPrinterPrintIfExpression(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") - p.Print(&stmt.Namespace{ - Stmts: []node.Node{ - &stmt.If{ - Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + p := printer.NewPrinter(o) + p.Print(&stmt.If{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.IfToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, + Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Stmt: &stmt.Expression{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + ElseIf: []node.Node{ + &stmt.ElseIf{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "c"}}, Stmt: &stmt.StmtList{ Stmts: []node.Node{ &stmt.Expression{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Expr: &expr.Variable{VarName: &node.Identifier{Value: "d"}}, }, }, }, }, + &stmt.ElseIf{ + Cond: &expr.Variable{VarName: &node.Identifier{Value: "e"}}, + Stmt: &stmt.Nop{}, + }, + }, + Else: &stmt.Else{ + Stmt: &stmt.Expression{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "f"}}, + }, }, }) - expected := `namespace { - if ($a) { - $b; - } -}` + expected := ` if ($a )$b;elseif($c){$d;}elseif($e);else$f;` actual := o.String() if expected != actual { @@ -3388,16 +4868,53 @@ func TestPrintIfStmtList(t *testing.T) { } } -func TestPrintIfNop(t *testing.T) { +func TestPrinterPrintIfStmtList(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) + p.Print(&stmt.If{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.IfToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.OpenParenthesisToken, + }, + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.CloseParenthesisToken, + }, + }, + Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Stmt: &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{ + Expr: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + }, + }, + }, + }) + + expected := ` if ($a ){$b;}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrinterPrintIfNop(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrinter(o) p.Print(&stmt.If{ Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Stmt: &stmt.Nop{}, }) - expected := `if ($a);` + expected := `if($a);` actual := o.String() if expected != actual { @@ -3405,15 +4922,21 @@ func TestPrintIfNop(t *testing.T) { } } -func TestPrintInlineHtml(t *testing.T) { +func TestPrinterPrintInlineHtml(t *testing.T) { o := bytes.NewBufferString("") - p := printer.NewPrinter(o, " ") + p := printer.NewPrinter(o) p.Print(&stmt.InlineHtml{ + Meta: []meta.Meta{ + &meta.WhiteSpace{ + Value: " ", + TokenName: meta.InlineHTMLToken, + }, + }, Value: "test", }) - expected := `?>testtest= '1' && c <= '9': goto yystate117 } @@ -5812,27 +5812,18 @@ yystate452: } yystate453: - c = l.Next() - switch { - default: - goto yyabort - case c >= '\x01' && c <= '/' || c >= ':' && c <= '@' || c >= '[' && c <= '^' || c == '`' || c >= '{' && c <= '\u007f': - goto yystate454 - } - -yystate454: c = l.Next() yyrule = 69 l.Mark() goto yyrule69 -yystate455: +yystate454: c = l.Next() yyrule = 95 l.Mark() goto yyrule95 -yystate456: +yystate455: c = l.Next() yyrule = 128 l.Mark() @@ -5840,15 +5831,28 @@ yystate456: default: goto yyrule128 case c == '=': - goto yystate457 + goto yystate456 } -yystate457: +yystate456: c = l.Next() yyrule = 108 l.Mark() goto yyrule108 +yystate457: + c = l.Next() + yyrule = 132 + l.Mark() + switch { + default: + goto yyrule132 + case c == '_': + goto yystate458 + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate159 + } + yystate458: c = l.Next() yyrule = 132 @@ -5856,9 +5860,23 @@ yystate458: switch { default: goto yyrule132 - case c == '_': + case c == 'C' || c == 'c': goto yystate459 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c == 'D' || c == 'd': + goto yystate466 + case c == 'F' || c == 'f': + goto yystate471 + case c == 'H' || c == 'h': + goto yystate486 + case c == 'L' || c == 'l': + goto yystate499 + case c == 'M' || c == 'm': + goto yystate505 + case c == 'N' || c == 'n': + goto yystate513 + case c == 'T' || c == 't': + goto yystate524 + case c >= '0' && c <= '9' || c == 'A' || c == 'B' || c == 'E' || c == 'G' || c >= 'I' && c <= 'K' || c >= 'O' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c == 'a' || c == 'b' || c == 'e' || c == 'g' || c >= 'i' && c <= 'k' || c >= 'o' && c <= 's' || c >= 'u' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -5869,23 +5887,9 @@ yystate459: switch { default: goto yyrule132 - case c == 'C' || c == 'c': - goto yystate460 - case c == 'D' || c == 'd': - goto yystate467 - case c == 'F' || c == 'f': - goto yystate472 - case c == 'H' || c == 'h': - goto yystate487 case c == 'L' || c == 'l': - goto yystate500 - case c == 'M' || c == 'm': - goto yystate506 - case c == 'N' || c == 'n': - goto yystate514 - case c == 'T' || c == 't': - goto yystate525 - case c >= '0' && c <= '9' || c == 'A' || c == 'B' || c == 'E' || c == 'G' || c >= 'I' && c <= 'K' || c >= 'O' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c == 'a' || c == 'b' || c == 'e' || c == 'g' || c >= 'i' && c <= 'k' || c >= 'o' && c <= 's' || c >= 'u' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate460 + case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -5896,9 +5900,9 @@ yystate460: switch { default: goto yyrule132 - case c == 'L' || c == 'l': + case c == 'A' || c == 'a': goto yystate461 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -5909,9 +5913,9 @@ yystate461: switch { default: goto yyrule132 - case c == 'A' || c == 'a': + case c == 'S' || c == 's': goto yystate462 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'R' || c >= 'T' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'r' || c >= 't' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -5935,9 +5939,9 @@ yystate463: switch { default: goto yyrule132 - case c == 'S' || c == 's': + case c == '_': goto yystate464 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'R' || c >= 'T' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'r' || c >= 't' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -5955,19 +5959,6 @@ yystate464: } yystate465: - c = l.Next() - yyrule = 132 - l.Mark() - switch { - default: - goto yyrule132 - case c == '_': - goto yystate466 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate159 - } - -yystate466: c = l.Next() yyrule = 75 l.Mark() @@ -5978,6 +5969,19 @@ yystate466: goto yystate159 } +yystate466: + c = l.Next() + yyrule = 132 + l.Mark() + switch { + default: + goto yyrule132 + case c == 'I' || c == 'i': + goto yystate467 + case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate159 + } + yystate467: c = l.Next() yyrule = 132 @@ -5985,9 +5989,9 @@ yystate467: switch { default: goto yyrule132 - case c == 'I' || c == 'i': + case c == 'R' || c == 'r': goto yystate468 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Q' || c >= 'S' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'q' || c >= 's' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -5998,9 +6002,9 @@ yystate468: switch { default: goto yyrule132 - case c == 'R' || c == 'r': + case c == '_': goto yystate469 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Q' || c >= 'S' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'q' || c >= 's' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6018,19 +6022,6 @@ yystate469: } yystate470: - c = l.Next() - yyrule = 132 - l.Mark() - switch { - default: - goto yyrule132 - case c == '_': - goto yystate471 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate159 - } - -yystate471: c = l.Next() yyrule = 76 l.Mark() @@ -6041,6 +6032,21 @@ yystate471: goto yystate159 } +yystate471: + c = l.Next() + yyrule = 132 + l.Mark() + switch { + default: + goto yyrule132 + case c == 'I' || c == 'i': + goto yystate472 + case c == 'U' || c == 'u': + goto yystate477 + case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'T' || c >= 'V' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 't' || c >= 'v' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate159 + } + yystate472: c = l.Next() yyrule = 132 @@ -6048,11 +6054,9 @@ yystate472: switch { default: goto yyrule132 - case c == 'I' || c == 'i': + case c == 'L' || c == 'l': goto yystate473 - case c == 'U' || c == 'u': - goto yystate478 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'T' || c >= 'V' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 't' || c >= 'v' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6063,9 +6067,9 @@ yystate473: switch { default: goto yyrule132 - case c == 'L' || c == 'l': + case c == 'E' || c == 'e': goto yystate474 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6076,9 +6080,9 @@ yystate474: switch { default: goto yyrule132 - case c == 'E' || c == 'e': + case c == '_': goto yystate475 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6096,19 +6100,6 @@ yystate475: } yystate476: - c = l.Next() - yyrule = 132 - l.Mark() - switch { - default: - goto yyrule132 - case c == '_': - goto yystate477 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate159 - } - -yystate477: c = l.Next() yyrule = 77 l.Mark() @@ -6119,6 +6110,19 @@ yystate477: goto yystate159 } +yystate477: + c = l.Next() + yyrule = 132 + l.Mark() + switch { + default: + goto yyrule132 + case c == 'N' || c == 'n': + goto yystate478 + case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate159 + } + yystate478: c = l.Next() yyrule = 132 @@ -6126,9 +6130,9 @@ yystate478: switch { default: goto yyrule132 - case c == 'N' || c == 'n': + case c == 'C' || c == 'c': goto yystate479 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c == 'A' || c == 'B' || c >= 'D' && c <= 'Z' || c == '_' || c == 'a' || c == 'b' || c >= 'd' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6139,9 +6143,9 @@ yystate479: switch { default: goto yyrule132 - case c == 'C' || c == 'c': + case c == 'T' || c == 't': goto yystate480 - case c >= '0' && c <= '9' || c == 'A' || c == 'B' || c >= 'D' && c <= 'Z' || c == '_' || c == 'a' || c == 'b' || c >= 'd' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6152,9 +6156,9 @@ yystate480: switch { default: goto yyrule132 - case c == 'T' || c == 't': + case c == 'I' || c == 'i': goto yystate481 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6165,9 +6169,9 @@ yystate481: switch { default: goto yyrule132 - case c == 'I' || c == 'i': + case c == 'O' || c == 'o': goto yystate482 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'N' || c >= 'P' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'n' || c >= 'p' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6178,9 +6182,9 @@ yystate482: switch { default: goto yyrule132 - case c == 'O' || c == 'o': + case c == 'N' || c == 'n': goto yystate483 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'N' || c >= 'P' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'n' || c >= 'p' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6191,9 +6195,9 @@ yystate483: switch { default: goto yyrule132 - case c == 'N' || c == 'n': + case c == '_': goto yystate484 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6211,19 +6215,6 @@ yystate484: } yystate485: - c = l.Next() - yyrule = 132 - l.Mark() - switch { - default: - goto yyrule132 - case c == '_': - goto yystate486 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate159 - } - -yystate486: c = l.Next() yyrule = 78 l.Mark() @@ -6234,6 +6225,19 @@ yystate486: goto yystate159 } +yystate486: + c = l.Next() + yyrule = 132 + l.Mark() + switch { + default: + goto yyrule132 + case c == 'A' || c == 'a': + goto yystate487 + case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate159 + } + yystate487: c = l.Next() yyrule = 132 @@ -6241,9 +6245,9 @@ yystate487: switch { default: goto yyrule132 - case c == 'A' || c == 'a': + case c == 'L' || c == 'l': goto yystate488 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6254,9 +6258,9 @@ yystate488: switch { default: goto yyrule132 - case c == 'L' || c == 'l': + case c == 'T' || c == 't': goto yystate489 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6267,9 +6271,9 @@ yystate489: switch { default: goto yyrule132 - case c == 'T' || c == 't': + case c == '_': goto yystate490 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6280,9 +6284,9 @@ yystate490: switch { default: goto yyrule132 - case c == '_': + case c == 'C' || c == 'c': goto yystate491 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c == 'A' || c == 'B' || c >= 'D' && c <= 'Z' || c == '_' || c == 'a' || c == 'b' || c >= 'd' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6293,9 +6297,9 @@ yystate491: switch { default: goto yyrule132 - case c == 'C' || c == 'c': + case c == 'O' || c == 'o': goto yystate492 - case c >= '0' && c <= '9' || c == 'A' || c == 'B' || c >= 'D' && c <= 'Z' || c == '_' || c == 'a' || c == 'b' || c >= 'd' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'N' || c >= 'P' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'n' || c >= 'p' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6306,9 +6310,9 @@ yystate492: switch { default: goto yyrule132 - case c == 'O' || c == 'o': + case c == 'M' || c == 'm': goto yystate493 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'N' || c >= 'P' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'n' || c >= 'p' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'L' || c >= 'N' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'l' || c >= 'n' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6319,9 +6323,9 @@ yystate493: switch { default: goto yyrule132 - case c == 'M' || c == 'm': + case c == 'P' || c == 'p': goto yystate494 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'L' || c >= 'N' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'l' || c >= 'n' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'O' || c >= 'Q' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'o' || c >= 'q' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6332,9 +6336,9 @@ yystate494: switch { default: goto yyrule132 - case c == 'P' || c == 'p': + case c == 'I' || c == 'i': goto yystate495 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'O' || c >= 'Q' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'o' || c >= 'q' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6345,9 +6349,9 @@ yystate495: switch { default: goto yyrule132 - case c == 'I' || c == 'i': + case c == 'L' || c == 'l': goto yystate496 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6358,26 +6362,13 @@ yystate496: switch { default: goto yyrule132 - case c == 'L' || c == 'l': + case c == 'E' || c == 'e': goto yystate497 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } yystate497: - c = l.Next() - yyrule = 132 - l.Mark() - switch { - default: - goto yyrule132 - case c == 'E' || c == 'e': - goto yystate498 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate159 - } - -yystate498: c = l.Next() yyrule = 132 l.Mark() @@ -6385,12 +6376,12 @@ yystate498: default: goto yyrule132 case c == 'R' || c == 'r': - goto yystate499 + goto yystate498 case c >= '0' && c <= '9' || c >= 'A' && c <= 'Q' || c >= 'S' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'q' || c >= 's' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } -yystate499: +yystate498: c = l.Next() yyrule = 83 l.Mark() @@ -6401,7 +6392,7 @@ yystate499: goto yystate159 } -yystate500: +yystate499: c = l.Next() yyrule = 132 l.Mark() @@ -6409,11 +6400,24 @@ yystate500: default: goto yyrule132 case c == 'I' || c == 'i': - goto yystate501 + goto yystate500 case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } +yystate500: + c = l.Next() + yyrule = 132 + l.Mark() + switch { + default: + goto yyrule132 + case c == 'N' || c == 'n': + goto yystate501 + case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate159 + } + yystate501: c = l.Next() yyrule = 132 @@ -6421,9 +6425,9 @@ yystate501: switch { default: goto yyrule132 - case c == 'N' || c == 'n': + case c == 'E' || c == 'e': goto yystate502 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6434,9 +6438,9 @@ yystate502: switch { default: goto yyrule132 - case c == 'E' || c == 'e': + case c == '_': goto yystate503 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6454,19 +6458,6 @@ yystate503: } yystate504: - c = l.Next() - yyrule = 132 - l.Mark() - switch { - default: - goto yyrule132 - case c == '_': - goto yystate505 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate159 - } - -yystate505: c = l.Next() yyrule = 79 l.Mark() @@ -6477,6 +6468,19 @@ yystate505: goto yystate159 } +yystate505: + c = l.Next() + yyrule = 132 + l.Mark() + switch { + default: + goto yyrule132 + case c == 'E' || c == 'e': + goto yystate506 + case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate159 + } + yystate506: c = l.Next() yyrule = 132 @@ -6484,9 +6488,9 @@ yystate506: switch { default: goto yyrule132 - case c == 'E' || c == 'e': + case c == 'T' || c == 't': goto yystate507 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6497,9 +6501,9 @@ yystate507: switch { default: goto yyrule132 - case c == 'T' || c == 't': + case c == 'H' || c == 'h': goto yystate508 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'G' || c >= 'I' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'g' || c >= 'i' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6510,9 +6514,9 @@ yystate508: switch { default: goto yyrule132 - case c == 'H' || c == 'h': + case c == 'O' || c == 'o': goto yystate509 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'G' || c >= 'I' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'g' || c >= 'i' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'N' || c >= 'P' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'n' || c >= 'p' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6523,9 +6527,9 @@ yystate509: switch { default: goto yyrule132 - case c == 'O' || c == 'o': + case c == 'D' || c == 'd': goto yystate510 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'N' || c >= 'P' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'n' || c >= 'p' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'C' || c >= 'E' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'c' || c >= 'e' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6536,9 +6540,9 @@ yystate510: switch { default: goto yyrule132 - case c == 'D' || c == 'd': + case c == '_': goto yystate511 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'C' || c >= 'E' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'c' || c >= 'e' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6556,19 +6560,6 @@ yystate511: } yystate512: - c = l.Next() - yyrule = 132 - l.Mark() - switch { - default: - goto yyrule132 - case c == '_': - goto yystate513 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate159 - } - -yystate513: c = l.Next() yyrule = 81 l.Mark() @@ -6579,6 +6570,19 @@ yystate513: goto yystate159 } +yystate513: + c = l.Next() + yyrule = 132 + l.Mark() + switch { + default: + goto yyrule132 + case c == 'A' || c == 'a': + goto yystate514 + case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate159 + } + yystate514: c = l.Next() yyrule = 132 @@ -6586,9 +6590,9 @@ yystate514: switch { default: goto yyrule132 - case c == 'A' || c == 'a': + case c == 'M' || c == 'm': goto yystate515 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'L' || c >= 'N' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'l' || c >= 'n' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6599,9 +6603,9 @@ yystate515: switch { default: goto yyrule132 - case c == 'M' || c == 'm': + case c == 'E' || c == 'e': goto yystate516 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'L' || c >= 'N' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'l' || c >= 'n' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6612,9 +6616,9 @@ yystate516: switch { default: goto yyrule132 - case c == 'E' || c == 'e': + case c == 'S' || c == 's': goto yystate517 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'R' || c >= 'T' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'r' || c >= 't' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6625,9 +6629,9 @@ yystate517: switch { default: goto yyrule132 - case c == 'S' || c == 's': + case c == 'P' || c == 'p': goto yystate518 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'R' || c >= 'T' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'r' || c >= 't' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'O' || c >= 'Q' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'o' || c >= 'q' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6638,9 +6642,9 @@ yystate518: switch { default: goto yyrule132 - case c == 'P' || c == 'p': + case c == 'A' || c == 'a': goto yystate519 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'O' || c >= 'Q' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'o' || c >= 'q' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6651,9 +6655,9 @@ yystate519: switch { default: goto yyrule132 - case c == 'A' || c == 'a': + case c == 'C' || c == 'c': goto yystate520 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c == 'A' || c == 'B' || c >= 'D' && c <= 'Z' || c == '_' || c == 'a' || c == 'b' || c >= 'd' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6664,9 +6668,9 @@ yystate520: switch { default: goto yyrule132 - case c == 'C' || c == 'c': + case c == 'E' || c == 'e': goto yystate521 - case c >= '0' && c <= '9' || c == 'A' || c == 'B' || c >= 'D' && c <= 'Z' || c == '_' || c == 'a' || c == 'b' || c >= 'd' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6677,9 +6681,9 @@ yystate521: switch { default: goto yyrule132 - case c == 'E' || c == 'e': + case c == '_': goto yystate522 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6697,19 +6701,6 @@ yystate522: } yystate523: - c = l.Next() - yyrule = 132 - l.Mark() - switch { - default: - goto yyrule132 - case c == '_': - goto yystate524 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate159 - } - -yystate524: c = l.Next() yyrule = 80 l.Mark() @@ -6720,6 +6711,19 @@ yystate524: goto yystate159 } +yystate524: + c = l.Next() + yyrule = 132 + l.Mark() + switch { + default: + goto yyrule132 + case c == 'R' || c == 'r': + goto yystate525 + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Q' || c >= 'S' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'q' || c >= 's' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate159 + } + yystate525: c = l.Next() yyrule = 132 @@ -6727,9 +6731,9 @@ yystate525: switch { default: goto yyrule132 - case c == 'R' || c == 'r': + case c == 'A' || c == 'a': goto yystate526 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Q' || c >= 'S' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'q' || c >= 's' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6740,9 +6744,9 @@ yystate526: switch { default: goto yyrule132 - case c == 'A' || c == 'a': + case c == 'I' || c == 'i': goto yystate527 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6753,9 +6757,9 @@ yystate527: switch { default: goto yyrule132 - case c == 'I' || c == 'i': + case c == 'T' || c == 't': goto yystate528 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6766,9 +6770,9 @@ yystate528: switch { default: goto yyrule132 - case c == 'T' || c == 't': + case c == '_': goto yystate529 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } @@ -6786,19 +6790,6 @@ yystate529: } yystate530: - c = l.Next() - yyrule = 132 - l.Mark() - switch { - default: - goto yyrule132 - case c == '_': - goto yystate531 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate159 - } - -yystate531: c = l.Next() yyrule = 82 l.Mark() @@ -6809,13 +6800,13 @@ yystate531: goto yystate159 } -yystate532: +yystate531: c = l.Next() yyrule = 139 l.Mark() goto yyrule139 -yystate533: +yystate532: c = l.Next() yyrule = 132 l.Mark() @@ -6825,23 +6816,23 @@ yystate533: case c == '"': goto yystate18 case c == '<': - goto yystate534 + goto yystate533 case c == 'R' || c == 'r': goto yystate175 case c >= '0' && c <= '9' || c >= 'A' && c <= 'Q' || c >= 'S' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'q' || c >= 's' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate159 } +yystate533: + c = l.Next() + switch { + default: + goto yyabort + case c == '<': + goto yystate534 + } + yystate534: - c = l.Next() - switch { - default: - goto yyabort - case c == '<': - goto yystate535 - } - -yystate535: c = l.Next() switch { default: @@ -6850,13 +6841,13 @@ yystate535: goto yystate132 } -yystate536: +yystate535: c = l.Next() yyrule = 129 l.Mark() goto yyrule129 -yystate537: +yystate536: c = l.Next() yyrule = 128 l.Mark() @@ -6864,59 +6855,59 @@ yystate537: default: goto yyrule128 case c == '=': - goto yystate538 + goto yystate537 case c == '|': - goto yystate539 + goto yystate538 } -yystate538: +yystate537: c = l.Next() yyrule = 101 l.Mark() goto yyrule101 -yystate539: +yystate538: c = l.Next() yyrule = 99 l.Mark() goto yyrule99 -yystate540: +yystate539: c = l.Next() yyrule = 130 l.Mark() goto yyrule130 - goto yystate541 // silence unused label error -yystate541: + goto yystate540 // silence unused label error +yystate540: c = l.Next() -yystart541: +yystart540: switch { default: goto yyabort case c == '"': - goto yystate543 - case c == '$': - goto yystate544 - case c == '{': - goto yystate547 - case c >= '\x01' && c <= '!' || c == '#' || c >= '%' && c <= 'z' || c >= '|' && c <= 'ÿ': goto yystate542 + case c == '$': + goto yystate543 + case c == '{': + goto yystate546 + case c >= '\x01' && c <= '!' || c == '#' || c >= '%' && c <= 'z' || c >= '|' && c <= 'ÿ': + goto yystate541 } -yystate542: +yystate541: c = l.Next() yyrule = 150 l.Mark() goto yyrule150 -yystate543: +yystate542: c = l.Next() yyrule = 146 l.Mark() goto yyrule146 -yystate544: +yystate543: c = l.Next() yyrule = 150 l.Mark() @@ -6924,12 +6915,12 @@ yystate544: default: goto yyrule150 case c == '{': - goto yystate546 - case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate545 + case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate544 } -yystate545: +yystate544: c = l.Next() yyrule = 149 l.Mark() @@ -6937,16 +6928,16 @@ yystate545: default: goto yyrule149 case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate545 + goto yystate544 } -yystate546: +yystate545: c = l.Next() yyrule = 148 l.Mark() goto yyrule148 -yystate547: +yystate546: c = l.Next() yyrule = 150 l.Mark() @@ -6954,41 +6945,41 @@ yystate547: default: goto yyrule150 case c == '$': - goto yystate548 + goto yystate547 } -yystate548: +yystate547: c = l.Next() yyrule = 147 l.Mark() goto yyrule147 - goto yystate549 // silence unused label error -yystate549: + goto yystate548 // silence unused label error +yystate548: c = l.Next() -yystart549: +yystart548: switch { default: goto yyabort case c == '$': - goto yystate551 - case c == '-': - goto yystate553 - case c == '[': - goto yystate558 - case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate556 - case c >= '\x01' && c <= '#' || c >= '%' && c <= ',' || c >= '.' && c <= '@' || c >= '\\' && c <= '^' || c == '`' || c >= '{' && c <= '~': goto yystate550 + case c == '-': + goto yystate552 + case c == '[': + goto yystate557 + case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate555 + case c >= '\x01' && c <= '#' || c >= '%' && c <= ',' || c >= '.' && c <= '@' || c >= '\\' && c <= '^' || c == '`' || c >= '{' && c <= '~': + goto yystate549 } -yystate550: +yystate549: c = l.Next() yyrule = 157 l.Mark() goto yyrule157 -yystate551: +yystate550: c = l.Next() yyrule = 157 l.Mark() @@ -6996,10 +6987,10 @@ yystate551: default: goto yyrule157 case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate552 + goto yystate551 } -yystate552: +yystate551: c = l.Next() yyrule = 153 l.Mark() @@ -7007,10 +6998,10 @@ yystate552: default: goto yyrule153 case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate552 + goto yystate551 } -yystate553: +yystate552: c = l.Next() yyrule = 157 l.Mark() @@ -7018,19 +7009,19 @@ yystate553: default: goto yyrule157 case c == '>': - goto yystate554 + goto yystate553 } -yystate554: +yystate553: c = l.Next() switch { default: goto yyabort case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate555 + goto yystate554 } -yystate555: +yystate554: c = l.Next() yyrule = 154 l.Mark() @@ -7038,7 +7029,18 @@ yystate555: default: goto yyrule154 case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate555 + goto yystate554 + } + +yystate555: + c = l.Next() + yyrule = 155 + l.Mark() + switch { + default: + goto yyrule155 + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate556 } yystate556: @@ -7049,59 +7051,54 @@ yystate556: default: goto yyrule155 case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate557 + goto yystate556 } yystate557: - c = l.Next() - yyrule = 155 - l.Mark() - switch { - default: - goto yyrule155 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate557 - } - -yystate558: c = l.Next() yyrule = 156 l.Mark() goto yyrule156 - goto yystate559 // silence unused label error -yystate559: + goto yystate558 // silence unused label error +yystate558: c = l.Next() -yystart559: +yystart558: switch { default: goto yyabort case c == '!' || c == '%' || c == '&' || c >= '(' && c <= '/' || c >= ':' && c <= '@' || c == '[' || c == '^' || c == '|' || c == '~': - goto yystate563 - case c == '$': - goto yystate564 - case c == '0': - goto yystate566 - case c == '\n': goto yystate562 - case c == '\t' || c == '\r' || c == ' ' || c == '#' || c == '\'' || c == '\\': + case c == '$': + goto yystate563 + case c == '0': + goto yystate565 + case c == '\n': goto yystate561 - case c == ']': - goto yystate575 - case c >= '1' && c <= '9': - goto yystate572 - case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate573 - case c >= '\x01' && c <= '\b' || c == '\v' || c == '\f' || c >= '\x0e' && c <= '\x1f' || c == '"' || c == '`' || c == '{' || c == '}': + case c == '\t' || c == '\r' || c == ' ' || c == '#' || c == '\'' || c == '\\': goto yystate560 + case c == ']': + goto yystate574 + case c >= '1' && c <= '9': + goto yystate571 + case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate572 + case c >= '\x01' && c <= '\b' || c == '\v' || c == '\f' || c >= '\x0e' && c <= '\x1f' || c == '"' || c == '`' || c == '{' || c == '}': + goto yystate559 } -yystate560: +yystate559: c = l.Next() yyrule = 164 l.Mark() goto yyrule164 +yystate560: + c = l.Next() + yyrule = 162 + l.Mark() + goto yyrule162 + yystate561: c = l.Next() yyrule = 162 @@ -7109,18 +7106,12 @@ yystate561: goto yyrule162 yystate562: - c = l.Next() - yyrule = 162 - l.Mark() - goto yyrule162 - -yystate563: c = l.Next() yyrule = 163 l.Mark() goto yyrule163 -yystate564: +yystate563: c = l.Next() yyrule = 163 l.Mark() @@ -7128,10 +7119,10 @@ yystate564: default: goto yyrule163 case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate565 + goto yystate564 } -yystate565: +yystate564: c = l.Next() yyrule = 159 l.Mark() @@ -7139,7 +7130,22 @@ yystate565: default: goto yyrule159 case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate565 + goto yystate564 + } + +yystate565: + c = l.Next() + yyrule = 158 + l.Mark() + switch { + default: + goto yyrule158 + case c == 'B' || c == 'b': + goto yystate567 + case c == 'X' || c == 'x': + goto yystate569 + case c >= '0' && c <= '9': + goto yystate566 } yystate566: @@ -7149,35 +7155,20 @@ yystate566: switch { default: goto yyrule158 - case c == 'B' || c == 'b': - goto yystate568 - case c == 'X' || c == 'x': - goto yystate570 case c >= '0' && c <= '9': - goto yystate567 + goto yystate566 } yystate567: - c = l.Next() - yyrule = 158 - l.Mark() - switch { - default: - goto yyrule158 - case c >= '0' && c <= '9': - goto yystate567 - } - -yystate568: c = l.Next() switch { default: goto yyabort case c == '0' || c == '1': - goto yystate569 + goto yystate568 } -yystate569: +yystate568: c = l.Next() yyrule = 158 l.Mark() @@ -7185,16 +7176,27 @@ yystate569: default: goto yyrule158 case c == '0' || c == '1': - goto yystate569 + goto yystate568 } -yystate570: +yystate569: c = l.Next() switch { default: goto yyabort case c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f': - goto yystate571 + goto yystate570 + } + +yystate570: + c = l.Next() + yyrule = 158 + l.Mark() + switch { + default: + goto yyrule158 + case c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f': + goto yystate570 } yystate571: @@ -7204,19 +7206,19 @@ yystate571: switch { default: goto yyrule158 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f': - goto yystate571 + case c >= '0' && c <= '9': + goto yystate566 } yystate572: c = l.Next() - yyrule = 158 + yyrule = 160 l.Mark() switch { default: - goto yyrule158 - case c >= '0' && c <= '9': - goto yystate567 + goto yyrule160 + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate573 } yystate573: @@ -7227,46 +7229,35 @@ yystate573: default: goto yyrule160 case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate574 + goto yystate573 } yystate574: - c = l.Next() - yyrule = 160 - l.Mark() - switch { - default: - goto yyrule160 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate574 - } - -yystate575: c = l.Next() yyrule = 161 l.Mark() goto yyrule161 - goto yystate576 // silence unused label error -yystate576: + goto yystate575 // silence unused label error +yystate575: c = l.Next() -yystart576: +yystart575: switch { default: goto yyabort case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate578 - case c >= '\x01' && c <= '\t' || c >= '\v' && c <= '@' || c >= '[' && c <= '^' || c == '`' || c >= '{' && c <= '~': goto yystate577 + case c >= '\x01' && c <= '\t' || c >= '\v' && c <= '@' || c >= '[' && c <= '^' || c == '`' || c >= '{' && c <= '~': + goto yystate576 } -yystate577: +yystate576: c = l.Next() yyrule = 166 l.Mark() goto yyrule166 -yystate578: +yystate577: c = l.Next() yyrule = 166 l.Mark() @@ -7274,53 +7265,64 @@ yystate578: default: goto yyrule166 case c == '[' || c == '}': - goto yystate580 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate579 + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate578 } -yystate579: +yystate578: c = l.Next() switch { default: goto yyabort case c == '[' || c == '}': - goto yystate580 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate579 + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate578 } -yystate580: +yystate579: c = l.Next() yyrule = 165 l.Mark() goto yyrule165 - goto yystate581 // silence unused label error -yystate581: + goto yystate580 // silence unused label error +yystate580: c = l.Next() -yystart581: +yystart580: switch { default: goto yyabort case c == '-': - goto yystate585 - case c == '\n': goto yystate584 - case c == '\t' || c == '\r' || c == ' ': + case c == '\n': goto yystate583 - case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate587 - case c >= '\x01' && c <= '\b' || c == '\v' || c == '\f' || c >= '\x0e' && c <= '\x1f' || c >= '!' && c <= ',' || c >= '.' && c <= '@' || c >= '[' && c <= '^' || c == '`' || c >= '{' && c <= '~': + case c == '\t' || c == '\r' || c == ' ': goto yystate582 + case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate586 + case c >= '\x01' && c <= '\b' || c == '\v' || c == '\f' || c >= '\x0e' && c <= '\x1f' || c >= '!' && c <= ',' || c >= '.' && c <= '@' || c >= '[' && c <= '^' || c == '`' || c >= '{' && c <= '~': + goto yystate581 } -yystate582: +yystate581: c = l.Next() yyrule = 137 l.Mark() goto yyrule137 +yystate582: + c = l.Next() + yyrule = 134 + l.Mark() + switch { + default: + goto yyrule134 + case c == '\t' || c == '\n' || c == '\r' || c == ' ': + goto yystate583 + } + yystate583: c = l.Next() yyrule = 134 @@ -7329,21 +7331,10 @@ yystate583: default: goto yyrule134 case c == '\t' || c == '\n' || c == '\r' || c == ' ': - goto yystate584 + goto yystate583 } yystate584: - c = l.Next() - yyrule = 134 - l.Mark() - switch { - default: - goto yyrule134 - case c == '\t' || c == '\n' || c == '\r' || c == ' ': - goto yystate584 - } - -yystate585: c = l.Next() yyrule = 137 l.Mark() @@ -7351,15 +7342,26 @@ yystate585: default: goto yyrule137 case c == '>': - goto yystate586 + goto yystate585 } -yystate586: +yystate585: c = l.Next() yyrule = 135 l.Mark() goto yyrule135 +yystate586: + c = l.Next() + yyrule = 136 + l.Mark() + switch { + default: + goto yyrule136 + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate587 + } + yystate587: c = l.Next() yyrule = 136 @@ -7368,32 +7370,21 @@ yystate587: default: goto yyrule136 case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate588 + goto yystate587 } + goto yystate588 // silence unused label error yystate588: c = l.Next() - yyrule = 136 - l.Mark() - switch { - default: - goto yyrule136 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate588 - } - - goto yystate589 // silence unused label error -yystate589: - c = l.Next() -yystart589: +yystart588: switch { default: goto yyabort case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate590 + goto yystate589 } -yystate590: +yystate589: c = l.Next() yyrule = 144 l.Mark() @@ -7401,54 +7392,67 @@ yystate590: default: goto yyrule144 case c == ';': - goto yystate591 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate590 + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate589 } -yystate591: +yystate590: c = l.Next() yyrule = 143 l.Mark() goto yyrule143 - goto yystate592 // silence unused label error -yystate592: + goto yystate591 // silence unused label error +yystate591: c = l.Next() -yystart592: +yystart591: switch { default: goto yyabort case c >= '\x01' && c <= 'ÿ': - goto yystate593 + goto yystate592 } -yystate593: +yystate592: c = l.Next() yyrule = 142 l.Mark() goto yyrule142 - goto yystate594 // silence unused label error -yystate594: + goto yystate593 // silence unused label error +yystate593: c = l.Next() -yystart594: +yystart593: switch { default: goto yyabort case c == '$': - goto yystate596 - case c == '{': - goto yystate597 - case c >= '\x01' && c <= '#' || c >= '%' && c <= 'z' || c >= '|' && c <= 'ÿ': goto yystate595 + case c == '{': + goto yystate596 + case c >= '\x01' && c <= '#' || c >= '%' && c <= 'z' || c >= '|' && c <= 'ÿ': + goto yystate594 } +yystate594: + c = l.Next() + yyrule = 152 + l.Mark() + goto yyrule152 + yystate595: c = l.Next() yyrule = 152 l.Mark() - goto yyrule152 + switch { + default: + goto yyrule152 + case c == '{': + goto yystate545 + case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate544 + } yystate596: c = l.Next() @@ -7457,47 +7461,34 @@ yystate596: switch { default: goto yyrule152 - case c == '{': - goto yystate546 - case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': - goto yystate545 + case c == '$': + goto yystate547 } + goto yystate597 // silence unused label error yystate597: c = l.Next() - yyrule = 152 - l.Mark() - switch { - default: - goto yyrule152 - case c == '$': - goto yystate548 - } - - goto yystate598 // silence unused label error -yystate598: - c = l.Next() -yystart598: +yystart597: switch { default: goto yyabort case c == '$': - goto yystate600 - case c == '`': - goto yystate601 - case c == '{': - goto yystate602 - case c >= '\x01' && c <= '#' || c >= '%' && c <= '_' || c >= 'a' && c <= 'z' || c >= '|' && c <= 'ÿ': goto yystate599 + case c == '`': + goto yystate600 + case c == '{': + goto yystate601 + case c >= '\x01' && c <= '#' || c >= '%' && c <= '_' || c >= 'a' && c <= 'z' || c >= '|' && c <= 'ÿ': + goto yystate598 } -yystate599: +yystate598: c = l.Next() yyrule = 151 l.Mark() goto yyrule151 -yystate600: +yystate599: c = l.Next() yyrule = 151 l.Mark() @@ -7505,18 +7496,18 @@ yystate600: default: goto yyrule151 case c == '{': - goto yystate546 - case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': goto yystate545 + case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ': + goto yystate544 } -yystate601: +yystate600: c = l.Next() yyrule = 140 l.Mark() goto yyrule140 -yystate602: +yystate601: c = l.Next() yyrule = 151 l.Mark() @@ -7524,7 +7515,7 @@ yystate602: default: goto yyrule151 case c == '$': - goto yystate548 + goto yystate547 } yyrule1: // [ \t\n\r]+ @@ -7997,7 +7988,7 @@ yyrule68: // while return T_WHILE goto yystate0 } -yyrule69: // yield[ \t\n\r]+from[^a-zA-Z0-9_\x80-\xff] +yyrule69: // yield[ \t\n\r]+from { lval.Token(l.createToken(l.Token())) return T_YIELD_FROM @@ -8356,6 +8347,7 @@ yyrule126: // (#|[/][/]) } case '\n': + c = l.Next() case '?': c = l.Next() if c == '>' { @@ -8441,8 +8433,10 @@ yyrule133: // -> goto yystate0 } yyrule134: // [ \t\n\r]+ - - goto yystate0 + { + l.addWhiteSpace(l.Token()) + goto yystate0 + } yyrule135: // -> { lval.Token(l.createToken(l.Token())) @@ -8899,8 +8893,13 @@ yyrule166: // . goto yyabort // silence unused label error yyabort: // no lexem recognized - 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 } diff --git a/scanner/scanner.l b/scanner/scanner.l index cfa3dda..53fc614 100644 --- a/scanner/scanner.l +++ b/scanner/scanner.l @@ -191,7 +191,7 @@ NEW_LINE (\r|\n|\r\n) use lval.Token(l.createToken(l.Token())); return T_USE var lval.Token(l.createToken(l.Token())); return T_VAR while lval.Token(l.createToken(l.Token())); return T_WHILE -yield[ \t\n\r]+from[^a-zA-Z0-9_\x80-\xff] lval.Token(l.createToken(l.Token())); return T_YIELD_FROM +yield[ \t\n\r]+from lval.Token(l.createToken(l.Token())); return T_YIELD_FROM yield lval.Token(l.createToken(l.Token())); return T_YIELD include lval.Token(l.createToken(l.Token())); return T_INCLUDE 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) {VAR_NAME} lval.Token(l.createToken(l.Token())); return T_STRING -> l.begin(PROPERTY);lval.Token(l.createToken(l.Token())); return T_OBJECT_OPERATOR; -[ \t\n\r]+ +[ \t\n\r]+ l.addWhiteSpace(l.Token()) -> lval.Token(l.createToken(l.Token())); return T_OBJECT_OPERATOR; {VAR_NAME} l.begin(PHP);lval.Token(l.createToken(l.Token())); return T_STRING; . l.ungetChars(1);l.begin(PHP) @@ -650,6 +651,13 @@ NEW_LINE (\r|\n|\r\n) . 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 } \ No newline at end of file diff --git a/scanner/scanner_test.go b/scanner/scanner_test.go index 9f52559..408d0ff 100644 --- a/scanner/scanner_test.go +++ b/scanner/scanner_test.go @@ -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 := ` 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 := ` 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()) } } diff --git a/visitor/dumper_test.go b/visitor/dumper_test.go index 1c2d9e0..73ac034 100644 --- a/visitor/dumper_test.go +++ b/visitor/dumper_test.go @@ -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} diff --git a/visitor/go_dumper_test.go b/visitor/go_dumper_test.go index ef0fb63..c2c012d 100644 --- a/visitor/go_dumper_test.go +++ b/visitor/go_dumper_test.go @@ -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", + // }, + // }, + // }, + // }, + // }, + // }, + // }, + // }, + // }, + // }, + // }, + // } } diff --git a/visitor/json_dumper.go b/visitor/json_dumper.go index f0e1934..cafe3b3 100644 --- a/visitor/json_dumper.go +++ b/visitor/json_dumper.go @@ -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()) } } diff --git a/visitor/json_dumper_test.go b/visitor/json_dumper_test.go index b99f8ac..b3baebc 100644 --- a/visitor/json_dumper_test.go +++ b/visitor/json_dumper_test.go @@ -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"}}}]}}]}]}]} } diff --git a/visitor/namespace_resolver.go b/visitor/namespace_resolver.go index c4d47fc..f8b0ea1 100644 --- a/visitor/namespace_resolver.go +++ b/visitor/namespace_resolver.go @@ -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 diff --git a/visitor/pretty_json_dumper.go b/visitor/pretty_json_dumper.go index 9b5b04b..63d5007 100644 --- a/visitor/pretty_json_dumper.go +++ b/visitor/pretty_json_dumper.go @@ -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, "}") diff --git a/visitor/pretty_json_dumper_test.go b/visitor/pretty_json_dumper_test.go index 92d753d..16a1e22 100644 --- a/visitor/pretty_json_dumper_test.go +++ b/visitor/pretty_json_dumper_test.go @@ -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"