13af6ab5fSopenharmony_ci# DSL for build AST tree 23af6ab5fSopenharmony_ci 33af6ab5fSopenharmony_ci## Usage 43af6ab5fSopenharmony_ci 53af6ab5fSopenharmony_ciAll nodes of AST tree builder is header only. 63af6ab5fSopenharmony_ci 73af6ab5fSopenharmony_ciFor use DSL for AST tree builder: 83af6ab5fSopenharmony_ci 93af6ab5fSopenharmony_ci1. Include header with needed node 103af6ab5fSopenharmony_ci2. Create builder: 113af6ab5fSopenharmony_ci 123af6ab5fSopenharmony_ci 1. All builder methods, except method `Build`, return `ASTBuilder` class. 133af6ab5fSopenharmony_ci 2. Builder constructor have `Allocator` argument, that must be sended. 143af6ab5fSopenharmony_ci 3. For set arguments for construct node we have methods that starts with `Set` or `Add`. For all necessary fields for constructor we have methods for set them. 153af6ab5fSopenharmony_ci 4. All builders have method `SetParent`, it can be used for set parent node. 163af6ab5fSopenharmony_ci 5. To get node from builder you must to use method `Build` 173af6ab5fSopenharmony_ci 183af6ab5fSopenharmony_ci Example: 193af6ab5fSopenharmony_ci ```cpp 203af6ab5fSopenharmony_ci // Create NumberLiteralBuildr, set value and build it. Variable `left` is NumberLiteral after call `Build` method. 213af6ab5fSopenharmony_ci auto left = NumberLiteralBuilder(Allocator()).SetValue("10").Build(); 223af6ab5fSopenharmony_ci auto right = NumberLiteralBuilder(Allocator()).SetValue("5").Build(); 233af6ab5fSopenharmony_ci // Create BinaryExpressionBuilder, set left operand, set right operand, set operator and build BinaryExpression node. 243af6ab5fSopenharmony_ci auto binaryExpr = BinaryExpressionBuilder(Allocator()) 253af6ab5fSopenharmony_ci .SetLeft(left) 263af6ab5fSopenharmony_ci .SetRight(right) 273af6ab5fSopenharmony_ci .SetOperator(ark::es2panda::lexer::TokenType::PUNCTUATOR_PLUS) 283af6ab5fSopenharmony_ci .Build(); 293af6ab5fSopenharmony_ci ``` 303af6ab5fSopenharmony_ci 313af6ab5fSopenharmony_ci *Note: More examples can be found in `ets_frontend/ets2panda/test/unit/public/ast_builder_test.cpp`* 323af6ab5fSopenharmony_ci 333af6ab5fSopenharmony_ci## List of implemented nodes 343af6ab5fSopenharmony_ci 353af6ab5fSopenharmony_ci<details> 363af6ab5fSopenharmony_ci <summary>Implemented nodes</summary> 373af6ab5fSopenharmony_ci 383af6ab5fSopenharmony_ci * AwaitExpression 393af6ab5fSopenharmony_ci * BigintLiteral 403af6ab5fSopenharmony_ci * BinaryExpression 413af6ab5fSopenharmony_ci * BlockExpression 423af6ab5fSopenharmony_ci * BlockStatement 433af6ab5fSopenharmony_ci * BooleanLiteral 443af6ab5fSopenharmony_ci * BreakStatement 453af6ab5fSopenharmony_ci * CallExpression 463af6ab5fSopenharmony_ci * CharLiteral 473af6ab5fSopenharmony_ci * ClassDeclaration 483af6ab5fSopenharmony_ci * ClassDefenition 493af6ab5fSopenharmony_ci * ClassPropery 503af6ab5fSopenharmony_ci * ETSTypeReference 513af6ab5fSopenharmony_ci * ETSTypeReferencePart 523af6ab5fSopenharmony_ci * ExportDefaultDeclaration 533af6ab5fSopenharmony_ci * ExpressionStatement 543af6ab5fSopenharmony_ci * FunctionExpression 553af6ab5fSopenharmony_ci * Identifier 563af6ab5fSopenharmony_ci * IfStatement 573af6ab5fSopenharmony_ci * MemberExpression 583af6ab5fSopenharmony_ci * MethodDefinition 593af6ab5fSopenharmony_ci * NullLiteral 603af6ab5fSopenharmony_ci * NumberLiteral 613af6ab5fSopenharmony_ci * OpaqueTypeNode 623af6ab5fSopenharmony_ci * ScriptFunction 633af6ab5fSopenharmony_ci * Statement 643af6ab5fSopenharmony_ci * StringLiteral 653af6ab5fSopenharmony_ci * SuperExpression 663af6ab5fSopenharmony_ci * SwitchCaseStatement 673af6ab5fSopenharmony_ci * SwitchStatement 683af6ab5fSopenharmony_ci * ThisExpression 693af6ab5fSopenharmony_ci * TSClassImplements 703af6ab5fSopenharmony_ci * TSEnumDeclaration 713af6ab5fSopenharmony_ci * TSEnumMember 723af6ab5fSopenharmony_ci * TSTypeParameterInstantiation 733af6ab5fSopenharmony_ci * UnaryExpression 743af6ab5fSopenharmony_ci * UndefinedLiteral 753af6ab5fSopenharmony_ci * UpdateExpression 763af6ab5fSopenharmony_ci * VariableDeclaration 773af6ab5fSopenharmony_ci * VariableDeclarator 783af6ab5fSopenharmony_ci * WhileStatement 793af6ab5fSopenharmony_ci * YieldExpression 803af6ab5fSopenharmony_ci 813af6ab5fSopenharmony_ci</details> 823af6ab5fSopenharmony_ci 833af6ab5fSopenharmony_ci*Note: list of implemented nodes actual by 2024.07.03*