From be3bdbfdc08324e8c3f93ae145461f94870877dc Mon Sep 17 00:00:00 2001 From: z7zmey Date: Sun, 27 May 2018 22:37:22 +0300 Subject: [PATCH] dump comment anchor --- comment/tokenNames.go | 160 +++++++++++++++++++++++++++++++++++++++++ visitor/dumper.go | 3 +- visitor/dumper_test.go | 2 +- 3 files changed, 163 insertions(+), 2 deletions(-) diff --git a/comment/tokenNames.go b/comment/tokenNames.go index 70175f3..cff630f 100644 --- a/comment/tokenNames.go +++ b/comment/tokenNames.go @@ -162,3 +162,163 @@ const ( 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", + 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/visitor/dumper.go b/visitor/dumper.go index 6930f1b..0cf56e1 100644 --- a/visitor/dumper.go +++ b/visitor/dumper.go @@ -6,6 +6,7 @@ import ( "io" "reflect" + "github.com/z7zmey/php-parser/comment" "github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/parser" @@ -44,7 +45,7 @@ func (d Dumper) EnterNode(w walker.Walkable) bool { if c := d.Comments[n]; len(c) > 0 { fmt.Fprintf(d.Writer, "%v\"Comments\":\n", d.Indent+" ") for _, cc := range c { - fmt.Fprintf(d.Writer, "%v%q\n", d.Indent+" ", cc) + fmt.Fprintf(d.Writer, "%v%q before %q\n", d.Indent+" ", cc, comment.TokenNames[cc.TokenName()]) } } } diff --git a/visitor/dumper_test.go b/visitor/dumper_test.go index f6bad0f..cb3094c 100644 --- a/visitor/dumper_test.go +++ b/visitor/dumper_test.go @@ -111,7 +111,7 @@ func ExampleDumper() { //| [*expr.Variable] //| "Position": Pos{Line: 8-8 Pos: 124-127}; //| "Comments": - //| "// some comment\n" + //| "// some comment\n" before "VariableToken" //| "VarName": //| [*node.Identifier] //| "Position": Pos{Line: 8-8 Pos: 124-127};