createParser
createParser<
TNodes,TScope>(nodes,options?):Parser<ComputeGrammar<TNodes>,TNodes, { [name in string | number | symbol]: bootstrapAliases<TScope>[name] extends Def<def> ? inferDefinition<def, bootstrapAliases<TScope>, {}> : bootstrapAliases<TScope>[name] extends { t: g } ? bindGenericToScope<g, bootstrapAliases<TScope>> : bootstrapAliases<TScope>[name] }>
Defined in: src/createParser.ts:276
Create a type-safe parser from node schemas.
Type Parameters
Section titled “Type Parameters”TNodes
Section titled “TNodes”TNodes extends readonly NodeSchema<string, readonly PatternSchema[], number, ResultSpec | undefined>[]
TScope
Section titled “TScope”TScope extends ScopeAliases = { }
Parameters
Section titled “Parameters”TNodes
Tuple of node schemas defining the grammar
options?
Section titled “options?”scope?
Section titled “scope?”TScope
Extra type aliases available in constraints, resultTypes, and schemas (e.g. { Money: “number” })
Returns
Section titled “Returns”Parser<ComputeGrammar<TNodes>, TNodes, { [name in string | number | symbol]: bootstrapAliases<TScope>[name] extends Def<def> ? inferDefinition<def, bootstrapAliases<TScope>, {}> : bootstrapAliases<TScope>[name] extends { t: g } ? bindGenericToScope<g, bootstrapAliases<TScope>> : bootstrapAliases<TScope>[name] }>
Example
Section titled “Example”const parser = createParser([ternary, add, atoms] as const);const result = parser.safeParse(dynamic, { x: "number" });const sum = parser.evaluate("1+2", {}, {}); // 3