PatternBuilder
Defined in: src/schema/index.ts:257
The pattern builder. Each element method appends one element and
returns a builder whose LAST element can be named with .as();
.result() (trailing) declares the node’s result type, after which
.eval() attaches an evaluation function checked against it.
The "~"-prefixed properties carry the accumulated state for
defineNode’s inference — they are internal.
Extended by
Section titled “Extended by”Type Parameters
Section titled “Type Parameters”TPattern
Section titled “TPattern”TPattern extends readonly PatternSchema[] = readonly []
$
$ extends BindingScope = { }
Properties
Section titled “Properties”~pattern
Section titled “~pattern”
readonly~pattern:TPattern
Defined in: src/schema/index.ts:261
~resultType
Section titled “~resultType”
readonly~resultType:undefined
Defined in: src/schema/index.ts:262
readonly~eval:undefined
Defined in: src/schema/index.ts:263
Methods
Section titled “Methods”number()
Section titled “number()”number():
NameableBuilder<TPattern,$,NumberSchema>
Defined in: src/schema/index.ts:266
Append a number literal element
Returns
Section titled “Returns”NameableBuilder<TPattern, $, NumberSchema>
string()
Section titled “string()”string<
TQuotes>(quotes):NameableBuilder<TPattern,$,StringSchema<TQuotes>>
Defined in: src/schema/index.ts:270
Append a string literal element, e.g. p.string(['"', "'"]) —
escapes are processed
Type Parameters
Section titled “Type Parameters”TQuotes
Section titled “TQuotes”TQuotes extends readonly string[]
Parameters
Section titled “Parameters”quotes
Section titled “quotes”TQuotes
Returns
Section titled “Returns”NameableBuilder<TPattern, $, StringSchema<TQuotes>>
ident()
Section titled “ident()”ident():
NameableBuilder<TPattern,$,IdentSchema>
Defined in: src/schema/index.ts:275
Append an identifier element (single segment, no dots)
Returns
Section titled “Returns”NameableBuilder<TPattern, $, IdentSchema>
path()
Section titled “path()”path():
NameableBuilder<TPattern,$,PathSchema>
Defined in: src/schema/index.ts:280
Append a member-access path element: matches ident(.ident)*
(e.g. values.password), type resolved by walking the schema.
Whitespace around the dots is not allowed.
Returns
Section titled “Returns”NameableBuilder<TPattern, $, PathSchema>
constVal()
Section titled “constVal()”constVal<
TValues>(…values):NameableBuilder<TPattern,$,ConstSchema<TValues>>
Defined in: src/schema/index.ts:301
Append a constant element — one or more values as an ORDERED
alternation (first match wins). IDENTIFIER-LIKE values
(constVal("null"), constVal("and")) match only as a WHOLE
identifier — nullable or andy never match (word-boundary rule;
pinned in design-claims); other values ("+", "==") match as raw
text, per member. Keyword literals are ordinary const-pattern nodes;
name the element to receive the MATCHED text in eval:
Type Parameters
Section titled “Type Parameters”TValues
Section titled “TValues”TValues extends readonly [string, string]
Parameters
Section titled “Parameters”values
Section titled “values”…TValues
Returns
Section titled “Returns”NameableBuilder<TPattern, $, ConstSchema<TValues>>
Example
Section titled “Example”const booleanLit = defineNode({ name: "bool", precedence: 5, pattern: (p) => p.constVal("true", "false").as("word") .result("boolean") .eval(({ word }) => word() === "true"),});operand()
Section titled “operand()”Call Signature
Section titled “Call Signature”operand():
NameableBuilder<TPattern,$,ExprSchema<undefined,"operand">>
Defined in: src/schema/index.ts:316
Append a TIGHTER-LEVEL expression element.
Parses at the next-higher grammar level, avoiding left-recursion.
A pattern whose final operand is operand() makes its level
LEFT-associative (the engine folds repetitions: a-b-c → (a-b)-c).
Constraint forms: operand(“number”), operand(“string | number”), operand(“left”) (a binding reference — not valid at position 0, where no earlier operand exists), operand().
Returns
Section titled “Returns”NameableBuilder<TPattern, $, ExprSchema<undefined, "operand">>
Call Signature
Section titled “Call Signature”operand<
C>(constraint):NameableBuilder<TPattern,$,ExprSchema<C,"operand">>
Defined in: src/schema/index.ts:317
Type Parameters
Section titled “Type Parameters”C extends string
Parameters
Section titled “Parameters”constraint
Section titled “constraint”[C] extends [" anyOrNever"] ? C : C extends OptionalPropertyDefinition ? "Optional definitions like 'string?' are only valid as properties in an object or tuple" : isDefaultable<C, $, bindThis<C>> extends true ? "Defaultable definitions like 'number = 0' are only valid as properties in an object or tuple" : validateInnerDefinition<C, $, bindThis<C>>
Returns
Section titled “Returns”NameableBuilder<TPattern, $, ExprSchema<C, "operand">>
Call Signature
Section titled “Call Signature”operand<
B>(constraint):NameableBuilder<TPattern,$,ExprSchema<OverlapsRef<B>,"operand">>
Defined in: src/schema/index.ts:320
Type Parameters
Section titled “Type Parameters”B extends string
Parameters
Section titled “Parameters”constraint
Section titled “constraint”OverlapsRef<ValidateOverlapsTarget<B, $>>
Returns
Section titled “Returns”NameableBuilder<TPattern, $, ExprSchema<OverlapsRef<B>, "operand">>
rest()
Section titled “rest()”Call Signature
Section titled “Call Signature”rest():
NameableBuilder<TPattern,$,ExprSchema<undefined,"rest">>
Defined in: src/schema/index.ts:333
Append a CURRENT-LEVEL expression element.
Parses at the same level. A pattern whose final operand is rest()
makes its level RIGHT-associative (a ^ b ^ c → a ^ (b ^ c)).
Constraint forms: rest(“number”), rest(“left”), rest(“left | null”), rest(overlapping(“left”)), rest().
Returns
Section titled “Returns”NameableBuilder<TPattern, $, ExprSchema<undefined, "rest">>
Call Signature
Section titled “Call Signature”rest<
C>(constraint):NameableBuilder<TPattern,$,ExprSchema<C,"rest">>
Defined in: src/schema/index.ts:334
Type Parameters
Section titled “Type Parameters”C extends string
Parameters
Section titled “Parameters”constraint
Section titled “constraint”[C] extends [" anyOrNever"] ? C : C extends OptionalPropertyDefinition ? "Optional definitions like 'string?' are only valid as properties in an object or tuple" : isDefaultable<C, $, bindThis<C>> extends true ? "Defaultable definitions like 'number = 0' are only valid as properties in an object or tuple" : validateInnerDefinition<C, $, bindThis<C>>
Returns
Section titled “Returns”NameableBuilder<TPattern, $, ExprSchema<C, "rest">>
Call Signature
Section titled “Call Signature”rest<
B>(constraint):NameableBuilder<TPattern,$,ExprSchema<OverlapsRef<B>,"rest">>
Defined in: src/schema/index.ts:337
Type Parameters
Section titled “Type Parameters”B extends string
Parameters
Section titled “Parameters”constraint
Section titled “constraint”OverlapsRef<ValidateOverlapsTarget<B, $>>
Returns
Section titled “Returns”NameableBuilder<TPattern, $, ExprSchema<OverlapsRef<B>, "rest">>
expr()
Section titled “expr()”Call Signature
Section titled “Call Signature”expr():
NameableBuilder<TPattern,$,ExprSchema<undefined,"expr">>
Defined in: src/schema/index.ts:349
Append a FULL expression element.
Resets to the full grammar (precedence 0). Only for DELIMITED contexts — every expr() must be followed by at least one constVal in the same pattern (parentheses’ “)”, ternary’s “:”), otherwise it would swallow looser operators and break precedence.
Returns
Section titled “Returns”NameableBuilder<TPattern, $, ExprSchema<undefined, "expr">>
Call Signature
Section titled “Call Signature”expr<
C>(constraint):NameableBuilder<TPattern,$,ExprSchema<C,"expr">>
Defined in: src/schema/index.ts:350
Type Parameters
Section titled “Type Parameters”C extends string
Parameters
Section titled “Parameters”constraint
Section titled “constraint”[C] extends [" anyOrNever"] ? C : C extends OptionalPropertyDefinition ? "Optional definitions like 'string?' are only valid as properties in an object or tuple" : isDefaultable<C, $, bindThis<C>> extends true ? "Defaultable definitions like 'number = 0' are only valid as properties in an object or tuple" : validateInnerDefinition<C, $, bindThis<C>>
Returns
Section titled “Returns”NameableBuilder<TPattern, $, ExprSchema<C, "expr">>
Call Signature
Section titled “Call Signature”expr<
B>(constraint):NameableBuilder<TPattern,$,ExprSchema<OverlapsRef<B>,"expr">>
Defined in: src/schema/index.ts:353
Type Parameters
Section titled “Type Parameters”B extends string
Parameters
Section titled “Parameters”constraint
Section titled “constraint”OverlapsRef<ValidateOverlapsTarget<B, $>>
Returns
Section titled “Returns”NameableBuilder<TPattern, $, ExprSchema<OverlapsRef<B>, "expr">>
result()
Section titled “result()”result<
R>(def):ResultedBuilder<TPattern,R>
Defined in: src/schema/index.ts:369
Declare the node’s result type (trailing — after the last element):
- a binding name (“then”) — derived per-parse from that operand
- an arktype def (“boolean”, { min: “number”, max: “number” }) — the node mints a type; defs may EMBED binding references (“then | null”), resolved per-parse
Validated by arktype with the chain’s bindings in scope. Required for every node that CONSTRUCTS a result; only a single-element passthrough pattern omits it. (The “~resolved” key is reserved — enforced at construction.)
Type Parameters
Section titled “Type Parameters”R extends ResultSpec
Parameters
Section titled “Parameters”[R] extends [" anyOrNever"] ? R : R extends OptionalPropertyDefinition ? "Optional definitions like 'string?' are only valid as properties in an object or tuple" : isDefaultable<R, $, bindThis<R>> extends true ? "Defaultable definitions like 'number = 0' are only valid as properties in an object or tuple" : validateInnerDefinition<R, $, bindThis<R>>
Returns
Section titled “Returns”ResultedBuilder<TPattern, R>