Skip to content

Commit eb036d5

Browse files
committed
Add instructions for adding new syntax support
1 parent 4a21235 commit eb036d5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

CONTRIBUTING.md

+28
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,31 @@
22

33
This project uses PSR-12 with consistent brace placement. This means that the opening brace is
44
always on the same line, even for class and method declarations.
5+
6+
## Tools
7+
8+
This project uses PHP-CS-Fixer and PHPStan. You can invoke them using `make`:
9+
10+
```shell
11+
make php-cs-fixer
12+
make phpstan
13+
```
14+
15+
## Adding support for new PHP syntax
16+
17+
1. If necessary, add emulation support for new tokens.
18+
* Add a new subclass of `Lexer\TokenEmulator`. Take inspiration from existing classes.
19+
* Add the new class to the array in `Lexer\Emulative`.
20+
* Add tests for the emulation in `Lexer\EmulativeTest`. You'll want to modify
21+
`provideTestReplaceKeywords()` for new reserved keywords and `provideTestLexNewFeatures()` for
22+
other emulations.
23+
2. Add any new node classes that are needed.
24+
3. Add support for the new syntax in `grammar/php.y`. Regenerate the parser by running
25+
`php grammar/rebuildParsers.php`. Use `--debug` if there are conflicts.
26+
4. Add pretty-printing support by implementing a `pFooBar()` method in `PrettyPrinter\Standard`.
27+
5. Add tests both in `test/code/parser` and `test/code/prettyPrinter`.
28+
6. Add support for formatting-preserving pretty-printing. This is done by modifying the data tables
29+
at the end of `PrettyPrinterAbstract`. Add a test in `test/code/formatPreservation`.
30+
7. Does the new syntax feature namespaced names? If so, add support for name resolution in
31+
`NodeVisitor\NameResolver`. Test it in `NodeVisitor\NameResolverTest`.
32+
8. Does the new syntax require any changes to builders? Is so, make them :)

0 commit comments

Comments
 (0)