@mojir/lits 1.3.0 → 2.0.2
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/README.md +2 -1
- package/dist/cli/cli.js +2661 -1980
- package/dist/cli/reference/api.d.ts +2 -2
- package/dist/cli/src/Lits/Lits.d.ts +5 -1
- package/dist/cli/src/analyze/index.d.ts +1 -1
- package/dist/cli/src/builtin/index.d.ts +1 -1
- package/dist/cli/src/builtin/interface.d.ts +4 -3
- package/dist/cli/src/builtin/specialExpressions/functions.d.ts +2 -2
- package/dist/cli/src/builtin/specialExpressions/if-let.d.ts +1 -4
- package/dist/cli/src/builtin/specialExpressions/let.d.ts +1 -4
- package/dist/cli/src/builtin/specialExpressions/try.d.ts +2 -2
- package/dist/cli/src/constants/constants.d.ts +2 -17
- package/dist/cli/src/errors.d.ts +1 -1
- package/dist/cli/src/evaluator/ContextStack.d.ts +3 -3
- package/dist/cli/src/identifier.d.ts +4 -0
- package/dist/cli/src/index.d.ts +12 -6
- package/dist/cli/src/parser/AlgebraicParser.d.ts +17 -0
- package/dist/cli/src/parser/PolishTokenParsers.d.ts +3 -0
- package/dist/cli/src/parser/commonTokenParsers.d.ts +6 -0
- package/dist/cli/src/parser/index.d.ts +2 -1
- package/dist/cli/src/parser/interface.d.ts +26 -20
- package/dist/cli/src/removeCommentNodes/index.d.ts +1 -1
- package/dist/cli/src/tokenizer/algebraic/algebraicReservedNames.d.ts +8 -0
- package/dist/cli/src/tokenizer/algebraic/algebraicTokenizers.d.ts +10 -0
- package/dist/cli/src/tokenizer/algebraic/algebraicTokens.d.ts +47 -0
- package/dist/cli/src/tokenizer/common/commonTokenizers.d.ts +8 -0
- package/dist/cli/src/tokenizer/common/commonTokens.d.ts +51 -0
- package/dist/cli/src/tokenizer/index.d.ts +1 -8
- package/dist/cli/src/tokenizer/interface.d.ts +5 -18
- package/dist/cli/src/tokenizer/polish/polishReservedNames.d.ts +7 -0
- package/dist/cli/src/tokenizer/polish/polishTokenizers.d.ts +13 -0
- package/dist/cli/src/tokenizer/polish/polishTokens.d.ts +59 -0
- package/dist/cli/src/tokenizer/tokens.d.ts +20 -0
- package/dist/cli/src/tokenizer/utils.d.ts +9 -0
- package/dist/cli/src/transformer/index.d.ts +2 -0
- package/dist/cli/src/typeGuards/astNode.d.ts +4 -4
- package/dist/cli/src/typeGuards/index.d.ts +0 -1
- package/dist/cli/src/untokenizer/index.d.ts +2 -0
- package/dist/cli/src/utils/debug/debugTools.d.ts +0 -2
- package/dist/cli/src/utils/debug/getCodeMarker.d.ts +2 -0
- package/dist/index.esm.js +9078 -1569
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +9089 -1569
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +9089 -1569
- package/dist/lits.iife.js.map +1 -1
- package/dist/reference/api.d.ts +2 -2
- package/dist/src/Lits/Lits.d.ts +5 -1
- package/dist/src/analyze/index.d.ts +1 -1
- package/dist/src/builtin/index.d.ts +1 -1
- package/dist/src/builtin/interface.d.ts +4 -3
- package/dist/src/builtin/specialExpressions/functions.d.ts +2 -2
- package/dist/src/builtin/specialExpressions/if-let.d.ts +1 -4
- package/dist/src/builtin/specialExpressions/let.d.ts +1 -4
- package/dist/src/builtin/specialExpressions/try.d.ts +2 -2
- package/dist/src/constants/constants.d.ts +2 -17
- package/dist/src/errors.d.ts +1 -1
- package/dist/src/evaluator/ContextStack.d.ts +3 -3
- package/dist/src/identifier.d.ts +4 -0
- package/dist/src/index.d.ts +12 -6
- package/dist/src/parser/AlgebraicParser.d.ts +17 -0
- package/dist/src/parser/PolishTokenParsers.d.ts +3 -0
- package/dist/src/parser/commonTokenParsers.d.ts +6 -0
- package/dist/src/parser/index.d.ts +2 -1
- package/dist/src/parser/interface.d.ts +26 -20
- package/dist/src/removeCommentNodes/index.d.ts +1 -1
- package/dist/src/tokenizer/algebraic/algebraicReservedNames.d.ts +8 -0
- package/dist/src/tokenizer/algebraic/algebraicTokenizers.d.ts +10 -0
- package/dist/src/tokenizer/algebraic/algebraicTokens.d.ts +47 -0
- package/dist/src/tokenizer/common/commonTokenizers.d.ts +8 -0
- package/dist/src/tokenizer/common/commonTokens.d.ts +51 -0
- package/dist/src/tokenizer/index.d.ts +1 -8
- package/dist/src/tokenizer/interface.d.ts +5 -18
- package/dist/src/tokenizer/polish/polishReservedNames.d.ts +7 -0
- package/dist/src/tokenizer/polish/polishTokenizers.d.ts +13 -0
- package/dist/src/tokenizer/polish/polishTokens.d.ts +59 -0
- package/dist/src/tokenizer/tokens.d.ts +20 -0
- package/dist/src/tokenizer/utils.d.ts +9 -0
- package/dist/src/transformer/index.d.ts +2 -0
- package/dist/src/typeGuards/astNode.d.ts +4 -4
- package/dist/src/typeGuards/index.d.ts +0 -1
- package/dist/src/untokenizer/index.d.ts +2 -0
- package/dist/src/utils/debug/debugTools.d.ts +0 -2
- package/dist/src/utils/debug/getCodeMarker.d.ts +2 -0
- package/dist/testFramework.esm.js +2196 -1539
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +2196 -1539
- package/dist/testFramework.js.map +1 -1
- package/package.json +6 -5
- package/dist/cli/src/parser/parsers.d.ts +0 -4
- package/dist/cli/src/reservedNames.d.ts +0 -7
- package/dist/cli/src/tokenizer/tokenizers.d.ts +0 -20
- package/dist/cli/src/typeGuards/token.d.ts +0 -13
- package/dist/src/parser/parsers.d.ts +0 -4
- package/dist/src/reservedNames.d.ts +0 -7
- package/dist/src/tokenizer/tokenizers.d.ts +0 -20
- package/dist/src/typeGuards/token.d.ts +0 -13
|
@@ -10,7 +10,7 @@ export declare const api: {
|
|
|
10
10
|
readonly regularExpression: readonly ["regexp", "match", "replace"];
|
|
11
11
|
readonly specialExpressions: readonly ["and", "or", "def", "defs", "let", "if-let", "when-let", "when-first", "fn", "defn", "defns", "try", "throw", "if", "if-not", "cond", "when", "when-not", "comment", "do", "recur", "loop", "time!", "doseq", "for", "declared?", "??"];
|
|
12
12
|
readonly string: readonly ["subs", "string-repeat", "str", "number", "number-to-string", "lower-case", "upper-case", "trim", "trim-left", "trim-right", "pad-left", "pad-right", "split", "template", "to-char-code", "from-char-code", "encode-base64", "decode-base64", "encode-uri-component", "decode-uri-component", "join"];
|
|
13
|
-
readonly bitwise: readonly ["bit-shift-left", "bit-shift-right", "bit-not", "bit-and", "bit-and-not", "bit-or", "bit-xor", "bit-flip", "bit-clear", "bit-set", "bit-test"];
|
|
13
|
+
readonly bitwise: readonly ["bit-shift-left", "bit-shift-right", "unsigned-bit-shift-right", "bit-not", "bit-and", "bit-and-not", "bit-or", "bit-xor", "bit-flip", "bit-clear", "bit-set", "bit-test"];
|
|
14
14
|
readonly assert: readonly ["assert", "assert=", "assert-not=", "assert-equal", "assert-not-equal", "assert>", "assert<", "assert>=", "assert<=", "assert-true", "assert-false", "assert-truthy", "assert-falsy", "assert-nil", "assert-throws", "assert-throws-error", "assert-not-throws"];
|
|
15
15
|
readonly shorthand: ["_short_regexp", "_short_fn", "_short_string", "_short_dot", "_short_hash"];
|
|
16
16
|
readonly datatype: ["_type_number", "_type_string", "_type_object", "_type_array", "_type_boolean", "_type_function", "_type_integer", "_type_any", "_type_nil", "_type_collection", "_type_sequence", "_type_regexp", "_type_never"];
|
|
@@ -31,7 +31,7 @@ export type AssertApiName = typeof api.assert[number];
|
|
|
31
31
|
export type FunctionName = CollectionApiName | ArrayApiName | SequenceApiName | MathApiName | FunctionalApiName | MiscApiName | ObjectApiName | PredicateApiName | RegularExpressionApiName | SpecialExpressionsApiName | StringApiName | BitwiseApiName | AssertApiName;
|
|
32
32
|
export type ShorthandName = typeof api.shorthand[number];
|
|
33
33
|
export type DatatypeName = typeof api.datatype[number];
|
|
34
|
-
declare const apiNames: readonly ["count", "get", "get-in", "contains?", "has?", "has-some?", "has-every?", "assoc", "assoc-in", "concat", "not-empty", "every?", "not-every?", "any?", "not-any?", "update", "update-in", "array", "range", "repeat", "flatten", "mapcat", "nth", "push", "pop", "unshift", "shift", "slice", "reductions", "reduce", "reduce-right", "map", "filter", "position", "index-of", "some", "reverse", "first", "second", "last", "rest", "nthrest", "next", "nthnext", "cons", "take", "take-last", "take-while", "drop", "drop-last", "drop-while", "sort", "sort-by", "random-sample!", "rand-nth!", "shuffle!", "distinct", "remove", "remove-at", "split-at", "split-with", "frequencies", "group-by", "partition", "partition-all", "partition-by", "+", "-", "*", "/", "mod", "rem", "quot", "inc", "dec", "sqrt", "cbrt", "pow", "exp", "round", "trunc", "floor", "ceil", "min", "max", "abs", "sign", "positive-infinity", "negative-infinity", "max-safe-integer", "min-safe-integer", "max-value", "min-value", "epsilon", "nan", "e", "pi", "log", "log2", "log10", "rand!", "rand-int!", "sin", "cos", "tan", "asin", "acos", "atan", "sinh", "cosh", "tanh", "asinh", "acosh", "atanh", "apply", "identity", "partial", "comp", "constantly", "juxt", "complement", "every-pred", "some-pred", "fnil", "not=", "=", "<", ">", "<=", ">=", "not", "write!", "inst-ms!", "iso-date-time->inst-ms", "inst-ms->iso-date-time", "boolean", "compare", "lits-version!", "uuid!", "equal?", "json-parse", "json-stringify", "dissoc", "object", "keys", "vals", "entries", "find", "merge", "merge-with", "zipmap", "select-keys", "boolean?", "nil?", "number?", "string?", "function?", "integer?", "array?", "object?", "coll?", "seq?", "regexp?", "zero?", "pos?", "neg?", "even?", "odd?", "finite?", "nan?", "negative-infinity?", "positive-infinity?", "false?", "true?", "empty?", "not-empty?", "regexp", "match", "replace", "and", "or", "def", "defs", "let", "if-let", "when-let", "when-first", "fn", "defn", "defns", "try", "throw", "if", "if-not", "cond", "when", "when-not", "comment", "do", "recur", "loop", "time!", "doseq", "for", "declared?", "??", "subs", "string-repeat", "str", "number", "number-to-string", "lower-case", "upper-case", "trim", "trim-left", "trim-right", "pad-left", "pad-right", "split", "template", "to-char-code", "from-char-code", "encode-base64", "decode-base64", "encode-uri-component", "decode-uri-component", "join", "bit-shift-left", "bit-shift-right", "bit-not", "bit-and", "bit-and-not", "bit-or", "bit-xor", "bit-flip", "bit-clear", "bit-set", "bit-test", "assert", "assert=", "assert-not=", "assert-equal", "assert-not-equal", "assert>", "assert<", "assert>=", "assert<=", "assert-true", "assert-false", "assert-truthy", "assert-falsy", "assert-nil", "assert-throws", "assert-throws-error", "assert-not-throws", "_short_regexp", "_short_fn", "_short_string", "_short_dot", "_short_hash", "_type_number", "_type_string", "_type_object", "_type_array", "_type_boolean", "_type_function", "_type_integer", "_type_any", "_type_nil", "_type_collection", "_type_sequence", "_type_regexp", "_type_never"];
|
|
34
|
+
declare const apiNames: readonly ["count", "get", "get-in", "contains?", "has?", "has-some?", "has-every?", "assoc", "assoc-in", "concat", "not-empty", "every?", "not-every?", "any?", "not-any?", "update", "update-in", "array", "range", "repeat", "flatten", "mapcat", "nth", "push", "pop", "unshift", "shift", "slice", "reductions", "reduce", "reduce-right", "map", "filter", "position", "index-of", "some", "reverse", "first", "second", "last", "rest", "nthrest", "next", "nthnext", "cons", "take", "take-last", "take-while", "drop", "drop-last", "drop-while", "sort", "sort-by", "random-sample!", "rand-nth!", "shuffle!", "distinct", "remove", "remove-at", "split-at", "split-with", "frequencies", "group-by", "partition", "partition-all", "partition-by", "+", "-", "*", "/", "mod", "rem", "quot", "inc", "dec", "sqrt", "cbrt", "pow", "exp", "round", "trunc", "floor", "ceil", "min", "max", "abs", "sign", "positive-infinity", "negative-infinity", "max-safe-integer", "min-safe-integer", "max-value", "min-value", "epsilon", "nan", "e", "pi", "log", "log2", "log10", "rand!", "rand-int!", "sin", "cos", "tan", "asin", "acos", "atan", "sinh", "cosh", "tanh", "asinh", "acosh", "atanh", "apply", "identity", "partial", "comp", "constantly", "juxt", "complement", "every-pred", "some-pred", "fnil", "not=", "=", "<", ">", "<=", ">=", "not", "write!", "inst-ms!", "iso-date-time->inst-ms", "inst-ms->iso-date-time", "boolean", "compare", "lits-version!", "uuid!", "equal?", "json-parse", "json-stringify", "dissoc", "object", "keys", "vals", "entries", "find", "merge", "merge-with", "zipmap", "select-keys", "boolean?", "nil?", "number?", "string?", "function?", "integer?", "array?", "object?", "coll?", "seq?", "regexp?", "zero?", "pos?", "neg?", "even?", "odd?", "finite?", "nan?", "negative-infinity?", "positive-infinity?", "false?", "true?", "empty?", "not-empty?", "regexp", "match", "replace", "and", "or", "def", "defs", "let", "if-let", "when-let", "when-first", "fn", "defn", "defns", "try", "throw", "if", "if-not", "cond", "when", "when-not", "comment", "do", "recur", "loop", "time!", "doseq", "for", "declared?", "??", "subs", "string-repeat", "str", "number", "number-to-string", "lower-case", "upper-case", "trim", "trim-left", "trim-right", "pad-left", "pad-right", "split", "template", "to-char-code", "from-char-code", "encode-base64", "decode-base64", "encode-uri-component", "decode-uri-component", "join", "bit-shift-left", "bit-shift-right", "unsigned-bit-shift-right", "bit-not", "bit-and", "bit-and-not", "bit-or", "bit-xor", "bit-flip", "bit-clear", "bit-set", "bit-test", "assert", "assert=", "assert-not=", "assert-equal", "assert-not-equal", "assert>", "assert<", "assert>=", "assert<=", "assert-true", "assert-false", "assert-truthy", "assert-falsy", "assert-nil", "assert-throws", "assert-throws-error", "assert-not-throws", "_short_regexp", "_short_fn", "_short_string", "_short_dot", "_short_hash", "_type_number", "_type_string", "_type_object", "_type_array", "_type_boolean", "_type_function", "_type_integer", "_type_any", "_type_nil", "_type_collection", "_type_sequence", "_type_regexp", "_type_never"];
|
|
35
35
|
export type ApiName = typeof apiNames[number];
|
|
36
36
|
export declare function isApiName(arg: string): arg is ApiName;
|
|
37
37
|
export declare const categoryRecord: {
|
|
@@ -15,7 +15,6 @@ export interface LazyValue {
|
|
|
15
15
|
}
|
|
16
16
|
export interface JsFunction {
|
|
17
17
|
fn: (...args: any[]) => unknown;
|
|
18
|
-
[key: string]: unknown;
|
|
19
18
|
}
|
|
20
19
|
export interface LitsParams {
|
|
21
20
|
globalContext?: Context;
|
|
@@ -25,16 +24,19 @@ export interface LitsParams {
|
|
|
25
24
|
jsFunctions?: Record<string, JsFunction>;
|
|
26
25
|
filePath?: string;
|
|
27
26
|
debug?: boolean;
|
|
27
|
+
algebraic?: boolean;
|
|
28
28
|
}
|
|
29
29
|
interface LitsConfig {
|
|
30
30
|
initialCache?: Record<string, Ast>;
|
|
31
31
|
astCacheSize?: number | null;
|
|
32
32
|
debug?: boolean;
|
|
33
|
+
algebraic?: boolean;
|
|
33
34
|
}
|
|
34
35
|
export declare class Lits {
|
|
35
36
|
private astCache;
|
|
36
37
|
private astCacheSize;
|
|
37
38
|
private debug;
|
|
39
|
+
private algebraic;
|
|
38
40
|
constructor(config?: LitsConfig);
|
|
39
41
|
getRuntimeInfo(): LitsRuntimeInfo;
|
|
40
42
|
run(program: string, params?: LitsParams): unknown;
|
|
@@ -43,6 +45,8 @@ export declare class Lits {
|
|
|
43
45
|
tokenize(program: string, tokenizeParams?: TokenizeParams): TokenStream;
|
|
44
46
|
parse(tokenStream: TokenStream): Ast;
|
|
45
47
|
evaluate(ast: Ast, params: LitsParams): Any;
|
|
48
|
+
transform(tokenStream: TokenStream, transformer: (name: string) => string): TokenStream;
|
|
49
|
+
untokenize(tokenStream: TokenStream): string;
|
|
46
50
|
apply(fn: LitsFunction, fnParams: unknown[], params?: LitsParams): Any;
|
|
47
51
|
private generateAst;
|
|
48
52
|
}
|
|
@@ -2,7 +2,7 @@ import type { LitsParams } from '../Lits/Lits';
|
|
|
2
2
|
import type { Builtin } from '../builtin/interface';
|
|
3
3
|
import { type ContextStack } from '../evaluator/ContextStack';
|
|
4
4
|
import type { Ast, AstNode } from '../parser/interface';
|
|
5
|
-
import type { Token } from '../tokenizer/
|
|
5
|
+
import type { Token } from '../tokenizer/tokens';
|
|
6
6
|
export interface UnresolvedIdentifier {
|
|
7
7
|
symbol: string;
|
|
8
8
|
token: Token | undefined;
|
|
@@ -31,7 +31,7 @@ declare const specialExpressions: {
|
|
|
31
31
|
export type SpecialExpressionName = keyof typeof specialExpressions;
|
|
32
32
|
export type BuiltinSpecialExpressions = typeof specialExpressions;
|
|
33
33
|
export type BuiltinSpecialExpression = typeof specialExpressions[SpecialExpressionName];
|
|
34
|
-
export type SpecialExpressionNode = ReturnType<typeof specialExpressions[SpecialExpressionName]['parse']
|
|
34
|
+
export type SpecialExpressionNode = ReturnType<typeof specialExpressions[SpecialExpressionName]['parse']>;
|
|
35
35
|
export declare const builtin: Builtin;
|
|
36
36
|
export declare const normalExpressionKeys: string[];
|
|
37
37
|
export declare const specialExpressionKeys: string[];
|
|
@@ -2,8 +2,9 @@ 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 { NormalExpressionNode, ParseArgument, ParseBinding, ParseBindings, ParseExpression, ParseToken, ParseTokensUntilClosingBracket } from '../parser/interface';
|
|
6
|
-
import type { SourceCodeInfo,
|
|
5
|
+
import type { NormalExpressionNode, ParseArgument, ParseBinding, ParseBindings, ParseExpression, ParseState, ParseToken, ParseTokensUntilClosingBracket } from '../parser/interface';
|
|
6
|
+
import type { SourceCodeInfo, TokenStream } from '../tokenizer/interface';
|
|
7
|
+
import type { Token } from '../tokenizer/tokens';
|
|
7
8
|
import type { BuiltinSpecialExpressions, SpecialExpressionNode } from '.';
|
|
8
9
|
export type NormalExpressionEvaluator<T> = (params: Arr, sourceCodeInfo: SourceCodeInfo | undefined, contextStack: ContextStack, { executeFunction }: {
|
|
9
10
|
executeFunction: ExecuteFunction;
|
|
@@ -27,7 +28,7 @@ interface EvaluateHelpers {
|
|
|
27
28
|
builtin: Builtin;
|
|
28
29
|
}
|
|
29
30
|
export interface BuiltinSpecialExpression<T, N extends SpecialExpressionNode> {
|
|
30
|
-
parse: (tokenStream: TokenStream,
|
|
31
|
+
parse: (tokenStream: TokenStream, parseState: ParseState, firstToken: Token, parsers: ParserHelpers) => N;
|
|
31
32
|
evaluate: (node: N, contextStack: ContextStack, helpers: EvaluateHelpers) => T;
|
|
32
33
|
findUnresolvedIdentifiers: (node: N, contextStack: ContextStack, params: {
|
|
33
34
|
findUnresolvedIdentifiers: FindUnresolvedIdentifiers;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { AstNode, CommonSpecialExpressionNode, LitsFunction,
|
|
1
|
+
import type { AstNode, CommonSpecialExpressionNode, LitsFunction, SymbolNode } from '../../parser/interface';
|
|
2
2
|
import type { BuiltinSpecialExpression } from '../interface';
|
|
3
3
|
import type { FunctionOverload } from '../utils';
|
|
4
4
|
export interface DefnNode extends CommonSpecialExpressionNode<'defn'> {
|
|
5
|
-
f:
|
|
5
|
+
f: SymbolNode;
|
|
6
6
|
o: FunctionOverload[];
|
|
7
7
|
}
|
|
8
8
|
export interface DefnsNode extends CommonSpecialExpressionNode<'defns'> {
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import type { Any } from '../../interface';
|
|
2
|
-
import type { BindingNode, CommonSpecialExpressionNode
|
|
2
|
+
import type { BindingNode, CommonSpecialExpressionNode } from '../../parser/interface';
|
|
3
3
|
import type { BuiltinSpecialExpression } from '../interface';
|
|
4
4
|
export interface IfLetNode extends CommonSpecialExpressionNode<'if-let'> {
|
|
5
5
|
b: BindingNode;
|
|
6
|
-
debugData: CommonSpecialExpressionNode<'let'>['debugData'] & ({
|
|
7
|
-
bindingArray: NormalExpressionNode;
|
|
8
|
-
} | undefined);
|
|
9
6
|
}
|
|
10
7
|
export declare const ifLetSpecialExpression: BuiltinSpecialExpression<Any, IfLetNode>;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import type { Any } from '../../interface';
|
|
2
|
-
import type { BindingNode, CommonSpecialExpressionNode
|
|
2
|
+
import type { BindingNode, CommonSpecialExpressionNode } from '../../parser/interface';
|
|
3
3
|
import type { BuiltinSpecialExpression } from '../interface';
|
|
4
4
|
export interface LetNode extends CommonSpecialExpressionNode<'let'> {
|
|
5
5
|
bs: BindingNode[];
|
|
6
|
-
debugData: CommonSpecialExpressionNode<'let'>['debugData'] & ({
|
|
7
|
-
bindingArray: NormalExpressionNode;
|
|
8
|
-
} | undefined);
|
|
9
6
|
}
|
|
10
7
|
export declare const letSpecialExpression: BuiltinSpecialExpression<Any, LetNode>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Any } from '../../interface';
|
|
2
|
-
import type { AstNode, CommonSpecialExpressionNode,
|
|
2
|
+
import type { AstNode, CommonSpecialExpressionNode, SymbolNode } from '../../parser/interface';
|
|
3
3
|
import type { BuiltinSpecialExpression } from '../interface';
|
|
4
4
|
export interface TryNode extends CommonSpecialExpressionNode<'try'> {
|
|
5
|
-
e:
|
|
5
|
+
e: SymbolNode;
|
|
6
6
|
ce: AstNode;
|
|
7
7
|
}
|
|
8
8
|
export declare const trySpecialExpression: BuiltinSpecialExpression<Any, TryNode>;
|
|
@@ -3,9 +3,9 @@ export declare enum AstNodeType {
|
|
|
3
3
|
String = 202,
|
|
4
4
|
NormalExpression = 203,
|
|
5
5
|
SpecialExpression = 204,
|
|
6
|
-
|
|
6
|
+
Symbol = 205,
|
|
7
7
|
Modifier = 206,
|
|
8
|
-
|
|
8
|
+
ReservedSymbol = 207,
|
|
9
9
|
Binding = 208,
|
|
10
10
|
Argument = 209,
|
|
11
11
|
Partial = 210,
|
|
@@ -13,21 +13,6 @@ export declare enum AstNodeType {
|
|
|
13
13
|
}
|
|
14
14
|
export declare const astNodeTypeName: Map<AstNodeType, string>;
|
|
15
15
|
export declare function isAstNodeType(type: unknown): type is AstNodeType;
|
|
16
|
-
export declare enum TokenType {
|
|
17
|
-
Bracket = 101,
|
|
18
|
-
Number = 102,
|
|
19
|
-
Name = 103,
|
|
20
|
-
String = 104,
|
|
21
|
-
ReservedName = 105,
|
|
22
|
-
Modifier = 106,
|
|
23
|
-
RegexpShorthand = 107,
|
|
24
|
-
FnShorthand = 108,
|
|
25
|
-
CollectionAccessor = 109,
|
|
26
|
-
Comment = 110,
|
|
27
|
-
NewLine = 111
|
|
28
|
-
}
|
|
29
|
-
export declare const tokenTypeName: Map<TokenType, string>;
|
|
30
|
-
export declare function isTokenType(type: unknown): type is TokenType;
|
|
31
16
|
export declare enum FunctionType {
|
|
32
17
|
UserDefined = 301,
|
|
33
18
|
Partial = 302,
|
package/dist/cli/src/errors.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare class RecurSignal extends Error {
|
|
|
7
7
|
export declare class LitsError extends Error {
|
|
8
8
|
readonly sourceCodeInfo?: SourceCodeInfo;
|
|
9
9
|
readonly shortMessage: string;
|
|
10
|
-
constructor(message: string | Error, sourceCodeInfo
|
|
10
|
+
constructor(message: string | Error, sourceCodeInfo: SourceCodeInfo | undefined);
|
|
11
11
|
getCodeMarker(): string | undefined;
|
|
12
12
|
}
|
|
13
13
|
export declare class NotAFunctionError extends LitsError {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExtraData,
|
|
1
|
+
import type { ExtraData, NativeJsFunction, SymbolNode } from '../parser/interface';
|
|
2
2
|
import type { Any } from '../interface';
|
|
3
3
|
import type { LazyValue, LitsParams } from '../Lits/Lits';
|
|
4
4
|
import type { Context, LookUpResult } from './interface';
|
|
@@ -18,7 +18,7 @@ export declare class ContextStackImpl {
|
|
|
18
18
|
create(context: Context, extraData?: ExtraData): ContextStack;
|
|
19
19
|
clone(): ContextStack;
|
|
20
20
|
getValue(name: string): unknown;
|
|
21
|
-
lookUp(node:
|
|
22
|
-
evaluateName(node:
|
|
21
|
+
lookUp(node: SymbolNode): LookUpResult;
|
|
22
|
+
evaluateName(node: SymbolNode): Any;
|
|
23
23
|
}
|
|
24
24
|
export declare function createContextStack(params?: LitsParams): ContextStack;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const polishIdentifierCharacterClass = "[\\w@%^?=!$<>+*/:-]";
|
|
2
|
+
export declare const polishIdentifierFirstCharacterClass = "[a-zA-Z_@%^?=!$<>+*/-]";
|
|
3
|
+
export declare const algebraicIdentifierCharacterClass = "[\\w$:]";
|
|
4
|
+
export declare const algebraicIdentifierFirstCharacterClass = "[a-zA-Z_$]";
|
package/dist/cli/src/index.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
export { AstNodeType,
|
|
1
|
+
export { AstNodeType, FunctionType } from './constants/constants';
|
|
2
2
|
export { isBuiltinFunction, isLitsFunction, asLitsFunction, assertLitsFunction, isUserDefinedFunction, asUserDefinedFunction, assertUserDefinedFunction, isNativeJsFunction, asNativeJsFunction, assertNativeJsFunction, } from './typeGuards/litsFunction';
|
|
3
|
-
export type
|
|
3
|
+
export { type LitsFunction, type NativeJsFunction, type ExtraData } from './parser/interface';
|
|
4
4
|
export type { Context } from './evaluator/interface';
|
|
5
|
-
export type {
|
|
6
|
-
export type {
|
|
5
|
+
export type { Ast } from './parser/interface';
|
|
6
|
+
export type { SourceCodeInfo } from './tokenizer/interface';
|
|
7
|
+
export type { Token } from './tokenizer/tokens';
|
|
7
8
|
export { normalExpressionKeys, specialExpressionKeys } from './builtin';
|
|
8
|
-
export {
|
|
9
|
+
export { polishReservedNames } from './tokenizer/polish/polishReservedNames';
|
|
9
10
|
export { Lits } from './Lits/Lits';
|
|
10
11
|
export { type LitsError, isLitsError } from './errors';
|
|
11
|
-
export type { LitsParams, LitsRuntimeInfo, LazyValue } from './Lits/Lits';
|
|
12
|
+
export type { LitsParams, LitsRuntimeInfo, LazyValue, JsFunction } from './Lits/Lits';
|
|
12
13
|
export { createNativeJsFunction } from './utils';
|
|
14
|
+
export { apiReference, isDatatypeReference, isFunctionReference, isNormalExpressionArgument, isShorthandReference, isSpecialExpressionArgument, isTypedValue } from '../reference';
|
|
15
|
+
export type { Argument, CommonReference, DatatypeReference, FunctionReference, Reference, ShorthandReference } from '../reference';
|
|
16
|
+
export type { ApiName, FunctionName, ShorthandName, DatatypeName } from '../reference/api';
|
|
17
|
+
export { isApiName, isDataType } from '../reference/api';
|
|
18
|
+
export { polishIdentifierCharacterClass as identifierCharacterClass, polishIdentifierFirstCharacterClass as identifierFirstCharacterClass } from './identifier';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TokenStream } from '../tokenizer/interface';
|
|
2
|
+
import type { AstNode, ParseState } from './interface';
|
|
3
|
+
export declare class AlgebraicParser {
|
|
4
|
+
private readonly tokenStream;
|
|
5
|
+
private parseState;
|
|
6
|
+
constructor(tokenStream: TokenStream, parseState: ParseState);
|
|
7
|
+
private advance;
|
|
8
|
+
parse(): AstNode;
|
|
9
|
+
private parseExpression;
|
|
10
|
+
private parseOperand;
|
|
11
|
+
private parseObject;
|
|
12
|
+
private parseArray;
|
|
13
|
+
private parseFunctionCall;
|
|
14
|
+
parseLamdaFunction(): AstNode | null;
|
|
15
|
+
private isAtEnd;
|
|
16
|
+
private peek;
|
|
17
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TokenStream } from '../tokenizer/interface';
|
|
2
|
+
import type { NumberNode, ParseState, ReservedSymbolNode, StringNode, SymbolNode } from './interface';
|
|
3
|
+
export declare function parseSymbol(tokenStream: TokenStream, parseState: ParseState): SymbolNode;
|
|
4
|
+
export declare function parseReservedSymbol(tokenStream: TokenStream, parseState: ParseState): ReservedSymbolNode;
|
|
5
|
+
export declare function parseNumber(tokenStream: TokenStream, parseState: ParseState): NumberNode;
|
|
6
|
+
export declare function parseString(tokenStream: TokenStream, parseState: ParseState): StringNode;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { TokenStream } from '../tokenizer/interface';
|
|
2
|
-
import type { Ast } from './interface';
|
|
2
|
+
import type { Ast, AstNode, ParseState } from './interface';
|
|
3
3
|
export declare function parse(tokenStream: TokenStream): Ast;
|
|
4
|
+
export declare function parseToken(tokenStream: TokenStream, parseState: ParseState): AstNode;
|
|
@@ -4,9 +4,16 @@ import type { Arity } from '../builtin/utils';
|
|
|
4
4
|
import type { AstNodeType, FunctionType } from '../constants/constants';
|
|
5
5
|
import type { Context } from '../evaluator/interface';
|
|
6
6
|
import type { Any, Arr } from '../interface';
|
|
7
|
-
import type {
|
|
8
|
-
import type { SourceCodeInfo,
|
|
7
|
+
import type { PolishReservedName } from '../tokenizer/polish/polishReservedNames';
|
|
8
|
+
import type { SourceCodeInfo, TokenStream } from '../tokenizer/interface';
|
|
9
9
|
import type { FUNCTION_SYMBOL, REGEXP_SYMBOL } from '../utils/symbols';
|
|
10
|
+
import type { Token } from '../tokenizer/tokens';
|
|
11
|
+
import type { ModifierName } from '../tokenizer/polish/polishTokens';
|
|
12
|
+
export interface ParseState {
|
|
13
|
+
position: number;
|
|
14
|
+
algebraic: boolean;
|
|
15
|
+
parseToken: ParseToken;
|
|
16
|
+
}
|
|
10
17
|
export interface EvaluatedFunctionArguments {
|
|
11
18
|
mandatoryArguments: string[];
|
|
12
19
|
restArgument?: string;
|
|
@@ -80,24 +87,23 @@ export interface BuiltinFunction extends GenericLitsFunction {
|
|
|
80
87
|
}
|
|
81
88
|
export type LitsFunction = NativeJsFunction | UserDefinedFunction | BuiltinFunction | PartialFunction | CompFunction | ConstantlyFunction | JuxtFunction | ComplementFunction | EveryPredFunction | SomePredFunction | FNilFunction;
|
|
82
89
|
export type LitsFunctionType = LitsFunction['t'];
|
|
83
|
-
export type
|
|
90
|
+
export type DebugData = {
|
|
91
|
+
token: Token;
|
|
92
|
+
nameToken?: Token;
|
|
93
|
+
};
|
|
84
94
|
export interface GenericNode {
|
|
85
95
|
t: AstNodeType;
|
|
86
96
|
p: AstNode[];
|
|
87
97
|
n: string | undefined;
|
|
88
|
-
|
|
89
|
-
token: Token;
|
|
90
|
-
lastToken: Token;
|
|
91
|
-
nameToken?: Token;
|
|
92
|
-
} | undefined;
|
|
98
|
+
token: Token | undefined;
|
|
93
99
|
}
|
|
94
100
|
export type ExpressionNode = NormalExpressionNode | SpecialExpressionNode | NumberNode | StringNode;
|
|
95
|
-
export type ParseBinding = (tokens: TokenStream,
|
|
96
|
-
export type ParseBindings = (tokens: TokenStream,
|
|
97
|
-
export type ParseArgument = (tokens: TokenStream,
|
|
98
|
-
export type ParseExpression = (tokens: TokenStream,
|
|
99
|
-
export type ParseTokensUntilClosingBracket = (tokens: TokenStream,
|
|
100
|
-
export type ParseToken = (tokens: TokenStream,
|
|
101
|
+
export type ParseBinding = (tokens: TokenStream, parseState: ParseState) => BindingNode;
|
|
102
|
+
export type ParseBindings = (tokens: TokenStream, parseState: ParseState) => BindingNode[];
|
|
103
|
+
export type ParseArgument = (tokens: TokenStream, parseState: ParseState) => ArgumentNode | ModifierNode;
|
|
104
|
+
export type ParseExpression = (tokens: TokenStream, parseState: ParseState) => ExpressionNode;
|
|
105
|
+
export type ParseTokensUntilClosingBracket = (tokens: TokenStream, parseState: ParseState) => AstNode[];
|
|
106
|
+
export type ParseToken = (tokens: TokenStream, parseState: ParseState) => AstNode;
|
|
101
107
|
export interface NumberNode extends GenericNode {
|
|
102
108
|
t: AstNodeType.Number;
|
|
103
109
|
v: number;
|
|
@@ -106,17 +112,17 @@ export interface StringNode extends GenericNode {
|
|
|
106
112
|
t: AstNodeType.String;
|
|
107
113
|
v: string;
|
|
108
114
|
}
|
|
109
|
-
export interface
|
|
110
|
-
t: AstNodeType.
|
|
115
|
+
export interface SymbolNode extends GenericNode {
|
|
116
|
+
t: AstNodeType.Symbol;
|
|
111
117
|
v: string;
|
|
112
118
|
}
|
|
113
119
|
export interface ModifierNode extends GenericNode {
|
|
114
120
|
t: AstNodeType.Modifier;
|
|
115
121
|
v: ModifierName;
|
|
116
122
|
}
|
|
117
|
-
export interface
|
|
118
|
-
t: AstNodeType.
|
|
119
|
-
v:
|
|
123
|
+
export interface ReservedSymbolNode extends GenericNode {
|
|
124
|
+
t: AstNodeType.ReservedSymbol;
|
|
125
|
+
v: PolishReservedName;
|
|
120
126
|
}
|
|
121
127
|
interface CommonNormalExpressionNode extends GenericNode {
|
|
122
128
|
t: AstNodeType.NormalExpression;
|
|
@@ -146,7 +152,7 @@ export interface CommentNode extends GenericNode {
|
|
|
146
152
|
t: AstNodeType.Comment;
|
|
147
153
|
v: string;
|
|
148
154
|
}
|
|
149
|
-
export type AstNode = NumberNode | StringNode |
|
|
155
|
+
export type AstNode = NumberNode | StringNode | ReservedSymbolNode | SymbolNode | CommentNode | NormalExpressionNode | ModifierNode | SpecialExpressionNode;
|
|
150
156
|
type AstBody = AstNode[];
|
|
151
157
|
export interface Ast {
|
|
152
158
|
b: AstBody;
|
|
@@ -7,5 +7,5 @@ export type RemoveOptions = typeof removeOptions;
|
|
|
7
7
|
export declare function removeCommenNodes(ast: Ast): void;
|
|
8
8
|
declare function recursivelyRemoveCommentNodes(astNode: AstNode): void;
|
|
9
9
|
declare function removeCommenNodesFromArray(astNodes: AstNode[]): void;
|
|
10
|
-
export declare function withoutCommentNodes(astNodes: AstNode[]): (import("../parser/interface").NumberNode | import("../parser/interface").StringNode | import("../parser/interface").
|
|
10
|
+
export declare function withoutCommentNodes(astNodes: AstNode[]): (import("../parser/interface").NumberNode | import("../parser/interface").StringNode | import("../parser/interface").ReservedSymbolNode | import("../parser/interface").SymbolNode | import("../parser/interface").NormalExpressionNode | import("../parser/interface").ModifierNode | import("../builtin").SpecialExpressionNode)[];
|
|
11
11
|
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Any } from '../../interface';
|
|
2
|
+
export declare const algebraicReservedNamesRecord: Record<string, {
|
|
3
|
+
value: Any;
|
|
4
|
+
forbidden?: true;
|
|
5
|
+
}>;
|
|
6
|
+
type AlgebraicReservedName = keyof typeof algebraicReservedNamesRecord;
|
|
7
|
+
export declare const algebraicReservedNames: AlgebraicReservedName[];
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Tokenizer } from '../interface';
|
|
2
|
+
import type { A_MultiLineCommentToken, A_NumberToken, A_OperatorToken, A_ReservedSymbolToken, A_SingleLineCommentToken, A_SymbolToken, A_WhitespaceToken } from './algebraicTokens';
|
|
3
|
+
export declare const tokenizeA_Whitespace: Tokenizer<A_WhitespaceToken>;
|
|
4
|
+
export declare const tokenizeA_Number: Tokenizer<A_NumberToken>;
|
|
5
|
+
export declare const tokenizeA_ReservedSymbolToken: Tokenizer<A_ReservedSymbolToken>;
|
|
6
|
+
export declare const tokenizeA_Symbol: Tokenizer<A_SymbolToken>;
|
|
7
|
+
export declare const tokenizeA_Operator: Tokenizer<A_OperatorToken>;
|
|
8
|
+
export declare const tokenizeA_MultiLineComment: Tokenizer<A_MultiLineCommentToken>;
|
|
9
|
+
export declare const tokenizeA_SingleLineComment: Tokenizer<A_SingleLineCommentToken>;
|
|
10
|
+
export declare const algebraicTokenizers: [Tokenizer<A_WhitespaceToken>, Tokenizer<A_MultiLineCommentToken>, Tokenizer<A_SingleLineCommentToken>, Tokenizer<import("../common/commonTokens").PolishNotationToken>, Tokenizer<import("../common/commonTokens").AlgebraicNotationToken>, Tokenizer<import("../common/commonTokens").EndNotationToken>, 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<A_NumberToken>, Tokenizer<A_OperatorToken>, Tokenizer<A_ReservedSymbolToken>, Tokenizer<A_SymbolToken>];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { CommonSimpleToken, CommonValueToken, CommonValueTokenType } from '../common/commonTokens';
|
|
2
|
+
import type { Token } from '../tokens';
|
|
3
|
+
import { type TokenDebugData } from '../utils';
|
|
4
|
+
export declare const algebraicSimpleTokenTypes: readonly ["LBrace", "LBracket", "LParen", "RBrace", "RBracket", "RParen", "AlgNotation", "PolNotation", "EndNotation"];
|
|
5
|
+
export declare const algebraicOnlyValueTokenTypes: ["A_Whitespace", "A_Operator", "A_Symbol", "A_ReservedSymbol", "A_SingleLineComment", "A_MultiLineComment", "A_Number"];
|
|
6
|
+
export declare const algebraicValueTokenTypes: readonly ["String", "A_Whitespace", "A_Operator", "A_Symbol", "A_ReservedSymbol", "A_SingleLineComment", "A_MultiLineComment", "A_Number"];
|
|
7
|
+
export declare const algebraicTokenTypes: readonly ["LBrace", "LBracket", "LParen", "RBrace", "RBracket", "RParen", "AlgNotation", "PolNotation", "EndNotation", "String", "A_Whitespace", "A_Operator", "A_Symbol", "A_ReservedSymbol", "A_SingleLineComment", "A_MultiLineComment", "A_Number"];
|
|
8
|
+
export declare const AlgebraicOperators: readonly ["!", "~", "=", ",", "=>", "...", ".", "**", "*", "/", "%", "+", "-", "<<", ">>", ">>>", "<", "<=", ">", ">=", "==", "!=", "&", "^", "|", "&&", "||", "??"];
|
|
9
|
+
export type AlgebraicOperator = typeof AlgebraicOperators[number];
|
|
10
|
+
export declare function isAlgebraicOperator(operator: string): operator is AlgebraicOperator;
|
|
11
|
+
export declare function assertAlgebraicOperator(operator: string): asserts operator is AlgebraicOperator;
|
|
12
|
+
export declare function asAlgebraicOperator(operator: string): AlgebraicOperator;
|
|
13
|
+
export type AlgebraicSimpleTokenType = typeof algebraicSimpleTokenTypes[number];
|
|
14
|
+
export type AlgebraicValueTokenType = typeof algebraicValueTokenTypes[number];
|
|
15
|
+
export type AlgebraicTokenType = typeof algebraicTokenTypes[number];
|
|
16
|
+
type GenericAlgebraicValueToken<T extends Exclude<AlgebraicValueTokenType, CommonValueTokenType>, V extends string = string> = [T, V] | [T, V, TokenDebugData];
|
|
17
|
+
export type A_WhitespaceToken = GenericAlgebraicValueToken<'A_Whitespace'>;
|
|
18
|
+
export type A_NumberToken = GenericAlgebraicValueToken<'A_Number'>;
|
|
19
|
+
export type A_OperatorToken<T extends AlgebraicOperator = AlgebraicOperator> = GenericAlgebraicValueToken<'A_Operator', T>;
|
|
20
|
+
export type A_SymbolToken = GenericAlgebraicValueToken<'A_Symbol'>;
|
|
21
|
+
export type A_ReservedSymbolToken = GenericAlgebraicValueToken<'A_ReservedSymbol'>;
|
|
22
|
+
export type A_SingleLineCommentToken = GenericAlgebraicValueToken<'A_SingleLineComment'>;
|
|
23
|
+
export type A_MultiLineCommentToken = GenericAlgebraicValueToken<'A_MultiLineComment'>;
|
|
24
|
+
export type AlgebraicOnlyValueToken = A_WhitespaceToken | A_NumberToken | A_OperatorToken | A_SymbolToken | A_ReservedSymbolToken | A_SingleLineCommentToken | A_MultiLineCommentToken;
|
|
25
|
+
export type AlgebraicToken = AlgebraicOnlyValueToken | CommonSimpleToken | CommonValueToken;
|
|
26
|
+
export declare function isA_SymbolToken(token?: Token): token is A_SymbolToken;
|
|
27
|
+
export declare function assertA_SymbolToken(token?: Token): asserts token is A_SymbolToken;
|
|
28
|
+
export declare function asA_SymbolToken(token?: Token): A_SymbolToken;
|
|
29
|
+
export declare function isA_ReservedSymbolToken(token?: Token): token is A_ReservedSymbolToken;
|
|
30
|
+
export declare function assertA_ReservedSymbolToken(token?: Token): asserts token is A_ReservedSymbolToken;
|
|
31
|
+
export declare function asA_ReservedSymbolToken(token?: Token): A_ReservedSymbolToken;
|
|
32
|
+
export declare function isA_CommentToken(token?: Token): token is A_SingleLineCommentToken;
|
|
33
|
+
export declare function assertA_CommentToken(token?: Token): asserts token is A_SingleLineCommentToken;
|
|
34
|
+
export declare function asA_CommentToken(token?: Token): A_SingleLineCommentToken;
|
|
35
|
+
export declare function isA_MultiLineCommentToken(token?: Token): token is A_MultiLineCommentToken;
|
|
36
|
+
export declare function assertA_MultiLineCommentToken(token?: Token): asserts token is A_MultiLineCommentToken;
|
|
37
|
+
export declare function asA_MultiLineCommentToken(token?: Token): A_MultiLineCommentToken;
|
|
38
|
+
export declare function isA_OperatorToken<T extends AlgebraicOperator>(token?: Token, operatorName?: T): token is A_OperatorToken<T>;
|
|
39
|
+
export declare function assertA_OperatorToken<T extends AlgebraicOperator>(token?: Token, operatorName?: T): asserts token is A_OperatorToken<T>;
|
|
40
|
+
export declare function asA_OperatorToken<T extends AlgebraicOperator>(token?: Token, operatorName?: T): A_OperatorToken<T>;
|
|
41
|
+
export declare function isA_WhitespaceToken(token?: Token): token is A_WhitespaceToken;
|
|
42
|
+
export declare function assertA_WhitespaceToken(token?: Token): asserts token is A_WhitespaceToken;
|
|
43
|
+
export declare function asA_WhitespaceToken(token?: Token): A_WhitespaceToken;
|
|
44
|
+
export declare function isA_NumberToken(token?: Token): token is A_NumberToken;
|
|
45
|
+
export declare function assertA_NumberToken(token?: Token): asserts token is A_NumberToken;
|
|
46
|
+
export declare function asA_NumberToken(token?: Token): A_NumberToken;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TokenDescriptor, Tokenizer } from '../interface';
|
|
2
|
+
import type { SimpleToken } from '../tokens';
|
|
3
|
+
import type { AlgebraicNotationToken, EndNotationToken, LBraceToken, LBracketToken, LParenToken, PolishNotationToken, RBraceToken, RBracketToken, RParenToken, StringToken } from './commonTokens';
|
|
4
|
+
export declare const NO_MATCH: TokenDescriptor<never>;
|
|
5
|
+
export declare function isNoMatch(tokenDescriptor: TokenDescriptor<any>): tokenDescriptor is TokenDescriptor<never>;
|
|
6
|
+
export declare const tokenizeString: Tokenizer<StringToken>;
|
|
7
|
+
export declare function tokenizeSimpleToken<T extends SimpleToken>(type: T[0], value: string, input: string, position: number): TokenDescriptor<T>;
|
|
8
|
+
export declare const commonTokenizers: readonly [Tokenizer<PolishNotationToken>, Tokenizer<AlgebraicNotationToken>, Tokenizer<EndNotationToken>, Tokenizer<LParenToken>, Tokenizer<RParenToken>, Tokenizer<LBracketToken>, Tokenizer<RBracketToken>, Tokenizer<LBraceToken>, Tokenizer<RBraceToken>, Tokenizer<StringToken>];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type TokenDebugData } from '../utils';
|
|
2
|
+
import type { Token } from '../tokens';
|
|
3
|
+
export declare const commonSimpleTokenTypes: readonly ["LBrace", "LBracket", "LParen", "RBrace", "RBracket", "RParen", "AlgNotation", "PolNotation", "EndNotation"];
|
|
4
|
+
export declare const commomValueTokenTypes: readonly ["String"];
|
|
5
|
+
export type CommonSimpleTokenType = typeof commonSimpleTokenTypes[number];
|
|
6
|
+
export type CommonValueTokenType = typeof commomValueTokenTypes[number];
|
|
7
|
+
type GenericCommonSimpleToken<T extends CommonSimpleTokenType> = [T] | [T, TokenDebugData];
|
|
8
|
+
type GenericCommonValueToken<T extends CommonValueTokenType, V extends string = string> = [T, V] | [T, V, TokenDebugData];
|
|
9
|
+
export type LParenToken = GenericCommonSimpleToken<'LParen'>;
|
|
10
|
+
export type RParenToken = GenericCommonSimpleToken<'RParen'>;
|
|
11
|
+
export type LBracketToken = GenericCommonSimpleToken<'LBracket'>;
|
|
12
|
+
export type RBracketToken = GenericCommonSimpleToken<'RBracket'>;
|
|
13
|
+
export type LBraceToken = GenericCommonSimpleToken<'LBrace'>;
|
|
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
|
+
export type StringToken = GenericCommonValueToken<'String'>;
|
|
19
|
+
export type CommonSimpleToken = LParenToken | RParenToken | LBracketToken | RBracketToken | LBraceToken | RBraceToken | AlgebraicNotationToken | PolishNotationToken | EndNotationToken;
|
|
20
|
+
export type CommonValueToken = StringToken;
|
|
21
|
+
export declare function isLParenToken(token?: Token): token is LParenToken;
|
|
22
|
+
export declare function assertLParenToken(token?: Token): asserts token is LParenToken;
|
|
23
|
+
export declare function asLParenToken(token?: Token): LParenToken;
|
|
24
|
+
export declare function isRParenToken(token?: Token): token is RParenToken;
|
|
25
|
+
export declare function assertRParenToken(token?: Token): asserts token is RParenToken;
|
|
26
|
+
export declare function asRParenToken(token?: Token): RParenToken;
|
|
27
|
+
export declare function isLBracketToken(token?: Token): token is LBracketToken;
|
|
28
|
+
export declare function assertLBracketToken(token?: Token): asserts token is LBracketToken;
|
|
29
|
+
export declare function asLBracketToken(token?: Token): LBracketToken;
|
|
30
|
+
export declare function isRBracketToken(token?: Token): token is RBracketToken;
|
|
31
|
+
export declare function assertRBracketToken(token?: Token): asserts token is RBracketToken;
|
|
32
|
+
export declare function asRBracketToken(token?: Token): RBracketToken;
|
|
33
|
+
export declare function isLBraceToken(token?: Token): token is LBraceToken;
|
|
34
|
+
export declare function assertLBraceToken(token?: Token): asserts token is LBraceToken;
|
|
35
|
+
export declare function asLBraceToken(token?: Token): LBraceToken;
|
|
36
|
+
export declare function isRBraceToken(token?: Token): token is RBraceToken;
|
|
37
|
+
export declare function assertRBraceToken(token?: Token): asserts token is RBraceToken;
|
|
38
|
+
export declare function asRBraceToken(token?: Token): RBraceToken;
|
|
39
|
+
export declare function isStringToken(token?: Token): token is StringToken;
|
|
40
|
+
export declare function assertStringToken(token?: Token): asserts token is StringToken;
|
|
41
|
+
export declare function asStringToken(token?: Token): StringToken;
|
|
42
|
+
export declare function isAlgebraicNotationToken(token?: Token): token is AlgebraicNotationToken;
|
|
43
|
+
export declare function assertAlgebraicNotationToken(token?: Token): asserts token is AlgebraicNotationToken;
|
|
44
|
+
export declare function asAlgebraicNotationToken(token?: Token): AlgebraicNotationToken;
|
|
45
|
+
export declare function isPolishNotationToken(token?: Token): token is PolishNotationToken;
|
|
46
|
+
export declare function assertPolishNotationToken(token?: Token): asserts token is PolishNotationToken;
|
|
47
|
+
export declare function asPolishNotationToken(token?: Token): PolishNotationToken;
|
|
48
|
+
export declare function isEndNotationToken(token?: Token): token is EndNotationToken;
|
|
49
|
+
export declare function assertEndNotationToken(token?: Token): asserts token is EndNotationToken;
|
|
50
|
+
export declare function asEndNotationToken(token?: Token): EndNotationToken;
|
|
51
|
+
export {};
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { MetaToken, Token, TokenStream, TokenizeParams } from './interface';
|
|
1
|
+
import type { TokenStream, TokenizeParams } from './interface';
|
|
3
2
|
export declare function tokenize(input: string, params: TokenizeParams): TokenStream;
|
|
4
|
-
export declare function isMetaToken(token?: Token): token is MetaToken;
|
|
5
|
-
export declare function assertMetaToken(token?: Token): asserts token is MetaToken;
|
|
6
|
-
export declare function isCommentToken(token?: Token): token is Token<TokenType.Comment>;
|
|
7
|
-
export declare function assertCommentToken(token?: Token): asserts token is Token<TokenType.Comment>;
|
|
8
|
-
export declare function isNewLineToken(token?: Token): token is Token<TokenType.NewLine>;
|
|
9
|
-
export declare function assertNewLineToken(token?: Token): asserts token is Token<TokenType.NewLine>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Token } from './tokens';
|
|
2
2
|
export interface SourceCodeInfo {
|
|
3
3
|
position?: {
|
|
4
4
|
line: number;
|
|
@@ -7,29 +7,16 @@ export interface SourceCodeInfo {
|
|
|
7
7
|
code?: string;
|
|
8
8
|
filePath?: string;
|
|
9
9
|
}
|
|
10
|
-
export type
|
|
11
|
-
export
|
|
12
|
-
leadingMetaTokens: MetaToken[];
|
|
13
|
-
inlineCommentToken: Token<TokenType.Comment> | null;
|
|
14
|
-
}
|
|
15
|
-
export interface TokenDebugData {
|
|
16
|
-
sourceCodeInfo: SourceCodeInfo;
|
|
17
|
-
metaTokens: MetaTokens;
|
|
18
|
-
}
|
|
19
|
-
export interface Token<T extends TokenType = TokenType> {
|
|
20
|
-
t: T;
|
|
21
|
-
v: string;
|
|
22
|
-
o?: Record<string, boolean>;
|
|
23
|
-
debugData: TokenDebugData | undefined;
|
|
24
|
-
}
|
|
25
|
-
export type TokenDescriptor = [length: number, token: Token | undefined];
|
|
26
|
-
export type Tokenizer = (input: string, position: number, debugData?: TokenDebugData) => TokenDescriptor;
|
|
10
|
+
export type TokenDescriptor<T extends Token> = [length: number, token?: T];
|
|
11
|
+
export type Tokenizer<T extends Token> = (input: string, position: number) => TokenDescriptor<T>;
|
|
27
12
|
export interface TokenStream {
|
|
28
13
|
tokens: Token[];
|
|
29
14
|
hasDebugData: boolean;
|
|
15
|
+
algebraic: boolean;
|
|
30
16
|
filePath?: string;
|
|
31
17
|
}
|
|
32
18
|
export interface TokenizeParams {
|
|
33
19
|
debug?: boolean;
|
|
34
20
|
filePath?: string;
|
|
21
|
+
algebraic?: boolean;
|
|
35
22
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Any } from '../../interface';
|
|
2
|
+
export declare const polishReservedNamesRecord: Record<string, {
|
|
3
|
+
value: Any;
|
|
4
|
+
forbidden?: true;
|
|
5
|
+
}>;
|
|
6
|
+
export type PolishReservedName = keyof typeof polishReservedNamesRecord;
|
|
7
|
+
export declare const polishReservedNames: PolishReservedName[];
|