IF Commons GitHub

walk

Walks over a tree (commons lang-sql 0002-sql-ast-parser FR-016): the children of a node in the order of the text, a depth-first walk with enter and leave, the nodes of one kind typed as that kind, and a fold from the leaves. children is one switch on kind that ends with absurd, so a kind added to the tree does not compile until it says what its children are.

const tables = findAll(script, "table").map((t) => t.name.parts.map((p) => p.name).join("."));

Spec: 0002-sql-ast-parser FR-016

Source: commons/lang-sql/src/walk.ts

4 of 5 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

childrenfunction
function children(n: Node): readonly Node[]

The children of a node: every node in one of its fields, in the order of the text.

ParameterWhat it is
na node

Returns: its children

Imported by 18 tests of the run (18 passed, 0 failed): the library's results

findAllfunction
function findAll<K extends Kind>(root: Node, kind: K): readonly NodeOf<K>[]

Every node of one kind in a tree, in the order of the text, typed as that kind.

ParameterWhat it is
rootthe tree
kinda kind of node

Returns: the nodes of that kind

Imported by 13 tests of the run (13 passed, 0 failed): the library's results

foldfunction
function fold<R>(root: Node, f: (node: Node, results: readonly R[]) => R): R

Combines a tree from its leaves: each node's result is made from the node and its children's results.

ParameterWhat it is
rootthe tree
fthe combination

Returns: the root's result

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

Visitorinterfaceno test imports it
interface Visitor

What a walk calls at each node.

MemberTypeWhat it is
enter?((node: Node, parent: Node | undefined) => boolean | undefined)Called before a node's children; returning false skips them (and leave).
leave?((node: Node, parent: Node | undefined) => void)Called after a node's children.
walkfunction
function walk(root: Node, visitor: Visitor): void

Walks a tree depth first.

ParameterWhat it is
rootwhere to begin
visitorwhat to call at each node

Imported by 24 tests of the run (24 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.