Merge branch 'comments3'

This commit is contained in:
z7zmey
2018-06-07 15:06:54 +03:00
138 changed files with 17339 additions and 10027 deletions

View File

@@ -8,9 +8,10 @@ import (
"io"
"unicode"
"github.com/z7zmey/php-parser/position"
"github.com/cznic/golex/lex"
"github.com/z7zmey/php-parser/comment"
t "github.com/z7zmey/php-parser/token"
)
// Allocate Character classes anywhere in [0x80, 0xFF].
@@ -369,32 +370,32 @@ const T_MINUS_EQUAL = 57460
// T_MUL_EQUAL token
const T_MUL_EQUAL = 57461
// T_POW_EQUAL token
const T_POW_EQUAL = 57462
// T_DIV_EQUAL token
const T_DIV_EQUAL = 57462
const T_DIV_EQUAL = 57463
// T_CONCAT_EQUAL token
const T_CONCAT_EQUAL = 57463
const T_CONCAT_EQUAL = 57464
// T_MOD_EQUAL token
const T_MOD_EQUAL = 57464
const T_MOD_EQUAL = 57465
// T_AND_EQUAL token
const T_AND_EQUAL = 57465
const T_AND_EQUAL = 57466
// T_OR_EQUAL token
const T_OR_EQUAL = 57466
const T_OR_EQUAL = 57467
// T_XOR_EQUAL token
const T_XOR_EQUAL = 57467
const T_XOR_EQUAL = 57468
// T_SL_EQUAL token
const T_SL_EQUAL = 57468
const T_SL_EQUAL = 57469
// T_SR_EQUAL token
const T_SR_EQUAL = 57469
// T_POW_EQUAL token
const T_POW_EQUAL = 57470
const T_SR_EQUAL = 57470
// T_BOOLEAN_OR token
const T_BOOLEAN_OR = 57471
@@ -402,36 +403,36 @@ const T_BOOLEAN_OR = 57471
// T_BOOLEAN_AND token
const T_BOOLEAN_AND = 57472
// T_IS_EQUAL token
const T_IS_EQUAL = 57473
// T_IS_NOT_EQUAL token
const T_IS_NOT_EQUAL = 57474
// T_IS_IDENTICAL token
const T_IS_IDENTICAL = 57475
// T_IS_NOT_IDENTICAL token
const T_IS_NOT_IDENTICAL = 57476
// T_IS_SMALLER_OR_EQUAL token
const T_IS_SMALLER_OR_EQUAL = 57477
// T_IS_GREATER_OR_EQUAL token
const T_IS_GREATER_OR_EQUAL = 57478
// T_POW token
const T_POW = 57473
// T_SL token
const T_SL = 57479
const T_SL = 57474
// T_SR token
const T_SR = 57480
const T_SR = 57475
// T_POW token
const T_POW = 57481
// T_IS_IDENTICAL token
const T_IS_IDENTICAL = 57476
// T_IS_NOT_IDENTICAL token
const T_IS_NOT_IDENTICAL = 57477
// T_IS_EQUAL token
const T_IS_EQUAL = 57478
// T_IS_NOT_EQUAL token
const T_IS_NOT_EQUAL = 57479
// T_IS_SMALLER_OR_EQUAL token
const T_IS_SMALLER_OR_EQUAL = 57480
// T_IS_GREATER_OR_EQUAL token
const T_IS_GREATER_OR_EQUAL = 57481
// Lval parsers yySymType must implement this interface
type Lval interface {
Token(tkn t.Token)
Token(tkn *Token)
}
// Lexer php lexer
@@ -439,7 +440,7 @@ type Lexer struct {
*lex.Lexer
StateStack []int
PhpDocComment string
Comments []comment.Comment
Comments []*comment.Comment
heredocLabel string
tokenBytesBuf *bytes.Buffer
}
@@ -511,19 +512,32 @@ func (l *Lexer) getCurrentState() int {
return l.StateStack[len(l.StateStack)-1]
}
func (l *Lexer) newToken(chars []lex.Char) t.Token {
func (l *Lexer) createToken(chars []lex.Char) *Token {
firstChar := chars[0]
lastChar := chars[len(chars)-1]
startLine := l.File.Line(firstChar.Pos())
endLine := l.File.Line(lastChar.Pos())
startPos := int(firstChar.Pos())
endPos := int(lastChar.Pos())
pos := position.NewPosition(
l.File.Line(firstChar.Pos()),
l.File.Line(lastChar.Pos()),
int(firstChar.Pos()),
int(lastChar.Pos()),
)
return t.NewToken(l.tokenString(chars), startLine, endLine, startPos, endPos).SetComments(l.Comments)
return NewToken(l.tokenString(chars), pos).SetComments(l.Comments)
}
func (l *Lexer) addComment(c comment.Comment) {
func (l *Lexer) addComment(chars []lex.Char) {
firstChar := chars[0]
lastChar := chars[len(chars)-1]
pos := position.NewPosition(
l.File.Line(firstChar.Pos()),
l.File.Line(lastChar.Pos()),
int(firstChar.Pos()),
int(lastChar.Pos()),
)
c := comment.NewComment(l.tokenString(chars), pos)
l.Comments = append(l.Comments, c)
}