create token name constants in comment
package
This commit is contained in:
parent
e396f81eea
commit
b383fe98fe
@ -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
176
comment/tokenNames.go
Normal 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 // '.'
|
||||
)
|
@ -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)
|
||||
}
|
||||
|
1032
php5/php5.go
1032
php5/php5.go
File diff suppressed because it is too large
Load Diff
@ -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 ','
|
||||
|
@ -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)
|
||||
|
2004
php7/php7.go
2004
php7/php7.go
File diff suppressed because it is too large
Load Diff
971
php7/php7.y
971
php7/php7.y
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user