parser

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package parser turns PHP source (the limited subset described in the project README) into the shared model AST consumed by the runner.

Scope of v0: the parser targets the README's "desired syntax" subset: php tags, $-variables, echo, assignment, if/elseif/else, foreach, for, while, function and class declarations, the `function Class::method()` form, method and property access via both `->` and `.`, array/new expressions, and the usual operators. It intentionally does not implement the full PHP grammar (see the README "omissions" list: inheritance, interfaces, traits, etc.). `extends` and `implements` are an exception in one direction only: they are parsed and recorded on the AST so files carrying them lint and reformat, but nothing downstream inherits.

Index

Constants

View Source
const (
	T_INLINE_HTML = 256 + iota
	T_OPEN_TAG
	T_CLOSE_TAG
	T_WHITESPACE
	T_COMMENT
	T_VARIABLE
	T_STRING // bare identifier / constant name / function name
	T_LNUMBER
	T_DNUMBER
	T_CONSTANT_ENCAPSED_STRING
	T_OBJECT_OPERATOR // ->
	T_DOUBLE_ARROW    // =>
	T_DOUBLE_COLON    // :: (a.k.a. T_PAAMAYIM_NEKUDOTAYIM)
	T_IS_EQUAL        // ==
	T_IS_NOT_EQUAL    // !=
	T_IS_IDENTICAL    // ===
	T_IS_NOT_IDENTICAL
	T_IS_SMALLER_OR_EQUAL
	T_IS_GREATER_OR_EQUAL
	T_BOOLEAN_AND // &&
	T_BOOLEAN_OR  // ||
	T_INC         // ++
	T_DEC         // --
	T_PLUS_EQUAL
	T_MINUS_EQUAL
	T_MUL_EQUAL
	T_DIV_EQUAL
	T_MOD_EQUAL
	T_CONCAT_EQUAL // .=
	// keywords
	T_IF
	T_ELSE
	T_ELSEIF
	T_FOREACH
	T_FOR
	T_WHILE
	T_AS
	T_FUNCTION
	T_RETURN
	T_NEW
	T_ECHO
	T_ARRAY
	T_CLASS
	T_VAR
	T_INCLUDE
	T_INCLUDE_ONCE
	T_REQUIRE
	T_REQUIRE_ONCE
	T_POW       // **
	T_POW_EQUAL // **=
	T_SL        // <<
	T_SR        // >>
	T_SL_EQUAL  // <<=
	T_SR_EQUAL  // >>=
	T_AND_EQUAL // &=
	T_OR_EQUAL  // |=
	T_XOR_EQUAL // ^=
)

T_* token identifiers. PHP's concrete integer values are version-specific; only self-consistency matters here because callers use token_name() and the named constants. We start at 256 like PHP (single-char tokens are < 256).

Variables

This section is empty.

Functions

func Parse

func Parse(src string) (*model.Program, error)

Parse compiles PHP source into a model.Program.

func TokenGetAll

func TokenGetAll(src string) []any

TokenGetAll tokenizes src the way PHP's token_get_all does, returning a []any of single-char strings and []any{id, text, line} triples.

func TokenName

func TokenName(id int) string

TokenName returns the PHP name for a token id (PHP's token_name). Unknown ids yield "UNKNOWN", matching PHP.

Types

This section is empty.

Jump to

Keyboard shortcuts

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