@@ -78,7 +78,7 @@ unist relates to the [unified][], [remark][], [rehype][], and [retext][]
78
78
projects in that unist syntax trees are used throughout their ecosystems.
79
79
80
80
unist relates to the [ vfile] [ ] project in that it accepts unist nodes for
81
- its message store, and that vfile can be a source [ _ file _ ] [ term-file ] of a
81
+ its message store, and that vfile can be a source [ * file * ] [ term-file ] of a
82
82
syntax tree.
83
83
84
84
## Nodes
@@ -97,7 +97,7 @@ interface Node {
97
97
```
98
98
99
99
The ` type ` field is a non-empty string representing the variant of a node.
100
- This field can be used to determine the [ _ type _ ] [ term-type ] a node implements.
100
+ This field can be used to determine the [ * type * ] [ term-type ] a node implements.
101
101
102
102
The ` data ` field represents information from the ecosystem.
103
103
The value of the ` data ` field implements the [ ** Data** ] [ dfn-data ] interface.
@@ -106,7 +106,7 @@ The `position` field represents the location of a node in a source document.
106
106
The value of the ` position ` field implements the [ ** Position** ] [ dfn-position ]
107
107
interface.
108
108
The ` position ` field must not be present if a node is
109
- [ _ generated _ ] [ term-generated ] .
109
+ [ * generated * ] [ term-generated ] .
110
110
111
111
Specifications implementing unist are encouraged to define more fields.
112
112
Ecosystems can define fields on [ ** Data** ] [ dfn-data ] .
@@ -128,7 +128,7 @@ interface Position {
128
128
}
129
129
```
130
130
131
- ** Position** represents the location of a node in a source [ _ file _ ] [ term-file ] .
131
+ ** Position** represents the location of a node in a source [ * file * ] [ term-file ] .
132
132
133
133
The ` start ` field of ** Position** represents the place of the first character
134
134
of the parsed source region.
@@ -141,8 +141,8 @@ The `indent` field of **Position** represents the start column at each index
141
141
(plus start line) in the source region, for elements that span multiple lines.
142
142
143
143
If the syntactic unit represented by a node is not present in the source
144
- [ _ file _ ] [ term-file ] at the time of parsing, the node is said to be
145
- [ _ generated _ ] [ term-generated ] and it must not have positional information.
144
+ [ * file * ] [ term-file ] at the time of parsing, the node is said to be
145
+ [ * generated * ] [ term-generated ] and it must not have positional information.
146
146
147
147
For example, if the following value was represented as unist:
148
148
@@ -168,7 +168,7 @@ interface Point {
168
168
}
169
169
```
170
170
171
- ** Point** represents one place in a source [ _ file _ ] [ term-file ] .
171
+ ** Point** represents one place in a source [ * file * ] [ term-file ] .
172
172
173
173
The ` line ` field (1-indexed integer) represents a line in a source file.
174
174
The ` column ` field (1-indexed integer) represents a column in a source file.
@@ -196,7 +196,7 @@ interface Parent <: Node {
196
196
}
197
197
```
198
198
199
- Nodes containing other nodes (said to be [ _ children _ ] [ term-child ] ) extend the
199
+ Nodes containing other nodes (said to be [ * children * ] [ term-child ] ) extend the
200
200
abstract interface ** Parent** ([ ** Node** ] [ dfn-node ] ).
201
201
202
202
The ` children ` field is a list representing the children of a node.
@@ -218,74 +218,74 @@ The `value` field can contain any value.
218
218
219
219
###### Tree
220
220
221
- A ** tree** is a node and all of its [ _ descendants _ ] [ term-descendant ] (if any).
221
+ A ** tree** is a node and all of its [ * descendants * ] [ term-descendant ] (if any).
222
222
223
223
###### Child
224
224
225
225
Node X is ** child** of node Y, if Y’s ` children ` include X.
226
226
227
227
###### Parent
228
228
229
- Node X is ** parent** of node Y, if Y is a [ _ child _ ] [ term-child ] of X.
229
+ Node X is ** parent** of node Y, if Y is a [ * child * ] [ term-child ] of X.
230
230
231
231
###### Index
232
232
233
- The ** index** of a [ _ child _ ] [ term-child ] is its number of preceding
234
- [ _ siblings _ ] [ term-sibling ] , or ` 0 ` if it has none.
233
+ The ** index** of a [ * child * ] [ term-child ] is its number of preceding
234
+ [ * siblings * ] [ term-sibling ] , or ` 0 ` if it has none.
235
235
236
236
###### Sibling
237
237
238
238
Node X is a ** sibling** of node Y, if X and Y have the same
239
- [ _ parent _ ] [ term-parent ] (if any).
239
+ [ * parent * ] [ term-parent ] (if any).
240
240
241
- The ** previous sibling** of a [ _ child _ ] [ term-child ] is its ** sibling** at its
242
- [ _ index _ ] [ term-index ] minus 1.
241
+ The ** previous sibling** of a [ * child * ] [ term-child ] is its ** sibling** at its
242
+ [ * index * ] [ term-index ] minus 1.
243
243
244
- The ** next sibling** of a [ _ child _ ] [ term-child ] is its ** sibling** at its
245
- [ _ index _ ] [ term-index ] plus 1.
244
+ The ** next sibling** of a [ * child * ] [ term-child ] is its ** sibling** at its
245
+ [ * index * ] [ term-index ] plus 1.
246
246
247
247
###### Root
248
248
249
- The ** root** of a node is itself, if without [ _ parent _ ] [ term-parent ] , or the
250
- ** root** of its [ _ parent _ ] [ term-parent ] .
249
+ The ** root** of a node is itself, if without [ * parent * ] [ term-parent ] , or the
250
+ ** root** of its [ * parent * ] [ term-parent ] .
251
251
252
- The ** root** of a [ _ tree _ ] [ term-tree ] is any node in that [ _ tree _ ] [ term-tree ]
253
- without [ _ parent _ ] [ term-parent ] .
252
+ The ** root** of a [ * tree * ] [ term-tree ] is any node in that [ * tree * ] [ term-tree ]
253
+ without [ * parent * ] [ term-parent ] .
254
254
255
255
###### Descendant
256
256
257
- Node X is ** descendant** of node Y, if X is a [ _ child _ ] [ term-child ] of Y, or if
258
- X is a [ _ child _ ] [ term-child ] of node Z that is a ** descendant** of Y.
257
+ Node X is ** descendant** of node Y, if X is a [ * child * ] [ term-child ] of Y, or if
258
+ X is a [ * child * ] [ term-child ] of node Z that is a ** descendant** of Y.
259
259
260
260
An ** inclusive descendant** is a node or one of its ** descendants** .
261
261
262
262
###### Ancestor
263
263
264
- Node X is an ** ancestor** of node Y, if Y is a [ _ descendant _ ] [ term-descendant ]
264
+ Node X is an ** ancestor** of node Y, if Y is a [ * descendant * ] [ term-descendant ]
265
265
of X.
266
266
267
267
An ** inclusive ancestor** is a node or one of its ** ancestors** .
268
268
269
269
###### Head
270
270
271
- The ** head** of a node is its first [ _ child _ ] [ term-child ] (if any).
271
+ The ** head** of a node is its first [ * child * ] [ term-child ] (if any).
272
272
273
273
###### Tail
274
274
275
- The ** tail** of a node is its last [ _ child _ ] [ term-child ] (if any).
275
+ The ** tail** of a node is its last [ * child * ] [ term-child ] (if any).
276
276
277
277
###### Leaf
278
278
279
- A ** leaf** is a node with no [ _ children _ ] [ term-child ] .
279
+ A ** leaf** is a node with no [ * children * ] [ term-child ] .
280
280
281
281
###### Branch
282
282
283
- A ** branch** is a node with one or more [ _ children _ ] [ term-child ] .
283
+ A ** branch** is a node with one or more [ * children * ] [ term-child ] .
284
284
285
285
###### Generated
286
286
287
- A node is ** generated** if it does not have [ _ positional
288
- information _ ] [ term-positional-info ] .
287
+ A node is ** generated** if it does not have [ * positional
288
+ information * ] [ term-positional-info ] .
289
289
290
290
###### Type
291
291
@@ -299,7 +299,7 @@ The **positional information** of a node is the value of its `position` field.
299
299
300
300
A ** file** is a source document that represents the original file that was
301
301
parsed to produce the syntax tree.
302
- [ _ Positional information _ ] [ term-positional-info ] represents the place of a node
302
+ [ * Positional information * ] [ term-positional-info ] represents the place of a node
303
303
in this file.
304
304
Files are provided by the host environment and not defined by unist.
305
305
@@ -308,44 +308,44 @@ For example, see projects such as [**vfile**][vfile].
308
308
###### Preorder
309
309
310
310
In ** preorder** (** NLR** ) is [ depth-first] [ traversal-depth ] [ tree
311
- traversal] [ traversal ] that performs the following steps for each node _ N _ :
311
+ traversal] [ traversal ] that performs the following steps for each node * N * :
312
312
313
- 1 . ** N** : visit _ N _ itself
314
- 2 . ** L** : traverse [ _ head _ ] [ term-head ] (then its _ next sibling _ , recursively
315
- moving forward until reaching _ tail _ )
316
- 3 . ** R** : traverse [ _ tail _ ] [ term-tail ]
313
+ 1 . ** N** : visit * N * itself
314
+ 2 . ** L** : traverse [ * head * ] [ term-head ] (then its * next sibling * , recursively
315
+ moving forward until reaching * tail * )
316
+ 3 . ** R** : traverse [ * tail * ] [ term-tail ]
317
317
318
318
###### Postorder
319
319
320
320
In ** postorder** (** LRN** ) is [ depth-first] [ traversal-depth ] [ tree
321
- traversal] [ traversal ] that performs the following steps for each node _ N _ :
321
+ traversal] [ traversal ] that performs the following steps for each node * N * :
322
322
323
- 1 . ** L** : traverse [ _ head _ ] [ term-head ] (then its _ next sibling _ , recursively
324
- moving forward until reaching _ tail _ )
325
- 2 . ** R** : traverse [ _ tail _ ] [ term-tail ]
326
- 3 . ** N** : visit _ N _ itself
323
+ 1 . ** L** : traverse [ * head * ] [ term-head ] (then its * next sibling * , recursively
324
+ moving forward until reaching * tail * )
325
+ 2 . ** R** : traverse [ * tail * ] [ term-tail ]
326
+ 3 . ** N** : visit * N * itself
327
327
328
328
###### Enter
329
329
330
- ** Enter** is a step right before other steps performed on a given node _ N _ when
330
+ ** Enter** is a step right before other steps performed on a given node * N * when
331
331
[ ** traversing** ] [ traversal ] a tree.
332
332
333
- For example, when performing _ preorder _ traversal, ** enter** is the first step
334
- taken, right before visiting _ N _ itself.
333
+ For example, when performing * preorder * traversal, ** enter** is the first step
334
+ taken, right before visiting * N * itself.
335
335
336
336
###### Exit
337
337
338
- ** Exit** is a step right after other steps performed on a given node _ N _ when
338
+ ** Exit** is a step right after other steps performed on a given node * N * when
339
339
[ ** traversing** ] [ traversal ] a tree.
340
340
341
- For example, when performing _ preorder _ traversal, ** exit** is the last step
342
- taken, right after traversing the [ _ tail _ ] [ term-tail ] of _ N _ .
341
+ For example, when performing * preorder * traversal, ** exit** is the last step
342
+ taken, right after traversing the [ * tail * ] [ term-tail ] of * N * .
343
343
344
344
## Tree traversal
345
345
346
- ** Tree traversal** is a common task when working with a [ _ tree _ ] [ term-tree ] to
346
+ ** Tree traversal** is a common task when working with a [ * tree * ] [ term-tree ] to
347
347
search it.
348
- Tree traversal is typically either _ breadth-first _ or _ depth-first _ .
348
+ Tree traversal is typically either * breadth-first * or * depth-first * .
349
349
350
350
In the following examples, we’ll work with this tree:
351
351
@@ -370,8 +370,8 @@ In the following examples, we’ll work with this tree:
370
370
###### Breadth-first traversal
371
371
372
372
** Breadth-first traversal** is visiting a node and all its
373
- [ _ siblings _ ] [ term-sibling ] to broaden the search at that level, before
374
- traversing [ _ children _ ] [ term-child ] .
373
+ [ * siblings * ] [ term-sibling ] to broaden the search at that level, before
374
+ traversing [ * children * ] [ term-child ] .
375
375
376
376
For the syntax tree defined in the diagram, a breadth-first traversal first
377
377
searches the root of the tree (** A** ), then its children (** B** and ** F** ), then
@@ -380,41 +380,41 @@ their children (**C**, **D**, **E**, and **G**).
380
380
###### Depth-first traversal
381
381
382
382
Alternatively, and more commonly, ** depth-first traversal** is used.
383
- The search is first deepened, by traversing [ _ children _ ] [ term-child ] , before
384
- traversing [ _ siblings _ ] [ term-sibling ] .
383
+ The search is first deepened, by traversing [ * children * ] [ term-child ] , before
384
+ traversing [ * siblings * ] [ term-sibling ] .
385
385
386
386
For the syntax tree defined in the diagram, a depth-first traversal first
387
387
searches the root of the tree (** A** ), then one of its children (** B** or
388
388
** F** ), then their children (** C** , ** D** , and ** E** , or ** G** ).
389
389
390
- For a given node _ N _ with [ _ children _ ] [ term-child ] , a ** depth-first traversal**
390
+ For a given node * N * with [ * children * ] [ term-child ] , a ** depth-first traversal**
391
391
performs three steps, simplified to only binary trees (every node has
392
- [ _ head _ ] [ term-head ] and [ _ tail _ ] [ term-tail ] , but no other children):
392
+ [ * head * ] [ term-head ] and [ * tail * ] [ term-tail ] , but no other children):
393
393
394
- * ** N** : visit _ N _ itself
395
- * ** L** : traverse [ _ head _ ] [ term-head ]
396
- * ** R** : traverse [ _ tail _ ] [ term-tail ]
394
+ * ** N** : visit * N * itself
395
+ * ** L** : traverse [ * head * ] [ term-head ]
396
+ * ** R** : traverse [ * tail * ] [ term-tail ]
397
397
398
398
These steps can be done in any order, but for non-binary trees, ** L** and ** R**
399
399
occur together.
400
- If ** L** is done before ** R** , the traversal is called _ left -to-right _
401
- traversal, otherwise it is called _ right -to-left _ traversal.
402
- In the case of non-binary trees, the other children between _ head _ and _ tail _
403
- are processed in that order as well, so for _ left -to-right _ traversal, first
404
- _ head _ is traversed (** L** ), then its _ next sibling _ is traversed, etcetera,
405
- until finally _ tail _ (** R** ) is traversed.
400
+ If ** L** is done before ** R** , the traversal is called * left -to-right *
401
+ traversal, otherwise it is called * right -to-left * traversal.
402
+ In the case of non-binary trees, the other children between * head * and * tail *
403
+ are processed in that order as well, so for * left -to-right * traversal, first
404
+ * head * is traversed (** L** ), then its * next sibling * is traversed, etcetera,
405
+ until finally * tail * (** R** ) is traversed.
406
406
407
407
Because ** L** and ** R** occur together for non-binary trees, we can produce four
408
408
types of orders: NLR, NRL, LRN, RLN.
409
409
410
- NLR and LRN (the two _ left -to-right _ traversal options) are most commonly used
411
- and respectively named [ _ preorder _ ] [ term-preorder ] and
412
- [ _ postorder _ ] [ term-postorder ] .
410
+ NLR and LRN (the two * left -to-right * traversal options) are most commonly used
411
+ and respectively named [ * preorder * ] [ term-preorder ] and
412
+ [ * postorder * ] [ term-postorder ] .
413
413
414
- For the syntax tree defined in the diagram, _ preorder _ and _ postorder _ traversal
414
+ For the syntax tree defined in the diagram, * preorder * and * postorder * traversal
415
415
thus first search the root of the tree (** A** ), then its head (** B** ), then its
416
416
children from left-to-right (** C** , ** D** , and then ** E** ).
417
- After all [ _ descendants _ ] [ term-descendant ] of ** B** are traversed, its next
417
+ After all [ * descendants * ] [ term-descendant ] of ** B** are traversed, its next
418
418
sibling (** F** ) is traversed and then finally its only child (** G** ).
419
419
420
420
## Utilities
0 commit comments