Overview
Toolkit
The toolkit works with types as data: every package reads or writes the same
tree of TypeLang\Type\* nodes.
Everything speaks the same AST. Parse a string, read a reflection, print back, or walk the nodes with a visitor.
| Package | Does |
|---|---|
type-lang/types |
The AST node classes, the vocabulary of the other parts |
type-lang/parser |
String to AST, with grammar checking and feature flags |
type-lang/printer |
AST to string: the full form or a native PHP type |
type-lang/reader |
PHP Reflection to AST |
Installation
Section titled “Installation”Install what you need, types comes with any of them:
composer require type-lang/parser type-lang/printerA string in, a string out
Section titled “A string in, a string out”$parser = new TypeLang\Parser\TypeParser();$type = $parser->parse('array{ key: int }');
echo new TypeLang\Printer\PrettyTypePrinter()->print($type); // array{key: int}echo new TypeLang\Printer\NativeTypePrinter()->print($type); // array- AST: every node class, what it holds and the syntax it stands for.
- Parser: reading modes, errors, feature flags, partial parsing, visitors and name resolution.
- Printer: the pretty and the native form of a type.
- Reader: types of constants, properties, functions and parameters from Reflection.