#33 comment package has renamed to meta and parser now saves whitespaces

This commit is contained in:
z7zmey
2018-06-30 00:51:11 +03:00
parent 36d0cf4823
commit e90df8ef5f
205 changed files with 16485 additions and 16302 deletions

View File

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff