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

@ -8,6 +8,7 @@ import (
type Comment struct { type Comment struct {
value string value string
position *position.Position position *position.Position
tokenName TokenName
} }
// NewComment - Comment constructor // NewComment - Comment constructor
@ -15,9 +16,20 @@ func NewComment(value string, pos *position.Position) *Comment {
return &Comment{ return &Comment{
value, value,
pos, 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 { func (c *Comment) String() string {
return c.value 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 ( import (
"github.com/z7zmey/php-parser/comment" "github.com/z7zmey/php-parser/comment"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/scanner"
) )
// Comments a collection of comment groups assigned to nodes // 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) { func (c Comments) AddComments(node node.Node, comments []*comment.Comment) {
c[node] = append(c[node], comments...) 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> '<'
%token <token> '>' %token <token> '>'
%token <token> '.'
%left T_INCLUDE T_INCLUDE_ONCE T_EVAL T_REQUIRE T_REQUIRE_ONCE %left T_INCLUDE T_INCLUDE_ONCE T_EVAL T_REQUIRE T_REQUIRE_ONCE
%left ',' %left ','

View File

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