@mojir/lits 2.0.19 → 2.0.21
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 +339 -455
- package/dist/cli/src/Lits/Lits.d.ts +3 -1
- package/dist/cli/src/builtin/interface.d.ts +9 -5
- package/dist/cli/src/parser/index.d.ts +1 -2
- package/dist/cli/src/parser/interface.d.ts +0 -1
- package/dist/cli/src/tokenizer/algebraic/algebraicTokenizers.d.ts +1 -1
- package/dist/cli/src/tokenizer/algebraic/algebraicTokens.d.ts +2 -2
- package/dist/cli/src/tokenizer/common/commonTokenizers.d.ts +2 -2
- package/dist/cli/src/tokenizer/common/commonTokens.d.ts +2 -14
- package/dist/cli/src/tokenizer/minifyTokenStream.d.ts +2 -0
- package/dist/cli/src/tokenizer/polish/polishTokenizers.d.ts +1 -1
- package/dist/cli/src/tokenizer/polish/polishTokens.d.ts +2 -2
- package/dist/cli/src/tokenizer/tokens.d.ts +2 -2
- package/dist/cli/src/typeGuards/index.d.ts +1 -7
- package/dist/index.esm.js +338 -454
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +338 -454
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +338 -454
- package/dist/lits.iife.js.map +1 -1
- package/dist/src/Lits/Lits.d.ts +3 -1
- package/dist/src/builtin/interface.d.ts +9 -5
- package/dist/src/parser/index.d.ts +1 -2
- package/dist/src/parser/interface.d.ts +0 -1
- package/dist/src/tokenizer/algebraic/algebraicTokenizers.d.ts +1 -1
- package/dist/src/tokenizer/algebraic/algebraicTokens.d.ts +2 -2
- package/dist/src/tokenizer/common/commonTokenizers.d.ts +2 -2
- package/dist/src/tokenizer/common/commonTokens.d.ts +2 -14
- package/dist/src/tokenizer/minifyTokenStream.d.ts +2 -0
- package/dist/src/tokenizer/polish/polishTokenizers.d.ts +1 -1
- package/dist/src/tokenizer/polish/polishTokens.d.ts +2 -2
- package/dist/src/tokenizer/tokens.d.ts +2 -2
- package/dist/src/typeGuards/index.d.ts +1 -7
- package/dist/testFramework.esm.js +448 -564
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +448 -564
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
package/dist/src/Lits/Lits.d.ts
CHANGED
|
@@ -40,7 +40,9 @@ export declare class Lits {
|
|
|
40
40
|
run(program: string, params?: LitsParams): unknown;
|
|
41
41
|
context(program: string, params?: LitsParams): Context;
|
|
42
42
|
analyze(program: string, params?: LitsParams): Analysis;
|
|
43
|
-
tokenize(program: string, tokenizeParams?: Pick<TokenizeParams, 'filePath'>
|
|
43
|
+
tokenize(program: string, tokenizeParams?: Pick<TokenizeParams, 'filePath'> & {
|
|
44
|
+
minify?: boolean;
|
|
45
|
+
}): TokenStream;
|
|
44
46
|
parse(tokenStream: TokenStream): Ast;
|
|
45
47
|
evaluate(ast: Ast, params: LitsParams): Any;
|
|
46
48
|
transform(tokenStream: TokenStream, transformer: (name: string) => string): TokenStream;
|
|
@@ -2,18 +2,22 @@ import type { FindUnresolvedIdentifiers, UnresolvedIdentifiers } from '../analyz
|
|
|
2
2
|
import type { ContextStack } from '../evaluator/ContextStack';
|
|
3
3
|
import type { EvaluateAstNode, ExecuteFunction } from '../evaluator/interface';
|
|
4
4
|
import type { Any, Arr } from '../interface';
|
|
5
|
-
import type {
|
|
5
|
+
import type { ParseArgument, ParseBinding, ParseBindings, ParseExpression, ParseState, ParseToken, ParseTokensUntilClosingBracket } from '../parser/interface';
|
|
6
6
|
import type { SourceCodeInfo, TokenStream } from '../tokenizer/interface';
|
|
7
7
|
import type { Token } from '../tokenizer/tokens';
|
|
8
8
|
import type { BuiltinSpecialExpressions, SpecialExpressionNode } from '.';
|
|
9
|
+
export type Count = number | {
|
|
10
|
+
min?: number;
|
|
11
|
+
max?: number;
|
|
12
|
+
even?: boolean;
|
|
13
|
+
odd?: boolean;
|
|
14
|
+
};
|
|
9
15
|
export type NormalExpressionEvaluator<T> = (params: Arr, sourceCodeInfo: SourceCodeInfo | undefined, contextStack: ContextStack, { executeFunction }: {
|
|
10
16
|
executeFunction: ExecuteFunction;
|
|
11
17
|
}) => T;
|
|
12
|
-
type ValidateNormalExpressionNode = (node: NormalExpressionNode) => void;
|
|
13
|
-
type ValidateSpecialExpressionNode = (node: SpecialExpressionNode) => void;
|
|
14
18
|
interface BuiltinNormalExpression<T> {
|
|
15
19
|
evaluate: NormalExpressionEvaluator<T>;
|
|
16
|
-
|
|
20
|
+
paramCount: Count;
|
|
17
21
|
}
|
|
18
22
|
export interface ParserHelpers {
|
|
19
23
|
parseExpression: ParseExpression;
|
|
@@ -31,7 +35,7 @@ interface EvaluateHelpers {
|
|
|
31
35
|
export interface BuiltinSpecialExpression<T, N extends SpecialExpressionNode> {
|
|
32
36
|
polishParse: (tokenStream: TokenStream, parseState: ParseState, firstToken: Token, parsers: ParserHelpers) => N;
|
|
33
37
|
evaluate: (node: N, contextStack: ContextStack, helpers: EvaluateHelpers) => T;
|
|
34
|
-
|
|
38
|
+
paramCount: Count;
|
|
35
39
|
findUnresolvedIdentifiers: (node: N, contextStack: ContextStack, params: {
|
|
36
40
|
findUnresolvedIdentifiers: FindUnresolvedIdentifiers;
|
|
37
41
|
builtin: Builtin;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { TokenStream } from '../tokenizer/interface';
|
|
2
|
-
import type { Ast
|
|
2
|
+
import type { Ast } from './interface';
|
|
3
3
|
export declare function parse(tokenStream: TokenStream): Ast;
|
|
4
|
-
export declare function parseToken(tokenStream: TokenStream, parseState: ParseState): AstNode;
|
|
@@ -11,7 +11,6 @@ import type { Token } from '../tokenizer/tokens';
|
|
|
11
11
|
import type { ModifierName } from '../tokenizer/polish/polishTokens';
|
|
12
12
|
export interface ParseState {
|
|
13
13
|
position: number;
|
|
14
|
-
algebraic: boolean;
|
|
15
14
|
parseToken: ParseToken;
|
|
16
15
|
}
|
|
17
16
|
export interface EvaluatedFunctionArguments {
|
|
@@ -8,4 +8,4 @@ export declare const tokenizeA_ReservedSymbolToken: Tokenizer<A_ReservedSymbolTo
|
|
|
8
8
|
export declare const tokenizeA_Operator: Tokenizer<A_OperatorToken>;
|
|
9
9
|
export declare const tokenizeA_MultiLineComment: Tokenizer<A_MultiLineCommentToken>;
|
|
10
10
|
export declare const tokenizeA_SingleLineComment: Tokenizer<A_SingleLineCommentToken>;
|
|
11
|
-
export declare const algebraicTokenizers: [Tokenizer<A_WhitespaceToken>, Tokenizer<A_MultiLineCommentToken>, Tokenizer<A_SingleLineCommentToken>, Tokenizer<import("../common/commonTokens").
|
|
11
|
+
export declare const algebraicTokenizers: [Tokenizer<A_WhitespaceToken>, Tokenizer<A_MultiLineCommentToken>, Tokenizer<A_SingleLineCommentToken>, Tokenizer<import("../common/commonTokens").LParenToken>, Tokenizer<import("../common/commonTokens").RParenToken>, Tokenizer<import("../common/commonTokens").LBracketToken>, Tokenizer<import("../common/commonTokens").RBracketToken>, Tokenizer<import("../common/commonTokens").LBraceToken>, Tokenizer<import("../common/commonTokens").RBraceToken>, Tokenizer<import("../common/commonTokens").StringToken>, Tokenizer<import("../common/commonTokens").RegexpShorthandToken>, Tokenizer<A_BasePrefixedNumberToken>, Tokenizer<A_NumberToken>, Tokenizer<A_OperatorToken>, Tokenizer<A_ReservedSymbolToken>, Tokenizer<A_SymbolToken>];
|
|
@@ -2,10 +2,10 @@ import type { CommonSimpleToken, CommonValueToken, CommonValueTokenType } from '
|
|
|
2
2
|
import type { Token } from '../tokens';
|
|
3
3
|
import { type TokenDebugData } from '../utils';
|
|
4
4
|
import type { ValidAlgebraicReservedName } from './algebraicReservedNames';
|
|
5
|
-
export declare const algebraicSimpleTokenTypes: readonly ["LBrace", "LBracket", "LParen", "RBrace", "RBracket", "RParen"
|
|
5
|
+
export declare const algebraicSimpleTokenTypes: readonly ["LBrace", "LBracket", "LParen", "RBrace", "RBracket", "RParen"];
|
|
6
6
|
export declare const algebraicOnlyValueTokenTypes: ["A_Whitespace", "A_Operator", "A_Symbol", "A_ReservedSymbol", "A_SingleLineComment", "A_MultiLineComment", "A_Number", "A_BasePrefixedNumber"];
|
|
7
7
|
export declare const algebraicValueTokenTypes: readonly ["String", "RegexpShorthand", "A_Whitespace", "A_Operator", "A_Symbol", "A_ReservedSymbol", "A_SingleLineComment", "A_MultiLineComment", "A_Number", "A_BasePrefixedNumber"];
|
|
8
|
-
export declare const algebraicTokenTypes: readonly ["LBrace", "LBracket", "LParen", "RBrace", "RBracket", "RParen", "
|
|
8
|
+
export declare const algebraicTokenTypes: readonly ["LBrace", "LBracket", "LParen", "RBrace", "RBracket", "RParen", "String", "RegexpShorthand", "A_Whitespace", "A_Operator", "A_Symbol", "A_ReservedSymbol", "A_SingleLineComment", "A_MultiLineComment", "A_Number", "A_BasePrefixedNumber"];
|
|
9
9
|
declare const symbolicUnaryOperators: readonly ["!", "~", "+", "-"];
|
|
10
10
|
declare const symbolicBinaryOperators: readonly ["**", "*", "/", "%", "+", "-", "<<", ">>", ">>>", "++", "<", "<=", ">", ">=", "==", "!=", "&", "^", "|", "&&", "||", "??"];
|
|
11
11
|
declare const symbolicOperators: readonly ["!", "~", "+", "-", "**", "*", "/", "%", "+", "-", "<<", ">>", ">>>", "++", "<", "<=", ">", ">=", "==", "!=", "&", "^", "|", "&&", "||", "??", "=>", "...", ".", ",", "=", ";"];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { TokenDescriptor, Tokenizer } from '../interface';
|
|
2
2
|
import type { SimpleToken } from '../tokens';
|
|
3
|
-
import type {
|
|
3
|
+
import type { LBraceToken, LBracketToken, LParenToken, RBraceToken, RBracketToken, RParenToken, RegexpShorthandToken, StringToken } from './commonTokens';
|
|
4
4
|
export declare const NO_MATCH: TokenDescriptor<never>;
|
|
5
5
|
export declare function isNoMatch(tokenDescriptor: TokenDescriptor<any>): tokenDescriptor is TokenDescriptor<never>;
|
|
6
6
|
export declare const tokenizeString: Tokenizer<StringToken>;
|
|
7
7
|
export declare const tokenizeRegexpShorthand: Tokenizer<RegexpShorthandToken>;
|
|
8
8
|
export declare function tokenizeSimpleToken<T extends SimpleToken>(type: T[0], value: string, input: string, position: number): TokenDescriptor<T>;
|
|
9
|
-
export declare const commonTokenizers: readonly [Tokenizer<
|
|
9
|
+
export declare const commonTokenizers: readonly [Tokenizer<LParenToken>, Tokenizer<RParenToken>, Tokenizer<LBracketToken>, Tokenizer<RBracketToken>, Tokenizer<LBraceToken>, Tokenizer<RBraceToken>, Tokenizer<StringToken>, Tokenizer<RegexpShorthandToken>];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type TokenDebugData } from '../utils';
|
|
2
2
|
import type { Token } from '../tokens';
|
|
3
|
-
export declare const commonSimpleTokenTypes: readonly ["LBrace", "LBracket", "LParen", "RBrace", "RBracket", "RParen"
|
|
3
|
+
export declare const commonSimpleTokenTypes: readonly ["LBrace", "LBracket", "LParen", "RBrace", "RBracket", "RParen"];
|
|
4
4
|
export declare const commomValueTokenTypes: readonly ["String", "RegexpShorthand"];
|
|
5
5
|
export type CommonSimpleTokenType = typeof commonSimpleTokenTypes[number];
|
|
6
6
|
export type CommonValueTokenType = typeof commomValueTokenTypes[number];
|
|
@@ -12,12 +12,9 @@ export type LBracketToken = GenericCommonSimpleToken<'LBracket'>;
|
|
|
12
12
|
export type RBracketToken = GenericCommonSimpleToken<'RBracket'>;
|
|
13
13
|
export type LBraceToken = GenericCommonSimpleToken<'LBrace'>;
|
|
14
14
|
export type RBraceToken = GenericCommonSimpleToken<'RBrace'>;
|
|
15
|
-
export type AlgebraicNotationToken = GenericCommonSimpleToken<'AlgNotation'>;
|
|
16
|
-
export type PolishNotationToken = GenericCommonSimpleToken<'PolNotation'>;
|
|
17
|
-
export type EndNotationToken = GenericCommonSimpleToken<'EndNotation'>;
|
|
18
15
|
export type StringToken = GenericCommonValueToken<'String'>;
|
|
19
16
|
export type RegexpShorthandToken = GenericCommonValueToken<'RegexpShorthand'>;
|
|
20
|
-
export type CommonSimpleToken = LParenToken | RParenToken | LBracketToken | RBracketToken | LBraceToken | RBraceToken
|
|
17
|
+
export type CommonSimpleToken = LParenToken | RParenToken | LBracketToken | RBracketToken | LBraceToken | RBraceToken;
|
|
21
18
|
export type CommonValueToken = StringToken | RegexpShorthandToken;
|
|
22
19
|
export declare function isLParenToken(token?: Token): token is LParenToken;
|
|
23
20
|
export declare function assertLParenToken(token?: Token): asserts token is LParenToken;
|
|
@@ -43,13 +40,4 @@ export declare function asStringToken(token?: Token): StringToken;
|
|
|
43
40
|
export declare function isRegexpShorthandToken(token?: Token): token is RegexpShorthandToken;
|
|
44
41
|
export declare function assertRegexpShorthandToken(token?: Token): asserts token is RegexpShorthandToken;
|
|
45
42
|
export declare function asRegexpShorthandToken(token?: Token): RegexpShorthandToken;
|
|
46
|
-
export declare function isAlgebraicNotationToken(token?: Token): token is AlgebraicNotationToken;
|
|
47
|
-
export declare function assertAlgebraicNotationToken(token?: Token): asserts token is AlgebraicNotationToken;
|
|
48
|
-
export declare function asAlgebraicNotationToken(token?: Token): AlgebraicNotationToken;
|
|
49
|
-
export declare function isPolishNotationToken(token?: Token): token is PolishNotationToken;
|
|
50
|
-
export declare function assertPolishNotationToken(token?: Token): asserts token is PolishNotationToken;
|
|
51
|
-
export declare function asPolishNotationToken(token?: Token): PolishNotationToken;
|
|
52
|
-
export declare function isEndNotationToken(token?: Token): token is EndNotationToken;
|
|
53
|
-
export declare function assertEndNotationToken(token?: Token): asserts token is EndNotationToken;
|
|
54
|
-
export declare function asEndNotationToken(token?: Token): EndNotationToken;
|
|
55
43
|
export {};
|
|
@@ -10,4 +10,4 @@ export declare const tokenizeP_FnShorthand: Tokenizer<P_FnShorthandToken>;
|
|
|
10
10
|
export declare const tokenizeP_ReservedSymbol: Tokenizer<P_ReservedSymbolToken>;
|
|
11
11
|
export declare const tokenizeP_Modifier: Tokenizer<P_ModifierToken>;
|
|
12
12
|
export declare const tokenizeP_CollectionAccessor: Tokenizer<P_CollectionAccessorToken>;
|
|
13
|
-
export declare const polishTokenizers: [Tokenizer<P_WhitespaceToken>, Tokenizer<P_CommentToken>, Tokenizer<import("../common/commonTokens").
|
|
13
|
+
export declare const polishTokenizers: [Tokenizer<P_WhitespaceToken>, Tokenizer<P_CommentToken>, Tokenizer<import("../common/commonTokens").LParenToken>, Tokenizer<import("../common/commonTokens").RParenToken>, Tokenizer<import("../common/commonTokens").LBracketToken>, Tokenizer<import("../common/commonTokens").RBracketToken>, Tokenizer<import("../common/commonTokens").LBraceToken>, Tokenizer<import("../common/commonTokens").RBraceToken>, Tokenizer<import("../common/commonTokens").StringToken>, Tokenizer<import("../common/commonTokens").RegexpShorthandToken>, Tokenizer<P_StringShorthandToken>, Tokenizer<P_NumberToken>, Tokenizer<P_ReservedSymbolToken>, Tokenizer<P_ModifierToken>, Tokenizer<P_SymbolToken>, Tokenizer<P_FnShorthandToken>, Tokenizer<P_CollectionAccessorToken>];
|
|
@@ -4,10 +4,10 @@ import { type TokenDebugData } from '../utils';
|
|
|
4
4
|
export declare const modifierNames: readonly ["&rest", "&let", "&when", "&while"];
|
|
5
5
|
export type ModifierName = typeof modifierNames[number];
|
|
6
6
|
export declare const polishOnlySimpleTokenTypes: ["P_FnShorthand"];
|
|
7
|
-
export declare const polishSimpleTokenTypes: readonly ["LBrace", "LBracket", "LParen", "RBrace", "RBracket", "RParen", "
|
|
7
|
+
export declare const polishSimpleTokenTypes: readonly ["LBrace", "LBracket", "LParen", "RBrace", "RBracket", "RParen", "P_FnShorthand"];
|
|
8
8
|
export declare const polishOnlyValueTokenTypes: ["P_Modifier", "P_StringShorthand", "P_Symbol", "P_ReservedSymbol", "P_CollectionAccessor", "P_Comment", "P_Whitespace", "P_Number"];
|
|
9
9
|
export declare const polishValueTokenTypes: readonly ["String", "RegexpShorthand", "P_Modifier", "P_StringShorthand", "P_Symbol", "P_ReservedSymbol", "P_CollectionAccessor", "P_Comment", "P_Whitespace", "P_Number"];
|
|
10
|
-
export declare const polishTokenTypes: readonly ["LBrace", "LBracket", "LParen", "RBrace", "RBracket", "RParen", "
|
|
10
|
+
export declare const polishTokenTypes: readonly ["LBrace", "LBracket", "LParen", "RBrace", "RBracket", "RParen", "P_FnShorthand", "String", "RegexpShorthand", "P_Modifier", "P_StringShorthand", "P_Symbol", "P_ReservedSymbol", "P_CollectionAccessor", "P_Comment", "P_Whitespace", "P_Number"];
|
|
11
11
|
export type PolishSimpleTokenType = typeof polishSimpleTokenTypes[number];
|
|
12
12
|
export type PolishValueTokenType = typeof polishValueTokenTypes[number];
|
|
13
13
|
export type PolishTokenType = typeof polishTokenTypes[number];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { CommonSimpleToken, CommonValueToken } from './common/commonTokens';
|
|
2
2
|
import type { AlgebraicOnlyValueToken } from './algebraic/algebraicTokens';
|
|
3
3
|
import type { PolishOnlySimpleToken, PolishOnlyValueToken } from './polish/polishTokens';
|
|
4
|
-
export declare const simpleTokenTypes: readonly ["LBrace", "LBracket", "LParen", "RBrace", "RBracket", "RParen", "
|
|
4
|
+
export declare const simpleTokenTypes: readonly ["LBrace", "LBracket", "LParen", "RBrace", "RBracket", "RParen", "P_FnShorthand"];
|
|
5
5
|
export declare const valueTokenTypes: readonly ["String", "RegexpShorthand", "A_Whitespace", "A_Operator", "A_Symbol", "A_ReservedSymbol", "A_SingleLineComment", "A_MultiLineComment", "A_Number", "A_BasePrefixedNumber", "P_Modifier", "P_StringShorthand", "P_Symbol", "P_ReservedSymbol", "P_CollectionAccessor", "P_Comment", "P_Whitespace", "P_Number"];
|
|
6
|
-
export declare const tokenTypes: readonly ["LBrace", "LBracket", "LParen", "RBrace", "RBracket", "RParen", "
|
|
6
|
+
export declare const tokenTypes: readonly ["LBrace", "LBracket", "LParen", "RBrace", "RBracket", "RParen", "P_FnShorthand", "String", "RegexpShorthand", "A_Whitespace", "A_Operator", "A_Symbol", "A_ReservedSymbol", "A_SingleLineComment", "A_MultiLineComment", "A_Number", "A_BasePrefixedNumber", "P_Modifier", "P_StringShorthand", "P_Symbol", "P_ReservedSymbol", "P_CollectionAccessor", "P_Comment", "P_Whitespace", "P_Number"];
|
|
7
7
|
export type TokenType = typeof tokenTypes[number];
|
|
8
8
|
export type SimpleToken = CommonSimpleToken | PolishOnlySimpleToken;
|
|
9
9
|
export type ValueToken = CommonValueToken | AlgebraicOnlyValueToken | PolishOnlyValueToken;
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
+
import type { Count } from '../builtin/interface';
|
|
1
2
|
import type { UnknownRecord } from '../interface';
|
|
2
3
|
import type { GenericNode } from '../parser/interface';
|
|
3
4
|
import type { SourceCodeInfo } from '../tokenizer/interface';
|
|
4
|
-
type Count = number | {
|
|
5
|
-
min?: number;
|
|
6
|
-
max?: number;
|
|
7
|
-
};
|
|
8
|
-
export declare function assertEvenNumberOfParams(node: GenericNode): void;
|
|
9
|
-
export declare function assertOddNumberOfParams(node: GenericNode): void;
|
|
10
5
|
export declare function assertNumberOfParams(count: Count, node: GenericNode): void;
|
|
11
6
|
export declare function isNonUndefined<T>(value: T | undefined): value is T;
|
|
12
7
|
export declare function asNonUndefined<T>(value: T | undefined, sourceCodeInfo?: SourceCodeInfo): T;
|
|
@@ -14,4 +9,3 @@ export declare function assertNonUndefined<T>(value: T | undefined, sourceCodeIn
|
|
|
14
9
|
export declare function isUnknownRecord(value: unknown): value is Record<string, unknown>;
|
|
15
10
|
export declare function assertUnknownRecord(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is UnknownRecord;
|
|
16
11
|
export declare function asUnknownRecord(value: unknown, sourceCodeInfo?: SourceCodeInfo): UnknownRecord;
|
|
17
|
-
export {};
|