preserves/implementations/javascript/packages/schema/src/meta.ts

31 lines
930 B
TypeScript

import { Value, preserves } from '@preserves/core';
export type Input = Value<never>;
export function isValidToken(s: string, allowLeadingUnderscore = false): boolean {
if (allowLeadingUnderscore) {
return /^[a-zA-Z_][a-zA-Z_0-9]*$/.test(s);
} else {
return /^[a-zA-Z][a-zA-Z_0-9]*$/.test(s);
}
}
export const ANDSYM = Symbol.for('&');
export const DOT = Symbol.for('.');
export const DOTDOTDOT = Symbol.for('...');
export const EQUALS = Symbol.for('=');
export const ORSYM = Symbol.for('/');
export * from './schemaschema';
import { Schema, Pattern, $definitions } from './schemaschema';
export type Environment = Array<Schema>;
export function lookup(env: Environment, name: symbol): Pattern {
for (const s of env) {
const p = Schema._.details(s).get($definitions).get(name);
if (p !== void 0) return p;
}
throw new Error(preserves`Schema: unbound name ${name}`);
}