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, traits, etc.). `extends` on a class is an exception in one direction only: it is parsed and recorded on the AST so files carrying it lint and reformat, but nothing downstream inherits. `interface` declarations and a class's `implements` list are parsed and checked as a contract, which also inherits nothing: see model.CheckInterfaces.
Index ¶
Constants ¶
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 // ^= // String interpolation. A double-quoted literal that embeds an expression is // reported as its pieces, and these are the ids that mark them. T_ENCAPSED_AND_WHITESPACE // a literal run between two embedded expressions T_CURLY_OPEN // the `{` of a {$...} T_NUM_STRING // digits used as an array key inside a literal )
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 TokenGetAll ¶
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 TokenIDs ¶ added in v0.3.4
TokenIDs returns every token name with the id token_get_all reports for it, which is what a host registers as PHP constants. A script comparing a token against a name it did not get from here would be comparing against nothing, so the table that names the ids is the table that publishes them.
Types ¶
This section is empty.