add comment struct

This commit is contained in:
z7zmey
2018-01-03 00:12:28 +02:00
parent bbf9b0cc09
commit e8655c5f4c
6 changed files with 44 additions and 1 deletions

View File

@@ -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 {

View File

@@ -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

View File

@@ -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
}