1# DSL for build AST tree 2 3## Usage 4 5All nodes of AST tree builder is header only. 6 7For use DSL for AST tree builder: 8 91. Include header with needed node 102. Create builder: 11 12 1. All builder methods, except method `Build`, return `ASTBuilder` class. 13 2. Builder constructor have `Allocator` argument, that must be sended. 14 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. 15 4. All builders have method `SetParent`, it can be used for set parent node. 16 5. To get node from builder you must to use method `Build` 17 18 Example: 19 ```cpp 20 // Create NumberLiteralBuildr, set value and build it. Variable `left` is NumberLiteral after call `Build` method. 21 auto left = NumberLiteralBuilder(Allocator()).SetValue("10").Build(); 22 auto right = NumberLiteralBuilder(Allocator()).SetValue("5").Build(); 23 // Create BinaryExpressionBuilder, set left operand, set right operand, set operator and build BinaryExpression node. 24 auto binaryExpr = BinaryExpressionBuilder(Allocator()) 25 .SetLeft(left) 26 .SetRight(right) 27 .SetOperator(ark::es2panda::lexer::TokenType::PUNCTUATOR_PLUS) 28 .Build(); 29 ``` 30 31 *Note: More examples can be found in `ets_frontend/ets2panda/test/unit/public/ast_builder_test.cpp`* 32 33## List of implemented nodes 34 35<details> 36 <summary>Implemented nodes</summary> 37 38 * AwaitExpression 39 * BigintLiteral 40 * BinaryExpression 41 * BlockExpression 42 * BlockStatement 43 * BooleanLiteral 44 * BreakStatement 45 * CallExpression 46 * CharLiteral 47 * ClassDeclaration 48 * ClassDefenition 49 * ClassPropery 50 * ETSTypeReference 51 * ETSTypeReferencePart 52 * ExportDefaultDeclaration 53 * ExpressionStatement 54 * FunctionExpression 55 * Identifier 56 * IfStatement 57 * MemberExpression 58 * MethodDefinition 59 * NullLiteral 60 * NumberLiteral 61 * OpaqueTypeNode 62 * ScriptFunction 63 * Statement 64 * StringLiteral 65 * SuperExpression 66 * SwitchCaseStatement 67 * SwitchStatement 68 * ThisExpression 69 * TSClassImplements 70 * TSEnumDeclaration 71 * TSEnumMember 72 * TSTypeParameterInstantiation 73 * UnaryExpression 74 * UndefinedLiteral 75 * UpdateExpression 76 * VariableDeclaration 77 * VariableDeclarator 78 * WhileStatement 79 * YieldExpression 80 81</details> 82 83*Note: list of implemented nodes actual by 2024.07.03*