add comment struct
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"unicode"
|
||||
|
||||
"github.com/cznic/golex/lex"
|
||||
"github.com/z7zmey/php-parser/comment"
|
||||
)
|
||||
|
||||
// Allocate Character classes anywhere in [0x80, 0xFF].
|
||||
@@ -21,6 +22,7 @@ type lexer struct {
|
||||
stateStack []int
|
||||
lineNumber int
|
||||
phpDocComment string
|
||||
comments []comment.Comment
|
||||
}
|
||||
|
||||
func rune2Class(r rune) int {
|
||||
@@ -43,7 +45,7 @@ func newLexer(src io.Reader, fName string) *lexer {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return &lexer{lx, []int{0}, 1, ""}
|
||||
return &lexer{lx, []int{0}, 1, "", []comment.Comment{}}
|
||||
}
|
||||
|
||||
func (l *lexer) ungetN(n int) []byte {
|
||||
|
||||
@@ -11,6 +11,7 @@ package parser
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/z7zmey/php-parser/comment"
|
||||
"github.com/z7zmey/php-parser/token"
|
||||
)
|
||||
|
||||
@@ -8263,8 +8264,10 @@ yyrule126: // ([/][*])|([/][*][*])
|
||||
lval.token = token.NewToken(l.handleNewLine(l.TokenBytes(nil)))
|
||||
if is_doc_comment {
|
||||
l.phpDocComment = string(l.TokenBytes(nil))
|
||||
l.comments = append(l.comments, comment.NewDocComment(string(l.TokenBytes(nil))))
|
||||
// return T_DOC_COMMENT
|
||||
} else {
|
||||
l.comments = append(l.comments, comment.NewPlainComment(string(l.TokenBytes(nil))))
|
||||
// return T_COMMENT
|
||||
}
|
||||
goto yystate0
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"fmt"
|
||||
"bytes"
|
||||
"github.com/z7zmey/php-parser/token"
|
||||
"github.com/z7zmey/php-parser/comment"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -271,8 +272,10 @@ NEW_LINE (\r|\n|\r\n)
|
||||
lval.token = token.NewToken(l.handleNewLine(l.TokenBytes(nil)))
|
||||
if is_doc_comment {
|
||||
l.phpDocComment = string(l.TokenBytes(nil))
|
||||
l.comments = append(l.comments, comment.NewDocComment(string(l.TokenBytes(nil))))
|
||||
// return T_DOC_COMMENT
|
||||
} else {
|
||||
l.comments = append(l.comments, comment.NewPlainComment(string(l.TokenBytes(nil))))
|
||||
// return T_COMMENT
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user