@tokens-studio/tokenscript-interpreter 0.36.4 → 0.37.1
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/chunk-3D6X7EAK.js +6605 -0
- package/dist/chunk-3D6X7EAK.js.map +1 -0
- package/dist/chunk-6KHDVYST.js +6616 -0
- package/dist/chunk-6KHDVYST.js.map +1 -0
- package/dist/chunk-6MXPTXGR.js +6591 -0
- package/dist/chunk-6MXPTXGR.js.map +1 -0
- package/dist/chunk-EM64RW7I.js +6592 -0
- package/dist/chunk-EM64RW7I.js.map +1 -0
- package/dist/chunk-H7YXFZ4I.js +6605 -0
- package/dist/chunk-H7YXFZ4I.js.map +1 -0
- package/dist/chunk-Z437BNC5.js +107 -0
- package/dist/chunk-Z437BNC5.js.map +1 -0
- package/dist/cli.js +149 -16
- package/dist/cli.js.map +1 -1
- package/dist/compliance-suite.js +3 -5
- package/dist/compliance-suite.js.map +1 -1
- package/dist/config-B-kbeoff.d.ts +927 -0
- package/dist/config-Mw_Iq324.d.ts +921 -0
- package/dist/lib/{chunk-S7WGJBSX.js → chunk-24FMHL6W.js} +16 -3
- package/dist/lib/chunk-24FMHL6W.js.map +1 -0
- package/dist/lib/{chunk-2BDFE7U4.js → chunk-4L54VFWU.js} +132 -15
- package/dist/lib/chunk-4L54VFWU.js.map +1 -0
- package/dist/lib/{chunk-UF6I25ED.cjs → chunk-KX5QZ5G2.cjs} +685 -567
- package/dist/lib/chunk-KX5QZ5G2.cjs.map +1 -0
- package/dist/lib/{chunk-K65UI6KX.cjs → chunk-OABJLZRZ.cjs} +113 -100
- package/dist/lib/chunk-OABJLZRZ.cjs.map +1 -0
- package/dist/lib/{chunk-AEOBCHBK.js → chunk-SLITBMFB.js} +10 -3
- package/dist/lib/chunk-SLITBMFB.js.map +1 -0
- package/dist/lib/{chunk-KHF2VXWO.cjs → chunk-ZMMIYWFF.cjs} +10 -2
- package/dist/lib/chunk-ZMMIYWFF.cjs.map +1 -0
- package/dist/lib/index.cjs +99 -91
- package/dist/lib/index.d.cts +4 -4
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +3 -3
- package/dist/lib/{interpreter-DdF_Hj-J.d.ts → interpreter-B7BcLEBz.d.cts} +54 -4
- package/dist/lib/{interpreter-Cz_vWDDa.d.cts → interpreter-wKto6JTb.d.ts} +54 -4
- package/dist/lib/interpreter.cjs +81 -73
- package/dist/lib/interpreter.d.cts +7 -6
- package/dist/lib/interpreter.d.ts +7 -6
- package/dist/lib/interpreter.js +3 -3
- package/dist/lib/processor-node.cjs +12 -12
- package/dist/lib/processor-node.d.cts +3 -3
- package/dist/lib/processor-node.d.ts +3 -3
- package/dist/lib/processor-node.js +3 -3
- package/dist/lib/processor.cjs +17 -17
- package/dist/lib/processor.d.cts +4 -4
- package/dist/lib/processor.d.ts +4 -4
- package/dist/lib/processor.js +3 -3
- package/dist/lib/schema.cjs +5 -5
- package/dist/lib/schema.d.cts +1 -1
- package/dist/lib/schema.d.ts +1 -1
- package/dist/lib/schema.js +3 -3
- package/dist/lib/syntax-highlighting.cjs +15 -15
- package/dist/lib/syntax-highlighting.d.cts +1 -1
- package/dist/lib/syntax-highlighting.d.ts +1 -1
- package/dist/lib/syntax-highlighting.js +2 -2
- package/dist/lib/{types-DRpZJjkx.d.ts → types-BHcQYEQ-.d.ts} +2 -2
- package/dist/lib/{types-CxQPMHn1.d.ts → types-BMYcHiSq.d.cts} +9 -1
- package/dist/lib/{types-CxQPMHn1.d.cts → types-BMYcHiSq.d.ts} +9 -1
- package/dist/lib/{types-6QQt-XVS.d.cts → types-BOyxzACN.d.cts} +2 -2
- package/dist/lib/types.cjs +10 -6
- package/dist/lib/types.d.cts +1 -1
- package/dist/lib/types.d.ts +1 -1
- package/dist/lib/types.js +1 -1
- package/dist/processor/index.d.ts +1 -1
- package/dist/processor/index.js +18 -2
- package/dist/processor/index.js.map +1 -1
- package/dist/repl.d.ts +15 -3
- package/dist/repl.js +6 -8
- package/dist/repl.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/package.json +1 -1
- package/dist/lib/chunk-2BDFE7U4.js.map +0 -1
- package/dist/lib/chunk-AEOBCHBK.js.map +0 -1
- package/dist/lib/chunk-K65UI6KX.cjs.map +0 -1
- package/dist/lib/chunk-KHF2VXWO.cjs.map +0 -1
- package/dist/lib/chunk-S7WGJBSX.js.map +0 -1
- package/dist/lib/chunk-UF6I25ED.cjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DictionarySymbol, serializeInterpreterResult, stringifyInterpreterResult, isSome, LexerError, isSpace, isNumber2, isAlpha, isAlphaNumeric, ParserError, isLanguageError, NullSymbol, isTokenscriptSymbol, StringSymbol, NumberWithUnitSymbol, NumberSymbol, InterpreterError, BooleanSymbol, isNull, jsValueToSymbolType, ListSymbol, ColorSymbol, parseHexWithAlpha, basicSymbolTypes, typeName, typeEquals, ProcessorError, isObject, TokenSymbol, isArray, isString, getKeyAlt, isNumber, isBoolean, safeParseInt, serializeError, ensureValidAlpha, formatHex8, isTransparent, getResultTypeName, LanguageError } from './chunk-
|
|
2
|
-
import { __name, SupportedFormats, ReservedKeyword, __export, UNINTERPRETED_KEYWORDS } from './chunk-
|
|
1
|
+
import { DictionarySymbol, serializeInterpreterResult, stringifyInterpreterResult, isSome, LexerError, isSpace, isNumber2, isAlpha, isAlphaNumeric, ParserError, isLanguageError, NullSymbol, isTokenscriptSymbol, StringSymbol, NumberWithUnitSymbol, NumberSymbol, InterpreterError, BooleanSymbol, isNull, jsValueToSymbolType, ListSymbol, ColorSymbol, parseHexWithAlpha, basicSymbolTypes, typeName, typeEquals, ProcessorError, isObject, TokenSymbol, isArray, isString, getKeyAlt, isNumber, isBoolean, safeParseInt, serializeError, ensureValidAlpha, formatHex8, isTransparent, getResultTypeName, LanguageError } from './chunk-24FMHL6W.js';
|
|
2
|
+
import { __name, SupportedFormats, ReservedKeyword, __export, SCRIPT_ONLY_STATEMENT_KEYWORDS, UNINTERPRETED_KEYWORDS } from './chunk-SLITBMFB.js';
|
|
3
3
|
import { z, Color, Fn, Token, Unit, Constants, ZodError } from '@tokens-studio/schema-validation';
|
|
4
4
|
|
|
5
5
|
// src/interpreter/tolerant/partial-nodes.ts
|
|
@@ -504,6 +504,7 @@ var _Lexer = class _Lexer {
|
|
|
504
504
|
this.text = text;
|
|
505
505
|
this.currentChar = this.pos < this.text.length ? this.text[this.pos] : null;
|
|
506
506
|
this.tolerant = options?.tolerant ?? false;
|
|
507
|
+
this.greedyStrings = options?.greedyStrings ?? false;
|
|
507
508
|
}
|
|
508
509
|
/**
|
|
509
510
|
* Check if a FORMAT token (unit suffix) is valid at the given position.
|
|
@@ -608,8 +609,91 @@ var _Lexer = class _Lexer {
|
|
|
608
609
|
const cp = char.codePointAt(0) ?? 0;
|
|
609
610
|
return isAlphaNumeric(char) || cp === 45 /* HYPHEN */ || cp === 95 /* UNDERSCORE */ || cp > 127;
|
|
610
611
|
}
|
|
612
|
+
/**
|
|
613
|
+
* Greedy variant of isValidStringElement.
|
|
614
|
+
* Consumes everything except whitespace and structural delimiters.
|
|
615
|
+
* Used in inline mode to allow values like `http://foo.bar` as a single string.
|
|
616
|
+
*/
|
|
617
|
+
isValidStringElementGreedy(char) {
|
|
618
|
+
if (char === null) return false;
|
|
619
|
+
if (isSpace(char)) return false;
|
|
620
|
+
const cp = char.codePointAt(0) ?? 0;
|
|
621
|
+
switch (cp) {
|
|
622
|
+
case 123:
|
|
623
|
+
// {
|
|
624
|
+
case 125:
|
|
625
|
+
// }
|
|
626
|
+
case 40:
|
|
627
|
+
// (
|
|
628
|
+
case 41:
|
|
629
|
+
// )
|
|
630
|
+
case 91:
|
|
631
|
+
// [
|
|
632
|
+
case 93:
|
|
633
|
+
// ]
|
|
634
|
+
case 44:
|
|
635
|
+
// ,
|
|
636
|
+
case 34:
|
|
637
|
+
// "
|
|
638
|
+
case 39:
|
|
639
|
+
// '
|
|
640
|
+
case 59:
|
|
641
|
+
return false;
|
|
642
|
+
}
|
|
643
|
+
return true;
|
|
644
|
+
}
|
|
611
645
|
stringElement() {
|
|
612
646
|
const startPos = this.pos;
|
|
647
|
+
const isGreedy = this.greedyStrings;
|
|
648
|
+
if (isGreedy && this.isValidFormatPosition(startPos)) {
|
|
649
|
+
return this.stringElementNonGreedy(startPos);
|
|
650
|
+
}
|
|
651
|
+
let result = "";
|
|
652
|
+
let isSimpleIdentifier = true;
|
|
653
|
+
const check = isGreedy ? (c) => this.isValidStringElementGreedy(c) : (c) => this.isValidStringElement(c);
|
|
654
|
+
while (check(this.currentChar)) {
|
|
655
|
+
if (isSimpleIdentifier && !isAlphaNumeric(this.currentChar) && this.currentChar !== "-" && this.currentChar !== "_") {
|
|
656
|
+
isSimpleIdentifier = false;
|
|
657
|
+
}
|
|
658
|
+
result += this.currentChar;
|
|
659
|
+
this.advance();
|
|
660
|
+
}
|
|
661
|
+
if (isSimpleIdentifier) {
|
|
662
|
+
const normalizedResult = result.toLowerCase();
|
|
663
|
+
const keyword = RESERVED_KEYWORD_STRINGS[normalizedResult];
|
|
664
|
+
if (keyword) {
|
|
665
|
+
return {
|
|
666
|
+
type: "RESERVED_KEYWORD" /* RESERVED_KEYWORD */,
|
|
667
|
+
value: keyword,
|
|
668
|
+
line: this.line,
|
|
669
|
+
pos: startPos,
|
|
670
|
+
endPos: this.pos
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
const format = SUPPORTED_FORMAT_STRINGS[normalizedResult];
|
|
674
|
+
if (format && this.isValidFormatPosition(startPos)) {
|
|
675
|
+
return {
|
|
676
|
+
type: "FORMAT" /* FORMAT */,
|
|
677
|
+
value: format,
|
|
678
|
+
line: this.line,
|
|
679
|
+
pos: startPos,
|
|
680
|
+
endPos: this.pos
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
return {
|
|
685
|
+
type: "STRING" /* STRING */,
|
|
686
|
+
value: result,
|
|
687
|
+
line: this.line,
|
|
688
|
+
pos: startPos,
|
|
689
|
+
endPos: this.pos
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Non-greedy string element parsing, used when in format-adjacent position
|
|
694
|
+
* so that unit suffixes are correctly extracted even in greedy mode.
|
|
695
|
+
*/
|
|
696
|
+
stringElementNonGreedy(startPos) {
|
|
613
697
|
let result = "";
|
|
614
698
|
while (this.isValidStringElement(this.currentChar)) {
|
|
615
699
|
result += this.currentChar;
|
|
@@ -1944,7 +2028,20 @@ ${contextText}`;
|
|
|
1944
2028
|
this.error("PARSER_TOLERANT_REQUIRES_INLINE" /* TOLERANT_REQUIRES_INLINE */);
|
|
1945
2029
|
}
|
|
1946
2030
|
if (this.currentToken.type === "EOF" /* EOF */) return null;
|
|
1947
|
-
if (inlineMode)
|
|
2031
|
+
if (inlineMode) {
|
|
2032
|
+
if (this.currentToken.type === "RESERVED_KEYWORD" /* RESERVED_KEYWORD */ && SCRIPT_ONLY_STATEMENT_KEYWORDS.has(this.currentToken.value)) {
|
|
2033
|
+
this.error("PARSER_UNALLOWED_INLINE_SYNTAX" /* UNALLOWED_INLINE_SYNTAX */, {
|
|
2034
|
+
originalError: `Unexpected token: ${this.currentToken.value}`
|
|
2035
|
+
});
|
|
2036
|
+
}
|
|
2037
|
+
const node2 = this.listExpr();
|
|
2038
|
+
if (!this.tolerant && this.currentToken.type !== "EOF" /* EOF */) {
|
|
2039
|
+
this.error("PARSER_UNEXPECTED_TOKEN" /* UNEXPECTED_TOKEN */, {
|
|
2040
|
+
token: String(this.currentToken.value)
|
|
2041
|
+
});
|
|
2042
|
+
}
|
|
2043
|
+
return node2;
|
|
2044
|
+
}
|
|
1948
2045
|
const node = this.statementsList();
|
|
1949
2046
|
if (this.currentToken.type !== "EOF" /* EOF */) {
|
|
1950
2047
|
this.error("PARSER_INVALID_SYNTAX" /* INVALID_SYNTAX */, {
|
|
@@ -1956,10 +2053,16 @@ ${contextText}`;
|
|
|
1956
2053
|
};
|
|
1957
2054
|
__name(_Parser, "Parser");
|
|
1958
2055
|
var Parser = _Parser;
|
|
1959
|
-
function
|
|
1960
|
-
const
|
|
2056
|
+
function lexerOptionsForMode(mode, overrides) {
|
|
2057
|
+
const base = mode === "inline" ? { greedyStrings: true } : {};
|
|
2058
|
+
return { ...base, ...overrides };
|
|
2059
|
+
}
|
|
2060
|
+
__name(lexerOptionsForMode, "lexerOptionsForMode");
|
|
2061
|
+
function parseExpression(text, options) {
|
|
2062
|
+
const mode = options?.mode ?? "script";
|
|
2063
|
+
const lexer = new Lexer(text, lexerOptionsForMode(mode, options?.lexerOverrides));
|
|
1961
2064
|
const parser = new Parser(lexer);
|
|
1962
|
-
const ast = parser.parse();
|
|
2065
|
+
const ast = parser.parse(mode === "inline");
|
|
1963
2066
|
return {
|
|
1964
2067
|
lexer,
|
|
1965
2068
|
parser,
|
|
@@ -3803,6 +3906,22 @@ var _PrefixResolver = class _PrefixResolver {
|
|
|
3803
3906
|
this.earlyResolved.push(tokenName);
|
|
3804
3907
|
}
|
|
3805
3908
|
tryParseExpression(refPath, value) {
|
|
3909
|
+
try {
|
|
3910
|
+
return parseExpression(value, { mode: "inline" });
|
|
3911
|
+
} catch (error) {
|
|
3912
|
+
const isStatementSyntax = error instanceof ParserError && (error.code === "PARSER_UNALLOWED_INLINE_SYNTAX" /* UNALLOWED_INLINE_SYNTAX */ || error.code === "PARSER_UNEXPECTED_TOKEN" /* UNEXPECTED_TOKEN */ && SCRIPT_ONLY_STATEMENT_KEYWORDS.has(error.data?.token));
|
|
3913
|
+
if (isStatementSyntax) ; else if (isLanguageError(error)) {
|
|
3914
|
+
return this.resolveError(refPath, error, value);
|
|
3915
|
+
} else {
|
|
3916
|
+
return this.resolveError(
|
|
3917
|
+
refPath,
|
|
3918
|
+
new ProcessorError("PROC_UNKNOWN_PARSING_ERROR" /* UNKNOWN_PARSING_ERROR */, {
|
|
3919
|
+
data: { error: error instanceof Error ? error.message : String(error) }
|
|
3920
|
+
}),
|
|
3921
|
+
value
|
|
3922
|
+
);
|
|
3923
|
+
}
|
|
3924
|
+
}
|
|
3806
3925
|
try {
|
|
3807
3926
|
return parseExpression(value);
|
|
3808
3927
|
} catch (error) {
|
|
@@ -7193,12 +7312,10 @@ Constants.specName;
|
|
|
7193
7312
|
|
|
7194
7313
|
// src/lib/eval.ts
|
|
7195
7314
|
function evaluateExpression(expression, options = {}) {
|
|
7196
|
-
const { references = {}, config,
|
|
7315
|
+
const { references = {}, config, mode = "script" } = options;
|
|
7197
7316
|
const startTime = performance.now();
|
|
7198
7317
|
try {
|
|
7199
|
-
const
|
|
7200
|
-
const parser = new Parser(lexer);
|
|
7201
|
-
const ast = parser.parse(allowStatements);
|
|
7318
|
+
const { ast } = parseExpression(expression, { mode });
|
|
7202
7319
|
if (!ast) {
|
|
7203
7320
|
return {
|
|
7204
7321
|
success: true,
|
|
@@ -7229,7 +7346,7 @@ __name(evaluateExpression, "evaluateExpression");
|
|
|
7229
7346
|
|
|
7230
7347
|
// src/interpreter/tolerant/index.ts
|
|
7231
7348
|
function parseTolerantly(text) {
|
|
7232
|
-
const lexer = new Lexer(text, { tolerant: true });
|
|
7349
|
+
const lexer = new Lexer(text, lexerOptionsForMode("inline", { tolerant: true }));
|
|
7233
7350
|
try {
|
|
7234
7351
|
const parser = new Parser(lexer, { tolerant: true });
|
|
7235
7352
|
const ast = parser.parse(true);
|
|
@@ -7252,7 +7369,7 @@ function parseTolerantly(text) {
|
|
|
7252
7369
|
}
|
|
7253
7370
|
__name(parseTolerantly, "parseTolerantly");
|
|
7254
7371
|
function tokenizeTolerantly(text) {
|
|
7255
|
-
const lexer = new Lexer(text, { tolerant: true });
|
|
7372
|
+
const lexer = new Lexer(text, lexerOptionsForMode("inline", { tolerant: true }));
|
|
7256
7373
|
return lexer.tokenizeAll();
|
|
7257
7374
|
}
|
|
7258
7375
|
__name(tokenizeTolerantly, "tokenizeTolerantly");
|
|
@@ -7299,6 +7416,6 @@ var ASTNodes = {
|
|
|
7299
7416
|
UnaryOpNode
|
|
7300
7417
|
};
|
|
7301
7418
|
|
|
7302
|
-
export { ASTNodes, ColorManager, ColorSpecificationSchema, Config, ConstantsSpecificationSchema, DEFAULT_LANGUAGE_OPTIONS, FunctionSpecificationSchema, FunctionsManager, IncompleteType, Interpreter, Lexer, ParseState, Parser, PartialBinOpNode, PartialFunctionCallNode, PartialParenNode, PartialReferenceNode, PartialStringNode, PartialUnaryOpNode, TokenResolver, UnitManager, UnitSpecificationSchema, ValidationSeverity, buildTokens, builders_exports, collectAllReferences, collectReferenceNodes, errorClasses, errorHelpers, evaluateExpression, fetchAndRegisterSchemas, fetchTokenScriptSchema, filterAST, flattenChildrenMap, flattenChildrenObject, getAffectedTokens, getBrokenReferences, getModifiedDependants, getRenamedReferences, hasPartialNodes, parseExpression, parseTolerantly, processTokenSets, processTokens, renameReferences, tokenizeTolerantly, validateTokenName, validateTokenPath, walkAST };
|
|
7303
|
-
//# sourceMappingURL=chunk-
|
|
7304
|
-
//# sourceMappingURL=chunk-
|
|
7419
|
+
export { ASTNodes, ColorManager, ColorSpecificationSchema, Config, ConstantsSpecificationSchema, DEFAULT_LANGUAGE_OPTIONS, FunctionSpecificationSchema, FunctionsManager, IncompleteType, Interpreter, Lexer, ParseState, Parser, PartialBinOpNode, PartialFunctionCallNode, PartialParenNode, PartialReferenceNode, PartialStringNode, PartialUnaryOpNode, TokenResolver, UnitManager, UnitSpecificationSchema, ValidationSeverity, buildTokens, builders_exports, collectAllReferences, collectReferenceNodes, errorClasses, errorHelpers, evaluateExpression, fetchAndRegisterSchemas, fetchTokenScriptSchema, filterAST, flattenChildrenMap, flattenChildrenObject, getAffectedTokens, getBrokenReferences, getModifiedDependants, getRenamedReferences, hasPartialNodes, lexerOptionsForMode, parseExpression, parseTolerantly, processTokenSets, processTokens, renameReferences, tokenizeTolerantly, validateTokenName, validateTokenPath, walkAST };
|
|
7420
|
+
//# sourceMappingURL=chunk-4L54VFWU.js.map
|
|
7421
|
+
//# sourceMappingURL=chunk-4L54VFWU.js.map
|