| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
The reference parser for TypeLang — a declarative type language inspired by static analyzers like PHPStan and Psalm.
It reads a type declaration string and builds an AST of TypeLang\Type\* nodes, checking the grammar along the way. The node classes themselves live in the separate type-lang/types package.
Install the package via Composer:
composer require type-lang/parserRequirements:
TypeLang\Parser\TypeParser is the entry point. Its parse() method turns a type declaration into a TypeLang\Type\TypeNode:
$parser = new TypeLang\Parser\TypeParser();
$type = $parser->parse('array{ key: int }');
var_dump($type);
// object(TypeLang\Type\NamedTypeNode) {
// ["name"] => "array"
// ["fields"] => object(TypeLang\Type\Shape\FieldsListNode) { ... }
// ...
// }Every node exposes an $offset (byte offset in the source) plus a handful of properties describing its kind.
$result = $parser->parseTolerant('int and some trailing description');
$result->type; // TypeLang\Type\NamedTypeNode ("int")
$result->offset; // offset where parsing stoppedSee the documentation for feature toggling, visitors and name resolution.
| Back | FazBrowse Home | New Git URL |