GithubHelp home page GithubHelp logo

siathalysedi / php-parser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from z7zmey/php-parser

0.0 3.0 0.0 6.15 MB

A Parser for PHP written in Go

License: MIT License

Makefile 0.04% Go 79.31% Yacc 18.57% Lex 2.09%

php-parser's Introduction

PHP-Parser

Go Report Card Exago Exago GoDoc

A Parser for PHP written in Go inspired by Nikic PHP Parser

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

php-parser's People

Contributors

z7zmey avatar

Watchers

Arnstein Henriksen avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.