From 5dc9257b18dccbff5a8191ac6a4b279fbf934192 Mon Sep 17 00:00:00 2001 From: Kirill Nesmeyanov Date: Sun, 30 Jun 2024 12:47:49 +0300 Subject: [PATCH] Improve parser documentation --- Writerside/topics/parser.md | 159 +++++++----------------------------- 1 file changed, 29 insertions(+), 130 deletions(-) diff --git a/Writerside/topics/parser.md b/Writerside/topics/parser.md index 1ba93e8..21654e6 100644 --- a/Writerside/topics/parser.md +++ b/Writerside/topics/parser.md @@ -24,12 +24,38 @@ information and grammar checking. To create a parser instance, the `TypeLang\Parser\Parser` class is used. To run code analysis, you should use the `parse()` method. - - +```php +$parser = new TypeLang\Parser\Parser(); + +$result = $parser->parse('example'); +``` + +```php +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: "example" + } + ] + } + +arguments: null + +fields: null +} +``` +{collapsible="true" collapsed-title="Result"} + +### Parser Arguments -The first argument of the `parse()` method corresponds to the source code data +The first argument of the `TypeLang\Parser\Parser::parse()` method corresponds to the source code data and can be of the following types: + + + @@ -66,130 +92,3 @@ and can be of the following types: - -```php -$parser = new TypeLang\Parser\Parser(); - -$result = $parser->parse(<<<'PHP' - array, - ... - }> - PHP); - -var_dump($result); -``` -{prompt="1"} - - -```php -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: TypeLang\Parser\Node\Stmt\Template\ArgumentsListNode { - +offset: 5 - +items: array:2 [ - 0 => TypeLang\Parser\Node\Stmt\Template\ArgumentNode { - +offset: 6 - +value: TypeLang\Parser\Node\Stmt\NamedTypeNode { - +offset: 6 - +name: TypeLang\Parser\Node\Name { - +offset: 6 - -parts: array:1 [ - 0 => TypeLang\Parser\Node\Identifier { - +offset: 6 - +value: "array-key" - } - ] - } - +arguments: null - +fields: null - } - } - 1 => TypeLang\Parser\Node\Stmt\Template\ArgumentNode { - +offset: 17 - +value: TypeLang\Parser\Node\Stmt\NamedTypeNode { - +offset: 17 - +name: TypeLang\Parser\Node\Name { - +offset: 17 - -parts: array:1 [ - 0 => TypeLang\Parser\Node\Identifier { - +offset: 17 - +value: "object" - } - ] - } - +arguments: null - +fields: TypeLang\Parser\Node\Stmt\Shape\FieldsListNode { - +offset: 27 - +items: array:1 [ - 0 => TypeLang\Parser\Node\Stmt\Shape\NamedFieldNode { - +offset: 27 - +type: TypeLang\Parser\Node\Stmt\NamedTypeNode { - +offset: 32 - +name: TypeLang\Parser\Node\Name { - +offset: 32 - -parts: array:1 [ - 0 => TypeLang\Parser\Node\Identifier { - +offset: 32 - +value: "int" - } - ] - } - +arguments: TypeLang\Parser\Node\Stmt\Template\ArgumentsListNode { - +offset: 35 - +items: array:2 [ - 0 => TypeLang\Parser\Node\Stmt\Template\ArgumentNode { - +offset: 36 - +value: TypeLang\Parser\Node\Literal\IntLiteralNode { - +offset: 36 - +raw: "0" - +value: 0 - } - } - 1 => TypeLang\Parser\Node\Stmt\Template\ArgumentNode { - +offset: 39 - +value: TypeLang\Parser\Node\Stmt\NamedTypeNode { - +offset: 39 - +name: TypeLang\Parser\Node\Name { - +offset: 39 - -parts: array:1 [ - 0 => TypeLang\Parser\Node\Identifier { - +offset: 39 - +value: "max" - } - ] - } - +arguments: null - +fields: null - } - } - ] - } - +fields: null - } - +optional: false - +key: TypeLang\Parser\Node\Identifier { - +offset: 27 - +value: "key" - } - } - ] - +sealed: false - } - } - } - ] - } - +fields: null -} -``` -{collapsible="true" collapsed-title="Result"} \ No newline at end of file