UNPKG

functionalscript

Version:

FunctionalScript is a purely functional subset of JavaScript

64 lines (63 loc) 2.67 kB
import { type Array2 } from '../types/array/module.f.ts'; /** * A range of symbols (48 bits) * For example: 0xBBBBBB_EEEEEE * - 0xBBBBBB is the first symbol * - 0xEEEEEE is the last symbol */ export type TerminalRange = number; /** A sequence of rules. */ export type Sequence = readonly Rule[]; /** A variant */ export type Variant = { readonly [k in string]: Rule; }; export type DataRule = Variant | Sequence | TerminalRange | string; export type LazyRule = () => DataRule; export type Rule = DataRule | LazyRule; export declare const max: string; export declare const rangeEncode: (a: number, b: number) => TerminalRange; export declare const oneEncode: (a: number) => TerminalRange; export declare const rangeDecode: (r: number) => Array2<number>; export declare const toSequence: (s: string) => readonly TerminalRange[]; export declare const str: (s: string) => readonly TerminalRange[] | TerminalRange; export declare const set: (s: string) => RangeVariant; export declare const range: (ab: string) => TerminalRange; /** * A set of terminal ranges compatible with the `Variant` rule. */ export type RangeVariant = { readonly [k in string]: TerminalRange; }; export declare const rangeToId: (r: TerminalRange) => string; export declare const remove: (range: TerminalRange, removeSet: RangeVariant) => RangeVariant; export type None = readonly []; export declare const none: None; export type Option<S> = { none: None; some: S; }; export declare const option: <S extends Rule>(some: S) => Option<S>; export type Repeat0Plus<T> = () => Option<readonly [T, Repeat0Plus<T>]>; /** * Repeat zero or more times. * * https://english.stackexchange.com/questions/506480/single-word-quantifiers-for-zero-or-more-like-cardinalities * - zero or more - any, 0Plus * - one or more - several, 1Plus * * Also see: https://arbs.nzcer.org.nz/types-numbers */ export declare const repeat0Plus: <T extends Rule>(some: T) => Repeat0Plus<T>; export type Repeat1Plus<T> = readonly [T, Repeat0Plus<T>]; /** * Repeat one or more times. */ export declare const repeat1Plus: <T extends Rule>(some: T) => Repeat1Plus<T>; export type Join1Plus<T, S> = readonly [T, Repeat0Plus<readonly [S, T]>]; export declare const join1Plus: <T extends Rule, S extends Rule>(some: T, separator: S) => Join1Plus<T, S>; export type Join0Plus<T, S> = Option<readonly [T, Repeat0Plus<readonly [S, T]>]>; export declare const join0Plus: <T extends Rule, S extends Rule>(some: T, separator: S) => Rule; export type Repeat<T> = readonly T[]; export declare const repeat: (n: number) => <T extends Rule>(some: T) => Repeat<T>; export declare const isEmpty: (rule: Rule) => boolean;