@rowsncolumns/fast-formula-parser 6.2.32 → 6.2.34
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/cjs/index.js +39 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +39 -6
- package/dist/esm/index.js.map +1 -1
- package/index.d.ts +4 -1
- package/package.json +3 -3
package/dist/esm/index.js
CHANGED
|
@@ -3219,12 +3219,15 @@ const IndexedColors = Object.freeze([
|
|
|
3219
3219
|
|
|
3220
3220
|
const isSingleSectionElapsedTimePattern = (pattern) => !pattern.includes(";") &&
|
|
3221
3221
|
/\[(?:h+|m+|s+)\]/i.test(pattern.replace(/\[\$[^\]]+\]/g, ""));
|
|
3222
|
+
const localeForPattern = (pattern, locale) => {
|
|
3223
|
+
return locale;
|
|
3224
|
+
};
|
|
3222
3225
|
const ssfFormat = (pattern, value, locale) => {
|
|
3223
3226
|
try {
|
|
3224
3227
|
const isNegativeElapsedTime = typeof value === "number" &&
|
|
3225
3228
|
value < 0 &&
|
|
3226
3229
|
isSingleSectionElapsedTimePattern(pattern);
|
|
3227
|
-
const formatted = format(pattern, isNegativeElapsedTime ? Math.abs(value) : value, { locale });
|
|
3230
|
+
const formatted = format(pattern, isNegativeElapsedTime ? Math.abs(value) : value, { locale: localeForPattern(pattern, locale) });
|
|
3228
3231
|
return isNegativeElapsedTime ? `-${formatted}` : formatted;
|
|
3229
3232
|
}
|
|
3230
3233
|
catch (err) {
|
|
@@ -41820,7 +41823,19 @@ const allTokens = [
|
|
|
41820
41823
|
|
|
41821
41824
|
const SelectLexer = new Lexer(allTokens, { ensureOptimizations: true });
|
|
41822
41825
|
|
|
41823
|
-
|
|
41826
|
+
// Catch-all for characters no other token matches. Spelled out as a code-unit
|
|
41827
|
+
// range because Chevrotain's first-char optimisation mis-analyses `[\s\S]`
|
|
41828
|
+
// (it never matches) and refuses to optimise the complement set `[^]`.
|
|
41829
|
+
const UnknownChar = createToken({
|
|
41830
|
+
name: "UnknownChar",
|
|
41831
|
+
pattern: /[\u0000-\uFFFF]/,
|
|
41832
|
+
});
|
|
41833
|
+
|
|
41834
|
+
const tolerantTokens = [...allTokens, UnknownChar];
|
|
41835
|
+
|
|
41836
|
+
const TolerantLexer = new Lexer(tolerantTokens, { ensureOptimizations: true });
|
|
41837
|
+
|
|
41838
|
+
tolerantTokens.forEach((tokenType) => {
|
|
41824
41839
|
tokenVocabulary$1[tokenType.name] = tokenType;
|
|
41825
41840
|
});
|
|
41826
41841
|
|
|
@@ -41848,11 +41863,29 @@ function lex(inputText) {
|
|
|
41848
41863
|
/**
|
|
41849
41864
|
* Tolerant lexer that returns partial tokens even when errors occur.
|
|
41850
41865
|
* Useful for incomplete formulas (e.g., '=SUM(') without throwing.
|
|
41866
|
+
*
|
|
41867
|
+
* Every character the formula grammar has no token for (e.g. a bare `\`)
|
|
41868
|
+
* is lexed as an `UnknownChar` token instead of being dropped by Chevrotain's
|
|
41869
|
+
* error recovery, which never advances its column counter over the dropped
|
|
41870
|
+
* characters. Unknown characters stay in `tokens` as first-class tokens with
|
|
41871
|
+
* native positions and are additionally reported in `errors` (Chevrotain's
|
|
41872
|
+
* `ILexingError` shape) so callers can still detect them.
|
|
41851
41873
|
*/
|
|
41852
41874
|
function tolerantLex(inputText) {
|
|
41853
|
-
const lexingResult =
|
|
41854
|
-
|
|
41855
|
-
|
|
41875
|
+
const lexingResult = TolerantLexer.tokenize(inputText);
|
|
41876
|
+
const errors = [];
|
|
41877
|
+
for (const token of lexingResult.tokens) {
|
|
41878
|
+
if (token.tokenType === UnknownChar) {
|
|
41879
|
+
errors.push({
|
|
41880
|
+
offset: token.startOffset,
|
|
41881
|
+
line: token.startLine,
|
|
41882
|
+
column: token.startColumn,
|
|
41883
|
+
length: 1,
|
|
41884
|
+
message: `unexpected character: ->${token.image}<- at offset: ${token.startOffset}, skipped 1 characters.`,
|
|
41885
|
+
});
|
|
41886
|
+
}
|
|
41887
|
+
}
|
|
41888
|
+
return { tokens: lexingResult.tokens, groups: lexingResult.groups, errors };
|
|
41856
41889
|
}
|
|
41857
41890
|
|
|
41858
41891
|
const tokenVocabulary = tokenVocabulary$1;
|
|
@@ -45743,5 +45776,5 @@ class DepParser {
|
|
|
45743
45776
|
// Export a Set of implemented function names for O(1) lookup
|
|
45744
45777
|
const implementedFunctionNames = FormulaParser.getImplementedFunctionNames();
|
|
45745
45778
|
|
|
45746
|
-
export { Address, Criteria, DepParser, Factorials, FormulaError, FormulaHelpers, MAX_COLUMN, MAX_ROW, ReversedTypes, Types, WildCard, allTokens, FormulaParser as default, implementedFunctionNames, lex, noop, tokenVocabulary$1 as tokenVocabulary, tolerantLex };
|
|
45779
|
+
export { Address, Criteria, DepParser, Factorials, FormulaError, FormulaHelpers, MAX_COLUMN, MAX_ROW, ReversedTypes, Types, UnknownChar, WildCard, allTokens, FormulaParser as default, implementedFunctionNames, lex, noop, tokenVocabulary$1 as tokenVocabulary, tolerantLex };
|
|
45747
45780
|
//# sourceMappingURL=index.js.map
|