php

package module
v0.0.0-...-952fa56 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2015 License: BSD-3-Clause Imports: 7 Imported by: 0

README

php

Parser for PHP written in Go

Project Status

This project is under heavy development, though some pieces are more or less stable. Listed here are components that in progress or are ideas for future development

Feature Status
Lexer and Parser mostly complete. there are probably a few gaps still
Scoping complete for simple cases. probably some gaps still, most notably that conditional definitions are treated as if they are always defined
Code search and symbol lookup basic idea implemented, many many details missing
Code formatting basic idea implemented, formatting needs to narrow down to PSR-2
Transpilation to Go basic idea implemented, need follow through with more node types
Type inferencing not begun
Dead code analysis basic idea implemented, but only for some types of code. Also, this suffers from the same caveats as scoping

Project Components

Directory Description
php the core parser
php/ast (abstract syntax tree) describes the nodes in PHP as parsed by the parser
php/ast/printer prints an ast back to source code
php/cmd a tool used to debug the parser
php/lexer reads a stream of tokens from source code
php/passes tools and packages related to modifying or analyzing PHP code (heavily a work in progress)
php/passes/togo transpiler
php/passes/deadcode dead code analyzer
php/query tools and packages related to analyzing and finding things in PHP code (heavily a work in progress)
php/testdata simple examples of PHP that must parse with no errors for tests to pass
php/token describes the tokens read by the lexer

original fork: https://github.com/stephens2424/php

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fuzz

func Fuzz(data []byte) int

Types

type ParseError

type ParseError struct {
	Line, Column int
	File         *ast.File
	// contains filtered or unexported fields
}

ParseError represents an error found during parsing.

func (ParseError) Error

func (p ParseError) Error() string

func (ParseError) String

func (p ParseError) String() string

type ParseErrorList

type ParseErrorList []ParseError

ParseErrorList is a list of ParseErrors.

func (ParseErrorList) Error

func (p ParseErrorList) Error() string

Error formats p into a string.

type Parser

type Parser struct {
	Debug       bool // Debug causes the parser to print all errors to stdout and relay any panic upon internal panic recovery.
	PrintTokens bool // PrintTokens causes the parser to print all tokens received from the lexer to stdout.
	MaxErrors   int  // Indicates the number of errors to allow before triggering a panic. The default is 10.
	FileSet     *ast.FileSet
	// contains filtered or unexported fields
}

Parser handles scanning through and parsing a PHP source string into an AST. It is configurable to have various types of debugging features.

func NewParser

func NewParser() *Parser

NewParser readies a parser

func (*Parser) Parse

func (p *Parser) Parse(filepath, input string) (file *ast.File, err error)

Parse consumes the input string to produce an AST that represents it.

Directories

Path Synopsis
ast
cmd
fmt
Lexer transforms an input string into a stream of PHP tokens.
Lexer transforms an input string into a stream of PHP tokens.
passes
Package query implements CSS/jQuery-esque selectors over a PHP AST Currently, the only supported selectors are: "node", where node is the type name of an AST node (e.g.
Package query implements CSS/jQuery-esque selectors over a PHP AST Currently, the only supported selectors are: "node", where node is the type name of an AST node (e.g.
cmd/query
Command query implements a simple CLI for querying a PHP AST.
Command query implements a simple CLI for querying a PHP AST.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL