Add regex to reef #1

Merged
defunkt merged 11 commits from regex into main 2025-10-16 21:15:42 +00:00
Showing only changes of commit 82d727cc74 - Show all commits

View File

@ -11,13 +11,13 @@ export type Value =
| {
type: 'function',
params: string[],
defaults: Record<string, number>, // indices into constants
defaults: Record<string, number>, // indices into constants
body: number,
parentScope: Scope,
variadic: boolean,
named: boolean,
value: '<function>'
}
}
export type Dict = Map<string, Value>
@ -31,13 +31,17 @@ export type FunctionDef = {
}
export function toValue(v: any): Value /* throws */ {
if (v === null || v === undefined) return { type: 'null', value: null }
if (v === null || v === undefined)
return { type: 'null', value: null }
if (v && typeof v === 'object' && 'type' in v && 'value' in v) return v as Value
if (v && typeof v === 'object' && 'type' in v && 'value' in v)
return v as Value
if (Array.isArray(v)) return { type: 'array', value: v.map(toValue) }
if (Array.isArray(v))
return { type: 'array', value: v.map(toValue) }
if (v instanceof RegExp) return { type: 'regex', value: v }
if (v instanceof RegExp)
return { type: 'regex', value: v }
switch (typeof v) {
case 'boolean':