Repository navigation
Releases
Releases · phpsyntax/phpsyntax
Released version 1.0.1
- New Indentation::opensMatchArm() – tells whether a token begins an arm of
match, the companion ofopensStatement()for a tool deciding how deep a continuation line goes. - Indentation::infer() places a line continuing an expression that begins an arm of
matchone level deeper than the arm, so an operator such as|| $bstands apart from the next arm.
Released version 1.0.0 🎉
The first release of PhpSyntax, a lossless concrete syntax tree for PHP. Every token, space and comment of the source is in the tree, and printing it gives the file back byte for byte, so a tool that changes one thing produces a diff with one thing in it. It is built for coding-standard fixers, codemods and upgrade tools, and DressCode already runs on it.
- Lossless round trip –
Printer::print($file) === $codefor any input PHP accepts, BOM, CRLF,?>with HTML after it, heredocs and__halt_compiler()data included; whitespace and comments live as trivia on the token they belong to - A typed tree with named slots –
$if->condition,$if->body,$call->arguments; every token,(and;included, is a child, and lists are nodes of their own - Edits that leave the rest of the file alone – write a slot by assignment,
replaceWith(),remove()orinsert()into a list; a list clones its separator style and its neighbor's indentation, a removed line takes its comment and separator with it, andreplaceWithExpression()adds the parentheses only where precedence needs them - Builder – make nodes from text (
expression(),statement(),type(),fragment()), from templates with named placeholders, or from nodes and values you already hold (methodCall(),binary(),value()) - Questions a rewrite needs answered –
matches(),isRepeatableRead(),hasInnerComment(),isRedundant()on parentheses,alwaysLeaves(),toValue()and more, so the safety checks of a fixer are method calls, not heuristics - Positions that follow your edits – lines, columns and offsets kept up to date incrementally, so the read–change–read loop of a fixer stays linear;
findNode()maps an editor position back to a node - Name resolution and imports –
NameResolverresolves names against namespace and imports,shortenName()writes a name the way this file would,addImport()adds ausein the style the statement already has;Scopetells where$thisis available - Modern syntax on every supported runtime – reads PHP 8.5 syntax plus the partial function application of PHP 8.6 on PHP 8.4 to 8.6, through token emulation on older runtimes
- bin/phpsyntax –
checkthe round trip over your own project,dumpthe tree of a file or an expression, list itstokens,resolveits names,finda node class - No package dependencies – just PHP 8.4+ and
ext-tokenizer, so it never brings version constraints into the projects your tool runs in
Coming from nikic/php-parser? The migration guide maps one onto the other, and the examples show each idea as a runnable script.