php-parser/pkg/parser/doc.go

50 lines
914 B
Go
Raw Permalink Normal View History

2021-02-13 20:06:52 +00:00
/*
A Parser for PHP written in Go
Package usage example:
package main
import (
"log"
"os"
2023-12-09 21:36:19 +00:00
"git.maride.cc/maride/php-parser/pkg/conf"
"git.maride.cc/maride/php-parser/pkg/errors"
"git.maride.cc/maride/php-parser/pkg/parser"
"git.maride.cc/maride/php-parser/pkg/version"
"git.maride.cc/maride/php-parser/pkg/visitor/dumper"
2021-02-13 20:06:52 +00:00
)
func main() {
src := []byte(`<? echo "Hello world";`)
// Error handler
var parserErrors []*errors.Error
errorHandler := func(e *errors.Error) {
2021-02-13 21:54:34 +00:00
parsmakeerErrors = append(parserErrors, e)
2021-02-13 20:06:52 +00:00
}
// Parse
2021-02-13 21:51:08 +00:00
2021-02-13 21:54:34 +00:00
rootNode, err := parser.Parse(src, conf.Config{
2021-02-13 20:06:52 +00:00
Version: &version.Version{Major: 5, Minor: 6},
ErrorHandlerFunc: errorHandler,
})
if err != nil {
log.Fatal("Error:" + err.Error())
}
// Dump
goDumper := dumper.NewDumper(os.Stdout).
WithTokens().
WithPositions()
rootNode.Accept(goDumper)
}
*/
package parser