PHP code example of phptl / parser
1. Go to this page and download the library: Download phptl/parser library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phptl / parser example snippets
$parser = new \TypeLang\Parser\Parser();
$type = $parser->parse(<<<'PHP'
array{
key: callable(Example, int): mixed,
...
}
PHP);
var_dump($type);
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
}
}