You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: import/code/README.md
+24-24
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ The usage procedure is shown below.
27
27
%auxil "pcc_ast_manager_t *"
28
28
```
29
29
30
-
If the prefix is set with `%prefix`, all symbols starting with <code><b><i>pcc</i></b>`_`</code> are changed to those with the specified prefix as below.
30
+
If the prefix is set with `%prefix`, all symbols starting with <code><b><i>pcc</i></b>\_</code> are changed to those with the specified prefix as below.
31
31
```c
32
32
%prefix "my"
33
33
@@ -36,33 +36,33 @@ The usage procedure is shown below.
36
36
%auxil "my_ast_manager_t *"
37
37
```
38
38
3. Create an AST node using either of the following functions in every rule action.
+ Adds a child node specified by the argument `node` to the variadic node `obj`.
54
54
+ Can be used for `obj` as a variadic node only.
55
55
56
-
As written above, if the prefix is set with `%prefix`, all symbols starting with <code><b><i>pcc</i></b>`_`</code> are changed to those with the specified prefix.
56
+
As written above, if the prefix is set with `%prefix`, all symbols starting with <code><b><i>pcc</i></b>\_</code> are changed to those with the specified prefix.
57
57
58
58
There are the variants of the node creation functions that enable setting a label as an `int` value.
59
59
The label can be used for specifying node kinds in order to make it easier to analyze the AST in the later parsing steps.
Every AST node retains the rule pattern matching range in the member variable `range`.
68
68
Namely, `obj->range.start` and `obj->range.end` memorize `$0s` and `$0e` respectively at the time when the node `obj` was created in a rule action.
@@ -92,9 +92,9 @@ The usage procedure is shown below.
92
92
#### Customization
93
93
94
94
To build a meaningful AST, customization of the node is needed.
95
-
By defining the macro <code><b><i>PCC</i></b>`_AST_NODE_CUSTOM_DATA_DEFINED`</code> in a `%header` section before `%import "code/pcc_ast.peg"`,
96
-
the node member variable `custom` whose data type is <code><b><i>pcc</i></b>`_ast_node_custom_data_t`</code> is enabled for storing node custom data.
97
-
If the prefix is set with `%prefix`, the macro name <code><b><i>PCC</i></b>`_AST_NODE_CUSTOM_DATA_DEFINED`</code> is changed to those with the uppercased prefix as below.
95
+
By defining the macro <code><b><i>PCC</i></b>\_AST_NODE_CUSTOM_DATA_DEFINED</code> in a `%header` section before `%import "code/pcc_ast.peg"`,
96
+
the node member variable `custom` whose data type is <code><b><i>pcc</i></b>\_ast_node_custom_data_t</code> is enabled for storing node custom data.
97
+
If the prefix is set with `%prefix`, the macro name <code><b><i>PCC</i></b>\_AST_NODE_CUSTOM_DATA_DEFINED</code> is changed to those with the uppercased prefix as below.
98
98
```c
99
99
%prefix "my"
100
100
@@ -134,9 +134,9 @@ The concrete usage procedure is shown below.
@@ -161,7 +161,7 @@ Note that, unlike other symbols, the prefix of these macro names is never change
161
161
**`PCC_AST_MALLOC(`**_mgr_**`,`**_size_**`)`**
162
162
163
163
The function macro to allocate a memory block.
164
-
The pointer to the instance of <code><b><i>pcc</i></b>`_ast_manager_t`</code> that was passed to the API function <code><b><i>pcc</i></b>`_create()`</code> can be retrieved from the argument _auxil_.
164
+
The pointer to the instance of <code><b><i>pcc</i></b>\_ast_manager_t</code> that was passed to the API function <code><b><i>pcc</i></b>\_create()</code> can be retrieved from the argument _auxil_.
165
165
It can be ignored if the instance does not concern memory allocation.
166
166
The argument _size_ is the number of bytes to allocate.
167
167
This macro must return a pointer to the allocated memory block, or `NULL` if no sufficient memory is available.
@@ -171,7 +171,7 @@ The default is defined as `PCC_MALLOC(mgr, size)`, which is used in the generate
The function macro to reallocate the existing memory block.
174
-
The pointer to the instance of <code><b><i>pcc</i></b>`_ast_manager_t`</code> that was passed to the API function <code><b><i>pcc</i></b>`_create()`</code> can be retrieved from the argument _auxil_.
174
+
The pointer to the instance of <code><b><i>pcc</i></b>\_ast_manager_t</code> that was passed to the API function <code><b><i>pcc</i></b>\_create()</code> can be retrieved from the argument _auxil_.
175
175
It can be ignored if the instance does not concern memory allocation.
176
176
The argument _ptr_ is the pointer to the previously allocated memory block.
177
177
The argument _size_ is the new number of bytes to reallocate.
@@ -183,7 +183,7 @@ The default is defined as `PCC_REALLOC(mgr, ptr, size)`, which is used in the ge
183
183
**`PCC_AST_FREE(`**_mgr_**`,`**_ptr_**`)`**
184
184
185
185
The function macro to free the existing memory block.
186
-
The pointer to the instance of <code><b><i>pcc</i></b>`_ast_manager_t`</code> that was passed to the API function <code><b><i>pcc</i></b>`_create()`</code> can be retrieved from the argument _auxil_.
186
+
The pointer to the instance of <code><b><i>pcc</i></b>\_ast_manager_t</code> that was passed to the API function <code><b><i>pcc</i></b>\_create()</code> can be retrieved from the argument _auxil_.
187
187
It can be ignored if the instance does not concern memory allocation.
188
188
The argument _ptr_ is the pointer to the previously allocated memory block.
0 commit comments