php-parser/php5/parser.go

69 lines
1.4 KiB
Go
Raw Normal View History

2018-01-26 13:24:56 +00:00
package php5
import (
"io"
2018-02-04 16:51:44 +00:00
"github.com/z7zmey/php-parser/node/expr"
2018-01-26 13:24:56 +00:00
"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
2018-02-04 16:51:44 +00:00
var parentNode node.Node
// Parse the php5 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-04 16:51:44 +00:00
yyDebug = 0
yyErrorVerbose = true
rootnode = stmt.NewStmtList([]node.Node{}) //reset
comments = comment.Comments{}
positions = position.Positions{}
positionBuilder = position.Builder{Positions: &positions}
2018-02-04 16:51:44 +00:00
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-04 16:51:44 +00:00
node node.Node
byRef bool
2018-01-26 13:24:56 +00:00
}
type nodesWithEndToken struct {
2018-02-04 16:51:44 +00:00
nodes []node.Node
endToken token.Token
2018-01-26 13:24:56 +00:00
}
type boolWithToken struct {
2018-02-04 16:51:44 +00:00
value bool
token *token.Token
2018-01-29 19:12:12 +00:00
}
type simpleIndirectReference struct {
2018-02-04 16:51:44 +00:00
all []*expr.Variable
last *expr.Variable
2018-02-01 14:07:18 +00:00
}
2018-02-18 17:44:17 +00:00
type altSyntaxNode struct {
node node.Node
isAlt bool
}