dump comment anchor

This commit is contained in:
z7zmey 2018-05-27 22:37:22 +03:00
parent 6b70d665d4
commit be3bdbfdc0
3 changed files with 163 additions and 2 deletions

View File

@ -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",
}

View File

@ -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()])
}
}
}

View File

@ -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};