@mojir/lits 2.1.24 → 2.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/cli.js +10140 -10013
- package/dist/cli/reference/api.d.ts +6 -3
- package/dist/cli/reference/categories/meta.d.ts +3 -0
- package/dist/cli/reference/index.d.ts +622 -620
- package/dist/cli/src/Lits/Lits.d.ts +3 -2
- package/dist/cli/src/builtin/interface.d.ts +4 -5
- package/dist/cli/src/builtin/normalExpressions/categories/meta.d.ts +3 -0
- package/dist/cli/src/builtin/normalExpressions/index.d.ts +3 -0
- package/dist/cli/src/builtin/specialExpressions/functions.d.ts +2 -2
- package/dist/cli/src/parser/Parser.d.ts +1 -0
- package/dist/cli/src/parser/types.d.ts +5 -2
- package/dist/cli/src/tokenizer/token.d.ts +4 -2
- package/dist/cli/src/tokenizer/tokenizers.d.ts +3 -2
- package/dist/cli/src/typeGuards/index.d.ts +0 -4
- package/dist/cli/src/utils/arity.d.ts +10 -0
- package/dist/cli/src/utils/docString/generateDocString.d.ts +2 -0
- package/dist/cli/src/utils/index.d.ts +1 -0
- package/dist/index.esm.js +9937 -9810
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +9937 -9810
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +9923 -9796
- package/dist/lits.iife.js.map +1 -1
- package/dist/reference/api.d.ts +6 -3
- package/dist/reference/categories/meta.d.ts +3 -0
- package/dist/reference/index.d.ts +622 -620
- package/dist/src/Lits/Lits.d.ts +3 -2
- package/dist/src/builtin/interface.d.ts +4 -5
- package/dist/src/builtin/normalExpressions/categories/meta.d.ts +3 -0
- package/dist/src/builtin/normalExpressions/index.d.ts +3 -0
- package/dist/src/builtin/specialExpressions/functions.d.ts +2 -2
- package/dist/src/index.d.ts +1 -1
- package/dist/src/parser/Parser.d.ts +1 -0
- package/dist/src/parser/types.d.ts +5 -2
- package/dist/src/tokenizer/token.d.ts +4 -2
- package/dist/src/tokenizer/tokenizers.d.ts +3 -2
- package/dist/src/typeGuards/index.d.ts +0 -4
- package/dist/src/utils/arity.d.ts +10 -0
- package/dist/src/utils/docString/generateDocString.d.ts +2 -0
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/testFramework.esm.js +16791 -746
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +16791 -746
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
- package/dist/cli/src/utils/paramCount.d.ts +0 -7
- package/dist/src/utils/paramCount.d.ts +0 -7
|
@@ -3,7 +3,7 @@ import type { Any } from '../interface';
|
|
|
3
3
|
import type { Ast, LitsFunction } from '../parser/types';
|
|
4
4
|
import type { TokenStream } from '../tokenizer/tokenize';
|
|
5
5
|
import { AutoCompleter } from '../AutoCompleter/AutoCompleter';
|
|
6
|
-
import type {
|
|
6
|
+
import type { Arity } from '../builtin/interface';
|
|
7
7
|
import { Cache } from './Cache';
|
|
8
8
|
export interface LitsRuntimeInfo {
|
|
9
9
|
astCache: Cache | null;
|
|
@@ -12,7 +12,8 @@ export interface LitsRuntimeInfo {
|
|
|
12
12
|
}
|
|
13
13
|
export interface JsFunction {
|
|
14
14
|
fn: (...args: any[]) => unknown;
|
|
15
|
-
|
|
15
|
+
arity?: Arity;
|
|
16
|
+
docString?: string;
|
|
16
17
|
}
|
|
17
18
|
export interface ContextParams {
|
|
18
19
|
globalContext?: Context;
|
|
@@ -5,18 +5,17 @@ import type { Any, Arr } from '../interface';
|
|
|
5
5
|
import type { SpecialExpressionNode } from '../parser/types';
|
|
6
6
|
import type { SourceCodeInfo } from '../tokenizer/token';
|
|
7
7
|
import type { SpecialExpressions } from '.';
|
|
8
|
-
export type
|
|
8
|
+
export type Arity = {
|
|
9
9
|
min?: number;
|
|
10
10
|
max?: number;
|
|
11
|
-
even?: true;
|
|
12
|
-
odd?: true;
|
|
13
11
|
};
|
|
14
12
|
export type NormalExpressionEvaluator<T> = (params: Arr, sourceCodeInfo: SourceCodeInfo | undefined, contextStack: ContextStack, { executeFunction }: {
|
|
15
13
|
executeFunction: ExecuteFunction;
|
|
16
14
|
}) => T;
|
|
17
15
|
export interface BuiltinNormalExpression<T> {
|
|
18
16
|
evaluate: NormalExpressionEvaluator<T>;
|
|
19
|
-
|
|
17
|
+
name?: string;
|
|
18
|
+
arity: Arity;
|
|
20
19
|
aliases?: string[];
|
|
21
20
|
}
|
|
22
21
|
export type BuiltinNormalExpressions = Record<string, BuiltinNormalExpression<Any>>;
|
|
@@ -29,7 +28,7 @@ export interface EvaluateHelpers {
|
|
|
29
28
|
export interface BuiltinSpecialExpression<T, N extends SpecialExpressionNode> {
|
|
30
29
|
evaluate: (node: N, contextStack: ContextStack, helpers: EvaluateHelpers) => T;
|
|
31
30
|
evaluateAsNormalExpression?: NormalExpressionEvaluator<T>;
|
|
32
|
-
|
|
31
|
+
arity: Arity;
|
|
33
32
|
getUndefinedSymbols: (node: N, contextStack: ContextStack, params: {
|
|
34
33
|
getUndefinedSymbols: GetUndefinedSymbols;
|
|
35
34
|
builtin: Builtin;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { BuiltinNormalExpression, BuiltinNormalExpressions } from '../interface';
|
|
2
2
|
import type { Any } from '../../interface';
|
|
3
|
+
import type { FunctionReference } from '../../../reference';
|
|
4
|
+
import type { NormalExpressionName } from '../../../reference/api';
|
|
5
|
+
export declare function setNormalExpressionReference(reference: Record<NormalExpressionName, FunctionReference>): void;
|
|
3
6
|
export declare const normalExpressions: BuiltinNormalExpressions;
|
|
4
7
|
export declare const normalExpressionTypes: Record<string, number>;
|
|
5
8
|
export declare const allNormalExpressions: BuiltinNormalExpression<Any>[];
|
|
@@ -2,8 +2,8 @@ import { type LitsFunction, type SpecialExpressionNode, type SymbolNode } from '
|
|
|
2
2
|
import type { BuiltinSpecialExpression } from '../interface';
|
|
3
3
|
import type { Function } from '../utils';
|
|
4
4
|
import type { specialExpressionTypes } from '../specialExpressionTypes';
|
|
5
|
-
export type DefnNode = SpecialExpressionNode<[typeof specialExpressionTypes['0_defn'], SymbolNode, Function]>;
|
|
6
|
-
export type FunctionNode = SpecialExpressionNode<[typeof specialExpressionTypes['function'], SymbolNode, Function]>;
|
|
5
|
+
export type DefnNode = SpecialExpressionNode<[typeof specialExpressionTypes['0_defn'], SymbolNode, Function, string]>;
|
|
6
|
+
export type FunctionNode = SpecialExpressionNode<[typeof specialExpressionTypes['function'], SymbolNode, Function, string]>;
|
|
7
7
|
export type FnNode = SpecialExpressionNode<[typeof specialExpressionTypes['0_fn'], Function]>;
|
|
8
8
|
export declare const functionSpecialExpression: BuiltinSpecialExpression<LitsFunction, FunctionNode>;
|
|
9
9
|
export declare const defnSpecialExpression: BuiltinSpecialExpression<LitsFunction, DefnNode>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { JsFunction } from '../Lits/Lits';
|
|
2
2
|
import type { SpecialExpressionType } from '../builtin';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Arity } from '../builtin/interface';
|
|
4
4
|
import type { specialExpressionTypes } from '../builtin/specialExpressionTypes';
|
|
5
5
|
import type { FunctionType, NodeType, NodeTypes } from '../constants/constants';
|
|
6
6
|
import type { Context } from '../evaluator/interface';
|
|
@@ -16,7 +16,7 @@ interface GenericLitsFunction {
|
|
|
16
16
|
[FUNCTION_SYMBOL]: true;
|
|
17
17
|
sourceCodeInfo?: SourceCodeInfo;
|
|
18
18
|
functionType: FunctionType;
|
|
19
|
-
|
|
19
|
+
arity: Arity;
|
|
20
20
|
}
|
|
21
21
|
export interface RegularExpression {
|
|
22
22
|
[REGEXP_SYMBOL]: true;
|
|
@@ -28,11 +28,13 @@ export interface NativeJsFunction extends GenericLitsFunction {
|
|
|
28
28
|
functionType: 'NativeJsFunction';
|
|
29
29
|
name: string | undefined;
|
|
30
30
|
nativeFn: JsFunction;
|
|
31
|
+
docString: string;
|
|
31
32
|
}
|
|
32
33
|
export interface UserDefinedFunction extends GenericLitsFunction {
|
|
33
34
|
functionType: 'UserDefined';
|
|
34
35
|
name: string | undefined;
|
|
35
36
|
evaluatedfunction: EvaluatedFunction;
|
|
37
|
+
docString: string;
|
|
36
38
|
}
|
|
37
39
|
export interface PartialFunction extends GenericLitsFunction {
|
|
38
40
|
functionType: 'Partial';
|
|
@@ -72,6 +74,7 @@ export interface FNullFunction extends GenericLitsFunction {
|
|
|
72
74
|
export interface NormalBuiltinFunction extends GenericLitsFunction {
|
|
73
75
|
functionType: 'Builtin';
|
|
74
76
|
normalBuitinSymbolType: number;
|
|
77
|
+
name: string;
|
|
75
78
|
}
|
|
76
79
|
export interface SpecialBuiltinFunction extends GenericLitsFunction {
|
|
77
80
|
functionType: 'SpecialBuiltin';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReservedSymbol } from './reservedNames';
|
|
2
2
|
import { type SymbolicBinaryOperator, type SymbolicOperator } from './operators';
|
|
3
|
-
export declare const tokenTypes: readonly ["LBrace", "LBracket", "RBrace", "RBracket", "LParen", "RParen", "BasePrefixedNumber", "MultiLineComment", "Number", "Operator", "RegexpShorthand", "ReservedSymbol", "SingleLineComment", "String", "Symbol", "Whitespace"];
|
|
3
|
+
export declare const tokenTypes: readonly ["LBrace", "LBracket", "RBrace", "RBracket", "LParen", "RParen", "BasePrefixedNumber", "DocString", "MultiLineComment", "Number", "Operator", "RegexpShorthand", "ReservedSymbol", "SingleLineComment", "String", "Symbol", "Whitespace"];
|
|
4
4
|
export type TokenType = typeof tokenTypes[number];
|
|
5
5
|
declare const modifierNames: readonly ["&rest", "&let", "&when", "&while"];
|
|
6
6
|
export type ModifierName = typeof modifierNames[number];
|
|
@@ -19,9 +19,10 @@ export type RegexpShorthandToken = GenericToken<'RegexpShorthand'>;
|
|
|
19
19
|
export type ReservedSymbolToken<T extends ReservedSymbol = ReservedSymbol> = GenericToken<'ReservedSymbol', T>;
|
|
20
20
|
export type SingleLineCommentToken = GenericToken<'SingleLineComment'>;
|
|
21
21
|
export type StringToken = GenericToken<'String'>;
|
|
22
|
+
export type DocStringToken = GenericToken<'DocString'>;
|
|
22
23
|
export type SymbolToken<T extends string = string> = GenericToken<'Symbol', T>;
|
|
23
24
|
export type WhitespaceToken = GenericToken<'Whitespace'>;
|
|
24
|
-
export type Token = LBraceToken | LBracketToken | LParenToken | RBraceToken | RBracketToken | RParenToken | BasePrefixedNumberToken | MultiLineCommentToken | NumberToken | OperatorToken | RegexpShorthandToken | ReservedSymbolToken | SingleLineCommentToken | StringToken | SymbolToken | WhitespaceToken;
|
|
25
|
+
export type Token = LBraceToken | LBracketToken | LParenToken | RBraceToken | RBracketToken | RParenToken | BasePrefixedNumberToken | DocStringToken | MultiLineCommentToken | NumberToken | OperatorToken | RegexpShorthandToken | ReservedSymbolToken | SingleLineCommentToken | StringToken | SymbolToken | WhitespaceToken;
|
|
25
26
|
export type TokenDescriptor<T extends Token> = [length: number, token?: T];
|
|
26
27
|
export interface SourceCodeInfo {
|
|
27
28
|
position: {
|
|
@@ -76,6 +77,7 @@ export declare function asRBraceToken(token: Token | undefined): RBraceToken;
|
|
|
76
77
|
export declare function isStringToken(token: Token | undefined): token is StringToken;
|
|
77
78
|
export declare function assertStringToken(token: Token | undefined): asserts token is StringToken;
|
|
78
79
|
export declare function asStringToken(token: Token | undefined): StringToken;
|
|
80
|
+
export declare function isDocStringToken(token: Token | undefined): token is DocStringToken;
|
|
79
81
|
export declare function isRegexpShorthandToken(token: Token | undefined): token is RegexpShorthandToken;
|
|
80
82
|
export declare function assertRegexpShorthandToken(token: Token | undefined): asserts token is RegexpShorthandToken;
|
|
81
83
|
export declare function asRegexpShorthandToken(token: Token | undefined): RegexpShorthandToken;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { BasePrefixedNumberToken, LBraceToken, LBracketToken, LParenToken, MultiLineCommentToken, NumberToken, OperatorToken, RBraceToken, RBracketToken, RParenToken, RegexpShorthandToken, ReservedSymbolToken, SingleLineCommentToken, StringToken, SymbolToken, Token, TokenDescriptor, WhitespaceToken } from './token';
|
|
1
|
+
import type { BasePrefixedNumberToken, DocStringToken, LBraceToken, LBracketToken, LParenToken, MultiLineCommentToken, NumberToken, OperatorToken, RBraceToken, RBracketToken, RParenToken, RegexpShorthandToken, ReservedSymbolToken, SingleLineCommentToken, StringToken, SymbolToken, Token, TokenDescriptor, WhitespaceToken } from './token';
|
|
2
2
|
export type Tokenizer<T extends Token> = (input: string, position: number) => TokenDescriptor<T>;
|
|
3
3
|
export declare const NO_MATCH: TokenDescriptor<never>;
|
|
4
|
+
export declare const tokenizeDocString: Tokenizer<DocStringToken>;
|
|
4
5
|
export declare const tokenizeWhitespace: Tokenizer<WhitespaceToken>;
|
|
5
6
|
export declare const tokenizeNumber: Tokenizer<NumberToken>;
|
|
6
7
|
export declare const tokenizeBasePrefixedNumber: Tokenizer<BasePrefixedNumberToken>;
|
|
@@ -9,4 +10,4 @@ export declare const tokenizeReservedSymbolToken: Tokenizer<ReservedSymbolToken>
|
|
|
9
10
|
export declare const tokenizeOperator: Tokenizer<OperatorToken>;
|
|
10
11
|
export declare const tokenizeMultiLineComment: Tokenizer<MultiLineCommentToken>;
|
|
11
12
|
export declare const tokenizeSingleLineComment: Tokenizer<SingleLineCommentToken>;
|
|
12
|
-
export declare const tokenizers: [Tokenizer<WhitespaceToken>, Tokenizer<MultiLineCommentToken>, Tokenizer<SingleLineCommentToken>, Tokenizer<ReservedSymbolToken>, Tokenizer<LParenToken>, Tokenizer<RParenToken>, Tokenizer<LBracketToken>, Tokenizer<RBracketToken>, Tokenizer<LBraceToken>, Tokenizer<RBraceToken>, Tokenizer<StringToken>, Tokenizer<RegexpShorthandToken>, Tokenizer<BasePrefixedNumberToken>, Tokenizer<NumberToken>, Tokenizer<OperatorToken>, Tokenizer<SymbolToken>];
|
|
13
|
+
export declare const tokenizers: [Tokenizer<WhitespaceToken>, Tokenizer<MultiLineCommentToken>, Tokenizer<SingleLineCommentToken>, Tokenizer<ReservedSymbolToken>, Tokenizer<LParenToken>, Tokenizer<RParenToken>, Tokenizer<LBracketToken>, Tokenizer<RBracketToken>, Tokenizer<LBraceToken>, Tokenizer<RBraceToken>, Tokenizer<DocStringToken>, Tokenizer<StringToken>, Tokenizer<RegexpShorthandToken>, Tokenizer<BasePrefixedNumberToken>, Tokenizer<NumberToken>, Tokenizer<OperatorToken>, Tokenizer<SymbolToken>];
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import type { ParamCount } from '../builtin/interface';
|
|
2
1
|
import type { UnknownRecord } from '../interface';
|
|
3
|
-
import type { NormalExpressionNodeWithName } from '../parser/types';
|
|
4
2
|
import type { SourceCodeInfo } from '../tokenizer/token';
|
|
5
|
-
export declare function assertNumberOfParams(count: ParamCount, node: NormalExpressionNodeWithName): void;
|
|
6
3
|
export declare function isNonUndefined<T>(value: T | undefined): value is T;
|
|
7
4
|
export declare function asNonUndefined<T>(value: T | undefined, sourceCodeInfo?: SourceCodeInfo): T;
|
|
8
5
|
export declare function assertNonUndefined<T>(value: T | undefined, sourceCodeInfo?: SourceCodeInfo): asserts value is T;
|
|
9
6
|
export declare function isUnknownRecord(value: unknown): value is Record<string, unknown>;
|
|
10
7
|
export declare function assertUnknownRecord(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is UnknownRecord;
|
|
11
8
|
export declare function asUnknownRecord(value: unknown, sourceCodeInfo?: SourceCodeInfo): UnknownRecord;
|
|
12
|
-
export declare function canBeOperator(count: ParamCount): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Arity } from '../builtin/interface';
|
|
2
|
+
import type { FunctionLike } from '../parser/types';
|
|
3
|
+
import type { SourceCodeInfo } from '../tokenizer/token';
|
|
4
|
+
export declare function arityAccepts(arity: Arity, nbrOfParams: number): boolean;
|
|
5
|
+
export declare function arityAcceptsMin(arity: Arity, nbrOfParams: number): boolean;
|
|
6
|
+
export declare function getCommonArityFromFunctions(params: FunctionLike[]): Arity | null;
|
|
7
|
+
export declare function getArityFromFunction(param: FunctionLike): Arity;
|
|
8
|
+
export declare function assertNumberOfParams(arity: Arity, length: number, sourceCodeInfo: SourceCodeInfo | undefined): void;
|
|
9
|
+
export declare function canBeOperator(count: Arity): boolean;
|
|
10
|
+
export declare function toFixedArity(arity: number): Arity;
|
|
@@ -11,3 +11,4 @@ export declare function addToSet<T>(target: Set<T>, source: Set<T>): void;
|
|
|
11
11
|
export declare const EPSILON = 1e-10;
|
|
12
12
|
export declare function approxEqual(a: number, b: number, epsilon?: number): boolean;
|
|
13
13
|
export declare function approxZero(value: number): boolean;
|
|
14
|
+
export declare function smartTrim(str: string, minIndent?: number): string;
|