create token name constants in comment package

This commit is contained in:
z7zmey 2018-05-27 22:15:27 +03:00
parent e396f81eea
commit b383fe98fe
8 changed files with 2217 additions and 2000 deletions

View File

@ -6,8 +6,9 @@ import (
// Comment aggrigates information about comment /**
type Comment struct {
value string
position *position.Position
value string
position *position.Position
tokenName TokenName
}
// NewComment - Comment constructor
@ -15,9 +16,20 @@ func NewComment(value string, pos *position.Position) *Comment {
return &Comment{
value,
pos,
UnknownToken,
}
}
// SetTokenName sets token name
func (c *Comment) SetTokenName(tokenName TokenName) {
c.tokenName = tokenName
}
// TokenName returns token name
func (c *Comment) TokenName() TokenName {
return c.tokenName
}
func (c *Comment) String() string {
return c.value
}

176
comment/tokenNames.go Normal file
View File

@ -0,0 +1,176 @@
package comment
// 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
CharacterToken
BadCharacterToken
EncapsedAndWhitespaceToken
ConstantEncapsedStringToken
EchoToken
DoToken
WhileToken
EndwhileToken
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
HalcompilerToken
ClassToken
TraitToken
InterfaceToken
ExtendsToken
ImplementsToken
ObjecoperatorToken
DoubleArrowToken
ListToken
ArrayToken
CallableToken
ClassCToken
TraitCToken
MethodCToken
FuncCToken
LineToken
FileToken
CommentToken
DocCommentToken
OpenTagToken
OpenTagWithEchoToken
CloseTagToken
WhitespaceToken
StartHeredocToken
EndHeredocToken
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
NoelseToken
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 // '.'
)

View File

@ -3,6 +3,7 @@ package parser
import (
"github.com/z7zmey/php-parser/comment"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/scanner"
)
// Comments a collection of comment groups assigned to nodes
@ -12,3 +13,18 @@ type Comments map[node.Node][]*comment.Comment
func (c Comments) AddComments(node node.Node, comments []*comment.Comment) {
c[node] = append(c[node], comments...)
}
func (c Comments) AddFromToken(node node.Node, token *scanner.Token, tokenName comment.TokenName) {
comments := token.Comments()
for _, cmt := range comments {
cmt.SetTokenName(tokenName)
}
c.AddComments(node, comments)
}
func (c Comments) AddFromChildNode(n node.Node, ch node.Node) {
c.AddComments(n, c[ch])
delete(c, ch)
}

File diff suppressed because it is too large Load Diff

View File

@ -193,6 +193,7 @@ import (
%token <token> '%'
%token <token> '<'
%token <token> '>'
%token <token> '.'
%left T_INCLUDE T_INCLUDE_ONCE T_EVAL T_REQUIRE T_REQUIRE_ONCE
%left ','

View File

@ -96,7 +96,6 @@ func (l *Parser) GetPositions() parser.Positions {
return l.positions
}
// GetPositions returns positions list
func (l *Parser) setCommentsFromChildNode(n node.Node, c node.Node) {
l.comments.AddComments(n, l.comments[c])
delete(l.comments, c)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff