2018-02-20 17:20:32 +00:00
|
|
|
/*
|
|
|
|
|
2018-02-20 17:33:03 +00:00
|
|
|
A Parser for PHP written in Go
|
|
|
|
|
|
|
|
Features:
|
2018-02-20 17:20:32 +00:00
|
|
|
|
2018-02-20 17:37:42 +00:00
|
|
|
* Fully support PHP5 and PHP7 syntax
|
|
|
|
* Abstract syntax tree representation
|
|
|
|
* Traversing AST
|
2018-04-10 12:51:00 +00:00
|
|
|
* Namespace resolver
|
2018-02-20 17:36:44 +00:00
|
|
|
|
2018-02-20 17:37:42 +00:00
|
|
|
Install:
|
2018-02-20 17:20:32 +00:00
|
|
|
|
|
|
|
go get github.com/z7zmey/php-parser
|
|
|
|
|
2018-02-20 17:37:42 +00:00
|
|
|
CLI dumper:
|
2018-02-20 17:33:03 +00:00
|
|
|
|
|
|
|
$GOPATH/bin/php-parser -php5 /path/to/file/or/dir
|
|
|
|
|
2018-02-20 17:37:42 +00:00
|
|
|
Package usage example:
|
2018-02-20 17:20:32 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-04-10 12:51:00 +00:00
|
|
|
"fmt"
|
2018-02-20 17:20:32 +00:00
|
|
|
"bytes"
|
2018-04-10 12:51:00 +00:00
|
|
|
"os"
|
2018-02-20 17:20:32 +00:00
|
|
|
|
|
|
|
"github.com/z7zmey/php-parser/php7"
|
|
|
|
"github.com/z7zmey/php-parser/visitor"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
src := bytes.NewBufferString(`<? echo "Hello world";`)
|
2018-04-10 12:51:00 +00:00
|
|
|
|
|
|
|
parser := php7.NewParser(src, "example.php")
|
|
|
|
parser.Parse()
|
|
|
|
|
|
|
|
for _, e := range parser.GetErrors() {
|
|
|
|
fmt.Println(e)
|
|
|
|
}
|
2018-02-20 17:20:32 +00:00
|
|
|
|
|
|
|
visitor := visitor.Dumper{
|
2018-04-10 12:51:00 +00:00
|
|
|
Writer: os.Stdout,
|
2018-02-20 17:20:32 +00:00
|
|
|
Indent: "",
|
2018-04-10 12:51:00 +00:00
|
|
|
Comments: parser.GetComments(),
|
|
|
|
Positions: parser.GetPositions(),
|
2018-02-20 17:20:32 +00:00
|
|
|
}
|
2018-04-10 12:51:00 +00:00
|
|
|
|
|
|
|
rootNode := parser.GetRootNode()
|
|
|
|
rootNode.Walk(visitor)
|
2018-02-20 17:20:32 +00:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
package main // import "github.com/z7zmey/php-parser"
|