z7zmey / php-parser

PHP parser written in Go

Home Page:https://php-parser.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix usage example in README

whisk opened this issue · comments

commented

Usage example in README.md is broken and outputs compile error:

./go_parser.go:25:11: unknown field 'Comments' in struct literal of type visitor.Dumper
./go_parser.go:26:12: unknown field 'Positions' in struct literal of type visitor.Dumper
./go_parser.go:30:15: cannot use visitor (type visitor.Dumper) as type walker.Visitor in argument to rootNode.Walk:
	visitor.Dumper does not implement walker.Visitor (EnterChildList method has pointer receiver)

Working example should be like:

package main

import (
	"bytes"
	"fmt"
	"os"

	"github.com/z7zmey/php-parser/php7"
	"github.com/z7zmey/php-parser/visitor"
)

func main() {
	src := bytes.NewBufferString(`<? echo "Hello world";`)

	parser := php7.NewParser(src, "example.php")
	parser.Parse()

	for _, e := range parser.GetErrors() {
		fmt.Println(e)
	}

	visitor := visitor.Dumper{
		Writer: os.Stdout,
		Indent: "",
	}

	rootNode := parser.GetRootNode()
	rootNode.Walk(&visitor)
}