type-lang / parser
Library for parsing and validating TypeLang syntax and converting it into AST nodes
Installs: 35 137
Dependents: 7
Suggesters: 0
Security: 0
Stars: 47
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: ^8.1
- phplrt/lexer: ^3.7
- phplrt/parser: ^3.7
- phplrt/source: ^3.7
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.53
- jetbrains/phpstorm-attributes: ^1.0
- phplrt/compiler: ^3.7
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^1.11
- phpstan/phpstan-strict-rules: ^1.6
- phpunit/phpunit: ^10.5|^11.0
- rector/rector: ^1.1
This package is auto-updated.
Last update: 2024-11-09 03:56:33 UTC
README
Reference implementation for TypeLang Parser.
TypeLang is a declarative type language inspired by static analyzers like PHPStan and Psalm.
Read documentation pages for more information.
Installation
TypeLang Parser is available as Composer repository and can be installed using the following command in a root of your project:
composer require type-lang/parser
Quick Start
$parser = new \TypeLang\Parser\Parser(); $type = $parser->parse(<<<'PHP' array{ key: callable(Example, int): mixed, ... } PHP); var_dump($type);
Expected Output:
TypeLang\Parser\Node\Stmt\NamedTypeNode { +offset: 0 +name: TypeLang\Parser\Node\Name { +offset: 0 -parts: array:1 [ 0 => TypeLang\Parser\Node\Identifier { +offset: 0 +value: "array" } ] } +arguments: null +fields: TypeLang\Parser\Node\Stmt\Shape\FieldsListNode { +offset: 11 +items: array:1 [ 0 => TypeLang\Parser\Node\Stmt\Shape\NamedFieldNode { +offset: 11 +type: TypeLang\Parser\Node\Stmt\CallableTypeNode { +offset: 16 +name: TypeLang\Parser\Node\Name { +offset: 16 -parts: array:1 [ 0 => TypeLang\Parser\Node\Identifier { +offset: 16 +value: "callable" } ] } +parameters: TypeLang\Parser\Node\Stmt\Callable\ParametersListNode { +offset: 25 +items: array:2 [ 0 => TypeLang\Parser\Node\Stmt\Callable\ParameterNode { +offset: 25 +type: TypeLang\Parser\Node\Stmt\NamedTypeNode { +offset: 25 +name: TypeLang\Parser\Node\Name { +offset: 25 -parts: array:1 [ 0 => TypeLang\Parser\Node\Identifier { +offset: 25 +value: "Example" } ] } +arguments: null +fields: null } +name: null +output: false +variadic: false +optional: false } 1 => TypeLang\Parser\Node\Stmt\Callable\ParameterNode { +offset: 34 +type: TypeLang\Parser\Node\Stmt\NamedTypeNode { +offset: 34 +name: TypeLang\Parser\Node\Name { +offset: 34 -parts: array:1 [ 0 => TypeLang\Parser\Node\Identifier { +offset: 34 +value: "int" } ] } +arguments: null +fields: null } +name: null +output: false +variadic: false +optional: false } ] } +type: TypeLang\Parser\Node\Stmt\NamedTypeNode { +offset: 40 +name: TypeLang\Parser\Node\Name { +offset: 40 -parts: array:1 [ 0 => TypeLang\Parser\Node\Identifier { +offset: 40 +value: "mixed" } ] } +arguments: null +fields: null } } +optional: false +key: TypeLang\Parser\Node\Identifier { +offset: 11 +value: "key" } } ] +sealed: false } }