import { CST } from "https://deno.land/x/windmill@v1.265.1/node_modules/yaml/browser/index.js";
const { visit } = CST;
Apply a visitor to a CST document or item.
Walks through the tree (depth-first) starting from the root, calling a
visitor
function with two arguments when entering each item:
item
: The current item, which included the following members:start: SourceToken[]
– Source tokens before the key or value, possibly including its anchor or tag.key?: Token | null
– Set for pair values. May then benull
, if the key before the:
separator is empty.sep?: SourceToken[]
– Source tokens between the key and the value, which should include the:
map value indicator ifvalue
is set.value?: Token
– The value of a sequence item, or of a map pair.
path
: The steps from the root to the current node, as an array of['key' | 'value', number]
tuples.
The return value of the visitor may be used to control the traversal:
undefined
(default): Do nothing and continuevisit.SKIP
: Do not visit the children of this token, continue with next siblingvisit.BREAK
: Terminate traversal completelyvisit.REMOVE
: Remove the current item, then continue with the next onenumber
: Set the index of the next step. This is useful especially if the index of the current token has changed.function
: Define the next visitor for this item. After the original visitor is called on item entry, next visitors are called after handling a non-emptykey
and when exiting the item.