php-parser/php7/parser.go

61 lines
1.2 KiB
Go
Raw Normal View History

2018-02-20 18:22:15 +00:00
// Package php7 parses PHP7
2018-01-26 13:24:56 +00:00
package php7
import (
"io"
"github.com/z7zmey/php-parser/comment"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/token"
)
var rootnode node.Node
var comments comment.Comments
var positions position.Positions
var positionBuilder position.Builder
// Parse the php7 parser entrypoint
2018-01-26 13:24:56 +00:00
func Parse(src io.Reader, fName string) (node.Node, comment.Comments, position.Positions) {
2018-02-06 10:39:42 +00:00
yyDebug = 0
yyErrorVerbose = true
rootnode = stmt.NewStmtList([]node.Node{}) //reset
comments = comment.Comments{}
positions = position.Positions{}
positionBuilder = position.Builder{&positions}
yyParse(newLexer(src, fName))
return rootnode, comments, positions
2018-01-26 13:24:56 +00:00
}
// ListGetFirstNodeComments returns comments of a first node in the list
2018-01-26 13:24:56 +00:00
func ListGetFirstNodeComments(list []node.Node) []comment.Comment {
if len(list) == 0 {
return nil
}
node := list[0]
return comments[node]
}
type foreachVariable struct {
2018-02-06 10:39:42 +00:00
node node.Node
byRef bool
2018-01-26 13:24:56 +00:00
}
type nodesWithEndToken struct {
2018-02-06 10:39:42 +00:00
nodes []node.Node
endToken token.Token
2018-01-26 13:24:56 +00:00
}
type boolWithToken struct {
2018-02-06 10:39:42 +00:00
value bool
token *token.Token
}
2018-02-18 17:44:17 +00:00
type altSyntaxNode struct {
node node.Node
isAlt bool
}