Go to file
2018-04-02 22:59:55 +03:00
comment add comment tests 2018-01-13 01:58:59 +02:00
node issue #2 - fix single line comment 2018-03-30 17:46:04 +03:00
php5 trim $ from variable name identifier 2018-03-18 16:50:19 +02:00
php7 trim $ from variable name identifier 2018-03-18 16:50:19 +02:00
position positions tests 2018-02-18 13:51:03 +02:00
printer pretty printer: update StmtList printer 2018-04-02 22:59:55 +03:00
scanner remove redundant nop before inline html 2018-04-02 00:02:13 +03:00
token token test 2018-02-18 12:55:32 +02:00
visitor trim $ from variable name identifier 2018-03-18 16:50:19 +02:00
walker update package comments 2018-02-20 20:22:15 +02:00
.gitignore ignore example.php 2018-01-05 13:22:38 +02:00
CODE_OF_CONDUCT.md update CODE_OF_CONDUCT.md 2018-01-05 19:49:29 +02:00
CONTRIBUTING.md create CONTRIBUTING.md 2018-01-05 19:37:08 +02:00
doc.go update doc.go 2018-02-20 19:37:42 +02:00
ISSUE_TEMPLATE.md Create ISSUE_TEMPLATE.md 2018-01-05 19:23:10 +02:00
LICENSE Create LICENSE 2018-01-02 14:37:19 +02:00
main.go dumper visitor write to io.Writer 2018-03-04 13:08:45 +02:00
Makefile update Makefile 2018-02-24 00:19:05 +02:00
parser.jpg add logo 2018-03-04 13:08:45 +02:00
README.md Update README.md 2018-03-04 15:47:41 +02:00

A parser for PHP written in Go

Go Report Card Exago Exago GoDoc

Try it online: demo

Features:

  • Fully support PHP5 and PHP7 syntax
  • Abstract syntax tree representation
  • Traversing AST
  • Namespace resolver

Install

go get github.com/z7zmey/php-parser

Example

package main

import (
	"bytes"

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

func main() {
	src := bytes.NewBufferString(`<? echo "Hello world";`)
	nodes, comments, positions := php7.Parse(src, "example.php")

	visitor := visitor.Dumper{
		Indent:    "",
		Comments:  comments,
		Positions: positions,
	}
	nodes.Walk(visitor)
}

CLI dumper

$GOPATH/bin/php-parser /path/to/file/or/dir

Namespace resolver

Namespace resolver is a visitor that traverses nodes and resolves nodes fully qualified name. It does not change AST but collects resolved names into map[node.Node]string

  • For Class, Interface, Trait, Function, ConstList nodes collects name with current namespace.
  • For Name, Relative, FullyQualified nodes resolves use aliases and collects a fully qualified name.

Roadmap

  • Lexer
  • PHP 7 syntax analyzer
  • AST nodes
  • AST visitor
  • AST dumper
  • node position
  • handling comments
  • PHP 5 syntax analyzer
  • Tests
  • Namespace resolver
  • PhpDocComment parser
  • Error handling
  • Stabilize api
  • Documentation
  • Pretty printer
  • Code flow graph