UNPKG

functionalscript

Version:

FunctionalScript is a purely functional subset of JavaScript

99 lines (98 loc) 3.19 kB
import * as list from '../../types/list/module.f.ts'; import type * as bigfloatT from '../../types/bigfloat/module.f.ts'; export type StringToken = { readonly kind: 'string'; readonly value: string; }; export type NumberToken = { readonly kind: 'number'; readonly value: string; readonly bf: bigfloatT.BigFloat; }; export type BigIntToken = { readonly kind: 'bigint'; readonly value: bigint; }; export type ErrorToken = { readonly kind: 'error'; message: ErrorMessage; }; export type WhitespaceToken = { readonly kind: 'ws'; }; export type NewLineToken = { readonly kind: 'nl'; }; type TrueToken = { readonly kind: 'true'; }; type FalseToken = { readonly kind: 'false'; }; type NullToken = { readonly kind: 'null'; }; type UndefinedToken = { readonly kind: 'undefined'; }; type KeywordToken = { readonly kind: 'arguments' | 'await' | 'break' | 'case' | 'catch' | 'class' | 'const' | 'continue'; } | { readonly kind: 'debugger' | 'default' | 'delete' | 'do' | 'else' | 'enum' | 'eval' | 'export'; } | { readonly kind: 'extends' | 'finally' | 'for' | 'function' | 'if' | 'implements' | 'import' | 'in'; } | { readonly kind: 'instanceof' | 'interface' | 'let' | 'new' | 'package' | 'private' | 'protected' | 'public'; } | { readonly kind: 'return' | 'static' | 'super' | 'switch' | 'this' | 'throw' | 'try' | 'typeof'; } | { readonly kind: 'var' | 'void' | 'while' | 'with' | 'yield'; }; export type IdToken = { readonly kind: 'id'; readonly value: string; }; type OperatorToken = { readonly kind: '{' | '}' | ':' | ',' | '[' | ']'; } | { readonly kind: '.' | '='; } | { readonly kind: '(' | ')'; } | { readonly kind: '==' | '!=' | '===' | '!==' | '>' | '>=' | '<' | '<='; } | { readonly kind: '+' | '-' | '*' | '/' | '%' | '++' | '--' | '**'; } | { readonly kind: '+=' | '-=' | '*=' | '/=' | '%=' | '**='; } | { readonly kind: '&' | '|' | '^' | '~' | '<<' | '>>' | '>>>'; } | { readonly kind: '&=' | '|=' | '^=' | '<<=' | '>>=' | '>>>='; } | { readonly kind: '&&' | '||' | '!' | '??'; } | { readonly kind: '&&=' | '||=' | '??='; } | { readonly kind: '?' | '?.' | '=>'; }; export type CommentToken = { readonly kind: '//' | '/*'; readonly value: string; }; export type EofToken = { readonly kind: 'eof'; }; export type JsToken = KeywordToken | TrueToken | FalseToken | NullToken | WhitespaceToken | NewLineToken | StringToken | NumberToken | ErrorToken | IdToken | BigIntToken | UndefinedToken | OperatorToken | CommentToken | EofToken; export type TokenMetadata = { readonly path: string; readonly line: number; readonly column: number; }; export type JsTokenWithMetadata = { readonly token: JsToken; readonly metadata: TokenMetadata; }; type ErrorMessage = '" are missing' | 'unescaped character' | 'invalid hex value' | 'unexpected character' | 'invalid number' | 'invalid token' | '*\/ expected' | 'unterminated string literal' | 'eof'; export declare const isKeywordToken: (token: JsToken) => boolean; export declare const tokenize: (input: list.List<number>) => (path: string) => list.List<JsTokenWithMetadata>; export {};