AbsenceTest
type| Package | @formscript/ast |
|---|---|
| Specification | 4, 9.9 |
| Depends on | nothing — it is a leaf |
@formscript/ast
The abstract syntax tree of §4 of the specification: the node types every production in the grammar can produce.
This package depends on nothing. The node definitions are the contract between the lexer, the parser, the scope builder, the analyser and the engine, so they are kept free of even a dependency on the error catalogue.
Nodes
Every node is a discriminated union member with a kind and a span:
import type { Expression, Statement } from '@formscript/ast';
function describe(node: Expression): string {
switch (node.kind) {
case 'identifier': return node.name;
case 'literal': return node.raw;
default: return node.kind;
}
}
SourceSpan is a half-open range with 1-based line and column, plus the byte
offset, so a diagnostic can point at the exact source text that caused it.
Walking
import { allExpressions, allStatements, childExpressions } from '@formscript/ast';
for (const expression of allExpressions(document)) {
// every expression in the document, each node once
}
for (const child of childExpressions(expression)) {
// the direct children of one expression
}
allExpressions returns each node once, in source order, which is what the
diagnostic order of §9.9 requires.
Public API
89 exported symbols.
AcceptedConstraint
interfaceActionStatement
interfaceallExpressions
re-exportallStatements
re-exportAnyTypeRef
interfaceArrayLiteralExpression
interfaceArrayTypeRef
interfaceAttributeStatement
interfaceBetweenExpression
interface
`x is between a and b` (§6.13).
BinaryExpression
interfaceBinaryOperator
typeBlock
interfaceBlockKind
typeBlockStatement
interfaceBound
interfaceCallExpression
interfacechildExpressions
re-exportCoalesceExpression
interface
`left ?? right` — coalescing (§6.11).
ComprehensionExpression
interface
`map(i in items, i * 2)` (§6.5).
ComprehensionFunction
typeConstraint
typeCrossConstraint
interfaceCustomConstraint
interfaceDateLikeTypeRef
interfaceDocument
interfaceEMPTY_SPAN
re-exportEnumOption
interfaceEnumTypeRef
interfaceEqualityConstraint
interfaceExpression
typeexpressionsOf
re-exportExpressionVisitor
typeFileTypeRef
interfaceFormatConstraint
interfaceFormDefinition
interfaceFormMeta
interfaceGeoTypeRef
interfaceIdentifierExpression
interfaceImportStatement
interfaceIncludeStatement
interfaceIndexExpression
interface
`target[index]`
IsExpression
interface
`x is known` and friends (§6.9).
LengthConstraint
interfaceLiteralExpression
interfaceLiteralKind
typeMatchArm
interfaceMatchesExpression
interface
`x matches "regex"` — the RE2 subset (§6.46).
MatchPattern
typeMatchStatement
interfaceMembershipConstraint
interfaceMultipleOfConstraint
interfaceNamespaceDefinition
interfaceNamespaceExpression
interface
`$env.foo.bar` — a runtime-resolved path (§2.4).
Node
interface
Every node carries the source range it was parsed from.
NowExpression
interface
`$now` — the transaction's fixed evaluation timestamp (§6.4).
NumericConstraint
interfaceObjectLiteralEntry
interfaceObjectLiteralExpression
interfaceObjectTypeMember
interfaceObjectTypeRef
interfaceOptionEntry
interfaceOptionsStatement
interfaceOutputEntry
interfaceOutputStatement
interfacePathRef
typePatternConstraint
interfaceRelationEquation
interfaceRelationStatement
interfaceRequiredConstraint
interfaceScalarTypeRef
interfaceSelectorExpression
interface
`target.property`
SelfExpression
interface
`self` — the field currently being computed (§6.3).
SourcePosition
interfaceSourceSpan
interface
A half-open source range, 1-based line and column.
SourceStatement
interfacespanBetween
re-exportStatement
typeTernaryExpression
interfaceTextEntry
interfaceTextStatement
interfaceTypeRef
typeTypeStatement
interfaceUnaryExpression
interfaceUnaryOperator
typeUniqueConstraint
interfaceValidateStatement
interfaceValidation
interfaceWildcardExpression
interface
`list.*` — the wildcard projection (§6.3).