issue #8: update readme

This commit is contained in:
z7zmey 2018-04-10 15:51:00 +03:00
parent 6f7834eb6b
commit 71f940fcf2
2 changed files with 28 additions and 9 deletions

View File

@ -31,6 +31,7 @@ go get github.com/z7zmey/php-parser
package main package main
import ( import (
"fmt"
"bytes" "bytes"
"os" "os"
@ -40,17 +41,23 @@ import (
func main() { func main() {
src := bytes.NewBufferString(`<? echo "Hello world";`) src := bytes.NewBufferString(`<? echo "Hello world";`)
nodes, comments, positions, errors := php7.Parse(src, "example.php")
_ = errors parser := php7.NewParser(src, "example.php")
parser.Parse()
for _, e := range parser.GetErrors() {
fmt.Println(e)
}
visitor := visitor.Dumper{ visitor := visitor.Dumper{
Writer: os.Stdout, Writer: os.Stdout,
Indent: "", Indent: "",
Comments: comments, Comments: parser.GetComments(),
Positions: positions, Positions: parser.GetPositions(),
} }
nodes.Walk(visitor)
rootNode := parser.GetRootNode()
rootNode.Walk(visitor)
} }
``` ```

20
doc.go
View File

@ -7,6 +7,7 @@ Features:
* Fully support PHP5 and PHP7 syntax * Fully support PHP5 and PHP7 syntax
* Abstract syntax tree representation * Abstract syntax tree representation
* Traversing AST * Traversing AST
* Namespace resolver
Install: Install:
@ -21,7 +22,9 @@ Package usage example:
package main package main
import ( import (
"fmt"
"bytes" "bytes"
"os"
"github.com/z7zmey/php-parser/php7" "github.com/z7zmey/php-parser/php7"
"github.com/z7zmey/php-parser/visitor" "github.com/z7zmey/php-parser/visitor"
@ -29,14 +32,23 @@ Package usage example:
func main() { func main() {
src := bytes.NewBufferString(`<? echo "Hello world";`) src := bytes.NewBufferString(`<? echo "Hello world";`)
nodes, comments, positions := php7.Parse(src, "example.php")
parser := php7.NewParser(src, "example.php")
parser.Parse()
for _, e := range parser.GetErrors() {
fmt.Println(e)
}
visitor := visitor.Dumper{ visitor := visitor.Dumper{
Writer: os.Stdout,
Indent: "", Indent: "",
Comments: comments, Comments: parser.GetComments(),
Positions: positions, Positions: parser.GetPositions(),
} }
nodes.Walk(visitor)
rootNode := parser.GetRootNode()
rootNode.Walk(visitor)
} }
*/ */
package main // import "github.com/z7zmey/php-parser" package main // import "github.com/z7zmey/php-parser"