add comment struct
This commit is contained in:
parent
bbf9b0cc09
commit
e8655c5f4c
5
comment/comment.go
Normal file
5
comment/comment.go
Normal file
@ -0,0 +1,5 @@
|
||||
package comment
|
||||
|
||||
type Comment interface {
|
||||
String() string
|
||||
}
|
15
comment/doc_comment.go
Normal file
15
comment/doc_comment.go
Normal file
@ -0,0 +1,15 @@
|
||||
package comment
|
||||
|
||||
type DocComment struct {
|
||||
value string
|
||||
}
|
||||
|
||||
func NewDocComment(value string) Comment {
|
||||
return &DocComment{
|
||||
value,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *DocComment) String() string {
|
||||
return c.value
|
||||
}
|
15
comment/plain_comment.go
Normal file
15
comment/plain_comment.go
Normal file
@ -0,0 +1,15 @@
|
||||
package comment
|
||||
|
||||
type PlainComment struct {
|
||||
value string
|
||||
}
|
||||
|
||||
func NewPlainComment(value string) Comment {
|
||||
return &PlainComment{
|
||||
value,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *PlainComment) String() string {
|
||||
return c.value
|
||||
}
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user