#33 comment package has renamed to meta and parser now saves whitespaces
This commit is contained in:
@@ -3,8 +3,8 @@ package php5
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/z7zmey/php-parser/comment"
|
||||
"github.com/z7zmey/php-parser/errors"
|
||||
"github.com/z7zmey/php-parser/meta"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/parser"
|
||||
"github.com/z7zmey/php-parser/scanner"
|
||||
@@ -22,7 +22,6 @@ type Parser struct {
|
||||
positionBuilder *parser.PositionBuilder
|
||||
errors []*errors.Error
|
||||
rootNode node.Node
|
||||
comments parser.Comments
|
||||
}
|
||||
|
||||
// NewParser creates and returns new Parser
|
||||
@@ -36,7 +35,6 @@ func NewParser(src io.Reader, path string) *Parser {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,12 +49,15 @@ func (l *Parser) Error(msg string) {
|
||||
l.errors = append(l.errors, errors.NewError(msg, l.currentToken))
|
||||
}
|
||||
|
||||
func (l *Parser) WithMeta() {
|
||||
l.Lexer.WithMeta = true
|
||||
}
|
||||
|
||||
// Parse the php7 Parser entrypoint
|
||||
func (l *Parser) Parse() int {
|
||||
// init
|
||||
l.errors = nil
|
||||
l.rootNode = nil
|
||||
l.comments = parser.Comments{}
|
||||
l.positionBuilder = &parser.PositionBuilder{}
|
||||
|
||||
// parse
|
||||
@@ -64,14 +65,14 @@ func (l *Parser) Parse() int {
|
||||
return yyParse(l)
|
||||
}
|
||||
|
||||
func (l *Parser) listGetFirstNodeComments(list []node.Node) []*comment.Comment {
|
||||
func (l *Parser) listGetFirstNodeMeta(list []node.Node) []meta.Meta {
|
||||
if len(list) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
node := list[0]
|
||||
|
||||
return l.comments[node]
|
||||
return node.GetMeta()
|
||||
}
|
||||
|
||||
// GetPath return path to file
|
||||
@@ -89,11 +90,6 @@ func (l *Parser) GetErrors() []*errors.Error {
|
||||
return l.errors
|
||||
}
|
||||
|
||||
// GetComments returns comments list
|
||||
func (l *Parser) GetComments() parser.Comments {
|
||||
return l.comments
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
func lastNode(nn []node.Node) node.Node {
|
||||
@@ -111,6 +107,14 @@ func isDollar(r rune) bool {
|
||||
return r == '$'
|
||||
}
|
||||
|
||||
func addMeta(n node.Node, mm []meta.Meta, tn meta.TokenName) {
|
||||
for _, m := range mm {
|
||||
m.SetTokenName(tn)
|
||||
}
|
||||
|
||||
n.AddMeta(mm)
|
||||
}
|
||||
|
||||
func (p *Parser) returnTokenToPool(yyDollar []yySymType, yyVAL *yySymType) {
|
||||
for i := 1; i < len(yyDollar); i++ {
|
||||
if yyDollar[i].token != nil {
|
||||
|
||||
1628
php5/php5.go
1628
php5/php5.go
File diff suppressed because it is too large
Load Diff
1176
php5/php5.y
1176
php5/php5.y
File diff suppressed because it is too large
Load Diff
12716
php5/php5_test.go
12716
php5/php5_test.go
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user