GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - rectorphp/php-parser-in-go

BranchesTags
Open more actions menu

Latest commit

 

History

14 Commits
14 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
benchmark
benchmark
 
 
internal
internal
 
 
pkg
pkg
 
 
.gitignore
.gitignore
 
 
.golangci.yml
.golangci.yml
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 

Repository files navigation

php-parser-in-go

A PHP parser written in Go. It lexes and parses PHP 5, 7 and 8 source into an AST that downstream tools (linters, refactoring, metrics, formatters) can traverse.

Install

go get github.com/rectorphp/php-parser-in-go

Usage

package main

import (
	"fmt"

	"github.com/rectorphp/php-parser-in-go/pkg/conf"
	"github.com/rectorphp/php-parser-in-go/pkg/parser"
	"github.com/rectorphp/php-parser-in-go/pkg/version"
	"github.com/rectorphp/php-parser-in-go/pkg/visitor/dumper"
)

func main() {
	phpVersion, _ := version.New("8.3")

	root, err := parser.Parse([]byte("<?php echo 'hi';"), conf.Config{
		Version: phpVersion,
	})
	if err != nil {
		panic(err)
	}

	// walk / print / dump the AST
	fmt.Print(dumper.Dump(root))
}

Packages

  • pkg/parser — parser.Parse(source, conf.Config{...}) entry point.
  • pkg/ast — AST node definitions.
  • pkg/visitor — traverser, printer, dumper, namespace and class resolvers, formatter.
  • pkg/token, pkg/position, pkg/version, pkg/errors, pkg/conf.

Benchmark

benchmark/ parses every .php file under a directory and reports the wall-clock time. Point it at any corpus:

make bench-corpus DIR=./laravel
# parsed 2966 files in 1215 ms

CI runs it against a full Laravel framework checkout (src/ + Composer vendor/) on every push and every 12 hours, reporting the average over 5 runs and peak memory in the run's Summary.

Generated code

internal/*/php*.go and internal/*/scanner.go are generated. Edit the grammar source instead:

  • *.y files are regenerated with goyacc.
  • *.rl files are regenerated with ragel.

Run make build to regenerate and build (both goyacc and ragel must be installed). make test runs the tests.

Credits

Based on z7zmey/php-parser, the original PHP parser written in Go.

About

No description, website, or topics provided.

Resources

Readme
MIT license
Activity
Custom properties

Stars

3 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.