Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
refactor(formula): defined name lexer (#1909)
Univere5a1b3196122
diff --git a/packages/engine-formula/src/engine/analysis/__tests__/lexer-tree-builder.spec.ts b/packages/engine-formula/src/engine/analysis/__tests__/lexer-tree-builder.spec.tsindex 7aef87e29f..0edfb94aaf 100644--- a/packages/engine-formula/src/engine/analysis/__tests__/lexer-tree-builder.spec.ts+++ b/packages/engine-formula/src/engine/analysis/__tests__/lexer-tree-builder.spec.ts@@ -16,24 +16,11 @@import { describe, expect, it } from 'vitest';+import { AbsoluteRefType } from '@univerjs/core';import type { LexerNode } from '../lexer-node';import { LexerTreeBuilder } from '../lexer-tree-builder';import { ErrorType } from '../../../basics/error-type';-function checkDefinedName(token: string) {- if (token === 'myName') {- return true;- }- return false;-}--function checkDefinedName2(token: string) {- if (token === 'DefinedName2') {- return true;- }- return false;-}-describe('lexer nodeMaker test', () => {const lexerTreeBuilder = new LexerTreeBuilder();@@ -257,7 +244,7 @@ describe('lexer nodeMaker test', () => {describe('sequenceNodesBuilder', () => {it('workbook ref build', () => {- expect(lexerTreeBuilder.sequenceNodesBuilder('=[workbook-01]工作表11!G14:M20', () => false)).toStrictEqual([+ expect(lexerTreeBuilder.sequenceNodesBuilder('=[workbook-01]工作表11!G14:M20')).toStrictEqual([{endIndex: 25,nodeType: 4,@@ -268,7 +255,7 @@ describe('lexer nodeMaker test', () => {});it('special workbook ref build', () => {- expect(lexerTreeBuilder.sequenceNodesBuilder('=\'[workbook-01]工作表11\'!G14:M20,\'[workbook-01]工作表11\'!K27:N32', () => false)).toStrictEqual([+ expect(lexerTreeBuilder.sequenceNodesBuilder('=\'[workbook-01]工作表11\'!G14:M20,\'[workbook-01]工作表11\'!K27:N32')).toStrictEqual([{endIndex: 27,nodeType: 4,@@ -286,7 +273,7 @@ describe('lexer nodeMaker test', () => {});it('cube', () => {- expect(lexerTreeBuilder.sequenceNodesBuilder('=INDEX((A6:B6,C6:D7),1,1,2)', () => false)).toStrictEqual([+ expect(lexerTreeBuilder.sequenceNodesBuilder('=INDEX((A6:B6,C6:D7),1,1,2)')).toStrictEqual([{endIndex: 4,nodeType: 3,@@ -335,7 +322,7 @@ describe('lexer nodeMaker test', () => {});it('No Parameter Function', () => {- expect(lexerTreeBuilder.sequenceNodesBuilder('=today()+today()+column()', () => false)).toStrictEqual([+ expect(lexerTreeBuilder.sequenceNodesBuilder('=today()+today()+column()')).toStrictEqual([{endIndex: 4,nodeType: 3,@@ -366,7 +353,7 @@ describe('lexer nodeMaker test', () => {});it('No Parameter Today', () => {- expect(lexerTreeBuilder.sequenceNodesBuilder('=IF(TODAY()>1,"TRUE", "FALSE")', () => false)).toStrictEqual([+ expect(lexerTreeBuilder.sequenceNodesBuilder('=IF(TODAY()>1,"TRUE", "FALSE")')).toStrictEqual([{endIndex: 1,nodeType: 3,@@ -406,56 +393,42 @@ describe('lexer nodeMaker test', () => {')',]);});+ });- it('Has defined name', () => {- expect(lexerTreeBuilder.sequenceNodesBuilder('=myName+A1:B10', checkDefinedName.bind(this))).toStrictEqual([- {- endIndex: 5,- nodeType: 6,- startIndex: 0,- token: 'myName',- },- '+',- {- endIndex: 12,- nodeType: 4,- startIndex: 7,- token: 'A1:B10',- },- ]);+ describe('convertRefersToAbsolute', () => {+ it('Formula All', () => {+ const result = lexerTreeBuilder.convertRefersToAbsolute('=sum(A1:B1,A1:B1,A1:B1,A1:B1)', AbsoluteRefType.ALL, AbsoluteRefType.ALL);+ expect(result).toStrictEqual('=sum($A$1:$B$1,$A$1:$B$1,$A$1:$B$1,$A$1:$B$1)');});- it('Has defined name11', () => {- expect(lexerTreeBuilder.sequenceNodesBuilder('=SUM(DefinedName2+E22:E32,J21:J32)', checkDefinedName2.bind(this))).toStrictEqual([- {- endIndex: 2,- nodeType: 3,- startIndex: 0,- token: 'SUM',- },- '(',- {- endIndex: 15,- nodeType: 6,- startIndex: 4,- token: 'DefinedName2',- },- '+',- {- endIndex: 23,- nodeType: 4,- startIndex: 17,- token: 'E22:E32',- },- ',',- {- endIndex: 31,- nodeType: 4,- startIndex: 25,- token: 'J21:J32',- },- ')',- ]);+ it('Range All', () => {+ const result = lexerTreeBuilder.convertRefersToAbsolute('A1:B1,A1:B1,A1:B1,A1:B1', AbsoluteRefType.ALL, AbsoluteRefType.ALL);+ expect(result).toStrictEqual('$A$1:$B$1,$A$1:$B$1,$A$1:$B$1,$A$1:$B$1');+ });++ it('Formula Column', () => {+ const result = lexerTreeBuilder.convertRefersToAbsolute('=sum(A1:B1,A1:B1,A1:B1,A1:B1)', AbsoluteRefType.COLUMN, AbsoluteRefType.COLUMN);+ expect(result).toStrictEqual('=sum($A1:$B1,$A1:$B1,$A1:$B1,$A1:$B1)');+ });++ it('Range Column', () => {+ const result = lexerTreeBuilder.convertRefersToAbsolute('A1:B1,A1:B1,A1:B1,A1:B1', AbsoluteRefType.COLUMN, AbsoluteRefType.COLUMN);+ expect(result).toStrictEqual('$A1:$B1,$A1:$B1,$A1:$B1,$A1:$B1');+ });++ it('Formula Row', () => {+ const result = lexerTreeBuilder.convertRefersToAbsolute('=sum(A1:B1,A1:B1,A1:B1,A1:B1)', AbsoluteRefType.ROW, AbsoluteRefType.ROW);+ expect(result).toStrictEqual('=sum(A$1:B$1,A$1:B$1,A$1:B$1,A$1:B$1)');+ });++ it('Range Row', () => {+ const result = lexerTreeBuilder.convertRefersToAbsolute('A1:B1,A1:B1,A1:B1,A1:B1', AbsoluteRefType.ROW, AbsoluteRefType.ROW);+ expect(result).toStrictEqual('A$1:B$1,A$1:B$1,A$1:B$1,A$1:B$1');+ });++ it('Complex Formula', () => {+ const result = lexerTreeBuilder.convertRefersToAbsolute('=SUM(A1:B10) + LAMBDA(x, y, x*y*x)(A1:B10, A10) + MAX(A1:B10,SUM(A2))', AbsoluteRefType.ALL, AbsoluteRefType.ALL);+ expect(result).toStrictEqual('=SUM($A$1:$B$10) + LAMBDA(x, y, x*y*x)($A$1:$B$10,$A$10) + MAX($A$1:$B$10,SUM($A$2))');});});});diff --git a/packages/engine-formula/src/engine/analysis/__tests__/lexer.spec.ts b/packages/engine-formula/src/engine/analysis/__tests__/lexer.spec.tsindex beffdd24e7..a27e4eb502 100644--- a/packages/engine-formula/src/engine/analysis/__tests__/lexer.spec.ts+++ b/packages/engine-formula/src/engine/analysis/__tests__/lexer.spec.ts@@ -15,7 +15,7 @@*/import type { IWorkbookData, Univer, Workbook } from '@univerjs/core';-import { AbsoluteRefType, IUniverInstanceService, LocaleType } from '@univerjs/core';+import { LocaleType } from '@univerjs/core';import type { Injector } from '@wendellhu/redi';import { afterEach, beforeEach, describe, expect, it } from 'vitest';@@ -70,7 +70,7 @@ describe('lexer test', () => {let definedNamesService: IDefinedNamesService;let formulaCurrentConfigService: IFormulaCurrentConfigService;let lexerTreeBuilder: LexerTreeBuilder;- let univerInstanceService: IUniverInstanceService;+beforeEach(() => {const testBed = createCommandTestBed(TEST_WORKBOOK_DATA);@@ -81,14 +81,14 @@ describe('lexer test', () => {definedNamesService = get(IDefinedNamesService);formulaCurrentConfigService = get(IFormulaCurrentConfigService);lexerTreeBuilder = get(LexerTreeBuilder);- univerInstanceService = get(IUniverInstanceService);+formulaCurrentConfigService.setExecuteUnitId('test');formulaCurrentConfigService.setExecuteSubUnitId('sheet1');// runtimeService.setCurrent(0, 0, 4, 1, 'sheet1', 'test');- lexer = new Lexer(definedNamesService, lexerTreeBuilder, formulaCurrentConfigService, univerInstanceService);+ lexer = new Lexer(definedNamesService, lexerTreeBuilder, formulaCurrentConfigService);});afterEach(() => {@@ -116,41 +116,4 @@ describe('lexer test', () => {);});});-- describe('convertRefersToAbsolute', () => {- it('Formula All', () => {- const result = lexer.convertRefersToAbsolute('=sum(A1:B1,A1:B1,A1:B1,A1:B1)', AbsoluteRefType.ALL, AbsoluteRefType.ALL);- expect(result).toStrictEqual('=sum($A$1:$B$1,$A$1:$B$1,$A$1:$B$1,$A$1:$B$1)');- });-- it('Range All', () => {- const result = lexer.convertRefersToAbsolute('A1:B1,A1:B1,A1:B1,A1:B1', AbsoluteRefType.ALL, AbsoluteRefType.ALL);- expect(result).toStrictEqual('$A$1:$B$1,$A$1:$B$1,$A$1:$B$1,$A$1:$B$1');- });-- it('Formula Column', () => {- const result = lexer.convertRefersToAbsolute('=sum(A1:B1,A1:B1,A1:B1,A1:B1)', AbsoluteRefType.COLUMN, AbsoluteRefType.COLUMN);- expect(result).toStrictEqual('=sum($A1:$B1,$A1:$B1,$A1:$B1,$A1:$B1)');- });-- it('Range Column', () => {- const result = lexer.convertRefersToAbsolute('A1:B1,A1:B1,A1:B1,A1:B1', AbsoluteRefType.COLUMN, AbsoluteRefType.COLUMN);- expect(result).toStrictEqual('$A1:$B1,$A1:$B1,$A1:$B1,$A1:$B1');- });-- it('Formula Row', () => {- const result = lexer.convertRefersToAbsolute('=sum(A1:B1,A1:B1,A1:B1,A1:B1)', AbsoluteRefType.ROW, AbsoluteRefType.ROW);- expect(result).toStrictEqual('=sum(A$1:B$1,A$1:B$1,A$1:B$1,A$1:B$1)');- });-- it('Range Row', () => {- const result = lexer.convertRefersToAbsolute('A1:B1,A1:B1,A1:B1,A1:B1', AbsoluteRefType.ROW, AbsoluteRefType.ROW);- expect(result).toStrictEqual('A$1:B$1,A$1:B$1,A$1:B$1,A$1:B$1');- });-- it('Complex Formula', () => {- const result = lexer.convertRefersToAbsolute('=SUM(A1:B10) + LAMBDA(x, y, x*y*x)(A1:B10, A10) + MAX(A1:B10,SUM(A2))', AbsoluteRefType.ALL, AbsoluteRefType.ALL);- expect(result).toStrictEqual('=SUM($A$1:$B$10) + LAMBDA(x, y, x*y*x)($A$1:$B$10,$A$10) + MAX($A$1:$B$10,SUM($A$2))');- });- });});diff --git a/packages/engine-formula/src/engine/analysis/lexer-tree-builder.ts b/packages/engine-formula/src/engine/analysis/lexer-tree-builder.tsindex f02082f4de..aea2b2e83e 100644--- a/packages/engine-formula/src/engine/analysis/lexer-tree-builder.ts+++ b/packages/engine-formula/src/engine/analysis/lexer-tree-builder.ts@@ -14,13 +14,13 @@* limitations under the License.*/-import type { Nullable } from '@univerjs/core';-import { Disposable, Tools } from '@univerjs/core';+import type { IRange, Nullable } from '@univerjs/core';+import { AbsoluteRefType, Disposable, isValidRange, moveRangeByOffset, Tools } from '@univerjs/core';import { FormulaAstLRU } from '../../basics/cache-lru';import { ErrorType } from '../../basics/error-type';import { isFormulaLexerToken } from '../../basics/match-token';-import { isReferenceString, REFERENCE_SINGLE_RANGE_REGEX } from '../../basics/regex';+import { REFERENCE_SINGLE_RANGE_REGEX } from '../../basics/regex';import {matchToken,OPERATOR_TOKEN_PRIORITY,@@ -39,7 +39,8 @@ import {DEFAULT_TOKEN_TYPE_ROOT,} from '../../basics/token-type';import type { ISequenceArray, ISequenceNode } from '../utils/sequence';-import { sequenceNodeType } from '../utils/sequence';+import { generateStringWithSequence, sequenceNodeType } from '../utils/sequence';+import { deserializeRangeWithSheet, isReferenceStringWithEffectiveColumn, serializeRangeToRefString } from '../utils/reference';import { LexerNode } from './lexer-node';enum bracketType {@@ -230,7 +231,7 @@ export class LexerTreeBuilder extends Disposable {return bracketCount;}- sequenceNodesBuilder(formulaString: string, definedNameCheck: (nodeToken: string) => boolean) {+ sequenceNodesBuilder(formulaString: string) {const sequenceNodesCache = FormulaSequenceNodeCache.get(formulaString);if (sequenceNodesCache) {return [...sequenceNodesCache];@@ -241,7 +242,7 @@ export class LexerTreeBuilder extends Disposable {return;}- const newSequenceNodes = this.getSequenceNode(sequenceArray, definedNameCheck);+ const newSequenceNodes = this.getSequenceNode(sequenceArray);// let sequenceString = '';// for (const node of newSequenceNodes) {@@ -258,7 +259,122 @@ export class LexerTreeBuilder extends Disposable {return newSequenceNodes;}- getSequenceNode(sequenceArray: ISequenceArray[], definedNameCheck: (nodeToken: string) => boolean) {+ convertRefersToAbsolute(formulaString: string, startAbsoluteRefType: AbsoluteRefType, endAbsoluteRefType: AbsoluteRefType) {+ const nodes = this.sequenceNodesBuilder(formulaString);+ if (nodes == null) {+ return formulaString;+ }++ let prefixToken = '';+ if (formulaString.substring(0, 1) === operatorToken.EQUALS) {+ prefixToken = operatorToken.EQUALS;+ }++ for (let i = 0, len = nodes.length; i < len; i++) {+ const node = nodes[i];+ if (typeof node === 'string') {+ continue;+ }++ if (node.nodeType === sequenceNodeType.REFERENCE) {+ const { token, endIndex } = node;+ const sequenceGrid = deserializeRangeWithSheet(token);+ if (sequenceGrid == null) {+ continue;+ }++ const { range, sheetName, unitId } = sequenceGrid;++ const newRange = {+ ...range,+ startAbsoluteRefType,+ endAbsoluteRefType,+ };++ const newToken = serializeRangeToRefString({+ range: newRange,+ unitId,+ sheetName,+ });++ const minusCount = newToken.length - token.length;++ nodes[i] = {+ ...node,+ token: newToken,+ endIndex: endIndex + minusCount,+ };++ /**+ * Adjust the start and end indexes of the subsequent nodes.+ */+ for (let j = i + 1; j < len; j++) {+ const nextNode = nodes[j];+ if (typeof nextNode === 'string') {+ continue;+ }++ nextNode.startIndex += minusCount;+ nextNode.endIndex += minusCount;+ }+ }+ }++ return `${prefixToken}${generateStringWithSequence(nodes)}`;+ }++ moveFormulaRefOffset(formulaString: string, refOffsetX: number, refOffsetY: number, ignoreAbsolute = false) {+ const sequenceNodes = this.sequenceNodesBuilder(formulaString);++ if (sequenceNodes == null) {+ return formulaString;+ }++ const newSequenceNodes: Array<string | ISequenceNode> = [];++ for (let i = 0, len = sequenceNodes.length; i < len; i++) {+ const node = sequenceNodes[i];+ if (typeof node === 'string' || node.nodeType !== sequenceNodeType.REFERENCE) {+ newSequenceNodes.push(node);+ continue;+ }++ const { token } = node;++ const sequenceGrid = deserializeRangeWithSheet(token);++ const { sheetName, unitId: sequenceUnitId } = sequenceGrid;++ let newRange: IRange = sequenceGrid.range;++ if (newRange.startAbsoluteRefType === AbsoluteRefType.ALL && newRange.endAbsoluteRefType === AbsoluteRefType.ALL) {+ newSequenceNodes.push(node);+ continue;+ } else {+ newRange = moveRangeByOffset(newRange, refOffsetX, refOffsetY, ignoreAbsolute);+ }++ let newToken = '';+ if (isValidRange(newRange)) {+ newToken = serializeRangeToRefString({+ range: newRange,+ unitId: sequenceUnitId,+ sheetName,+ });+ } else {+ newToken = ErrorType.REF;+ }++ newSequenceNodes.push({+ ...node,+ token: newToken,+ });+ }++ return `=${generateStringWithSequence(newSequenceNodes)}`;+ }++ getSequenceNode(sequenceArray: ISequenceArray[]) {const sequenceNodes: Array<ISequenceNode | string> = [];let maybeString = false;@@ -302,30 +418,10 @@ export class LexerTreeBuilder extends Disposable {const preSegmentNotPrefixToken = this._replacePrefixString(preSegmentTrim);- if (definedNameCheck && definedNameCheck(preSegmentTrim)) {- this._pushSequenceNode(- sequenceNodes,- {- nodeType: sequenceNodeType.DEFINED_NAME,- token: preSegment,- startIndex,- endIndex,- },- deleteEndIndex- );- } else if (maybeString === true && preSegmentTrim[preSegmentTrim.length - 1] === matchToken.DOUBLE_QUOTATION) {+ if (maybeString === true && preSegmentTrim[preSegmentTrim.length - 1] === matchToken.DOUBLE_QUOTATION) {maybeString = false;- this._pushSequenceNode(- sequenceNodes,- {- nodeType: sequenceNodeType.STRING,- token: preSegment,- startIndex,- endIndex,- },- deleteEndIndex- );- } else if (new RegExp(REFERENCE_SINGLE_RANGE_REGEX).test(preSegmentNotPrefixToken)) {+ this._processPushSequenceNode(sequenceNodes, sequenceNodeType.STRING, preSegment, startIndex, endIndex, deleteEndIndex);+ } else if (new RegExp(REFERENCE_SINGLE_RANGE_REGEX).test(preSegmentNotPrefixToken) && isReferenceStringWithEffectiveColumn(preSegmentNotPrefixToken)) {/*** =-A1 Separate the negative sign from the ref string.*/@@ -336,39 +432,11 @@ export class LexerTreeBuilder extends Disposable {preSegment = this._replacePrefixString(preSegment);}-- this._pushSequenceNode(- sequenceNodes,- {- nodeType: sequenceNodeType.REFERENCE,- token: preSegment,- startIndex,- endIndex,- },- deleteEndIndex- );+ this._processPushSequenceNode(sequenceNodes, sequenceNodeType.REFERENCE, preSegment, startIndex, endIndex, deleteEndIndex);} else if (Tools.isStringNumber(preSegmentTrim)) {- this._pushSequenceNode(- sequenceNodes,- {- nodeType: sequenceNodeType.NUMBER,- token: preSegment,- startIndex,- endIndex,- },- deleteEndIndex- );+ this._processPushSequenceNode(sequenceNodes, sequenceNodeType.NUMBER, preSegment, startIndex, endIndex, deleteEndIndex);} else if (preSegmentTrim.length > 0) {- this._pushSequenceNode(- sequenceNodes,- {- nodeType: sequenceNodeType.FUNCTION,- token: preSegment,- startIndex,- endIndex,- },- deleteEndIndex- );+ this._processPushSequenceNode(sequenceNodes, sequenceNodeType.FUNCTION, preSegment, startIndex, endIndex, deleteEndIndex);}if (i !== len - 1 || !this._isLastMergeString(currentString)) {@@ -379,6 +447,20 @@ export class LexerTreeBuilder extends Disposable {return this._mergeSequenceNodeReference(sequenceNodes);}+ private _processPushSequenceNode(sequenceNodes: (string | ISequenceNode)[], nodeType: sequenceNodeType, token: string, startIndex: number, endIndex: number, deleteEndIndex: number) {+ this._pushSequenceNode(+ sequenceNodes,+ {+ nodeType,+ token,+ startIndex,+ endIndex,+ },+ deleteEndIndex+ );+ }++private _getCurrentParamIndex(formulaString: string, index: number) {return this._nodeMaker(formulaString, undefined, index);}@@ -432,7 +514,7 @@ export class LexerTreeBuilder extends Disposable {typeof node !== 'string' &&nextTwoNode != null &&typeof nextTwoNode !== 'string' &&- isReferenceString((node.token + nextOneNode + nextTwoNode.token).trim())+ isReferenceStringWithEffectiveColumn((node.token + nextOneNode + nextTwoNode.token).trim())) {node.nodeType = sequenceNodeType.REFERENCE;node.token += nextOneNode + nextTwoNode.token;@@ -498,9 +580,7 @@ export class LexerTreeBuilder extends Disposable {}this._resetCurrentLexerNode();-this._currentLexerNode.setToken(DEFAULT_TOKEN_TYPE_ROOT);-const sequenceArray: ISequenceArray[] = [];let state = this._nodeMaker(formulaString, sequenceArray);@@ -517,11 +597,8 @@ export class LexerTreeBuilder extends Disposable {if (injectDefinedName) {const { hasDefinedName, sequenceString, definedNames } = injectDefinedName(sequenceArray);-currentHasDefinedName = hasDefinedName;-currentSequenceString = sequenceString;-currentDefinedNames = definedNames;}@@ -531,11 +608,8 @@ export class LexerTreeBuilder extends Disposable {*/if (currentHasDefinedName) {this._resetCurrentLexerNode();-this._currentLexerNode.setToken(DEFAULT_TOKEN_TYPE_ROOT);-state = this._nodeMaker(`=${currentSequenceString}`);-if (state === ErrorType.VALUE) {return state;}@@ -548,11 +622,9 @@ export class LexerTreeBuilder extends Disposable {if (transformSuffix) {const isValid = this._suffixExpressionHandler(this._currentLexerNode);-if (!isValid) {return ErrorType.VALUE;}-FormulaLexerNodeCache.set(formulaString, this._currentLexerNode);}@@ -613,28 +685,7 @@ export class LexerTreeBuilder extends Disposable {symbolStack.push(node as string);} else if (char === matchToken.CLOSE_BRACKET) {// =()+9, return error- if (this._checkOpenBracket(children[i - 1])) {- return false;- }-- // =1+(1*)- if (this._checkOperator(children[i - 1])) {- return false;- }-- while (symbolStack.length > 0) {- const lastSymbol = symbolStack[symbolStack.length - 1]?.trim();- if (!lastSymbol) {- break;- }-- if (lastSymbol === matchToken.OPEN_BRACKET) {- symbolStack.pop();- break;- }-- baseStack.push(symbolStack.pop()!);- }+ this._processSuffixExpressionCloseBracket(baseStack, symbolStack, children, i);} else {// =(1+3)9, return errorif (this._checkCloseBracket(children[i - 1])) {@@ -647,6 +698,11 @@ export class LexerTreeBuilder extends Disposable {baseStack.push(node);}}++ return this._processSuffixExpressionRemain(baseStack, symbolStack, lexerNode);+ }++ private _processSuffixExpressionRemain(baseStack: (string | LexerNode)[], symbolStack: string[], lexerNode: LexerNode) {const baseStackLength = baseStack.length;const lastBaseStack = baseStack[baseStackLength - 1];while (symbolStack.length > 0) {@@ -657,10 +713,34 @@ export class LexerTreeBuilder extends Disposable {baseStack.push(symbol);}lexerNode.setChildren(baseStack);-return true;}+ private _processSuffixExpressionCloseBracket(baseStack: (string | LexerNode)[], symbolStack: string[], children: (string | LexerNode)[], i: number) {+ if (this._checkOpenBracket(children[i - 1])) {+ return false;+ }++ // =1+(1*)+ if (this._checkOperator(children[i - 1])) {+ return false;+ }++ while (symbolStack.length > 0) {+ const lastSymbol = symbolStack[symbolStack.length - 1]?.trim();+ if (!lastSymbol) {+ break;+ }++ if (lastSymbol === matchToken.OPEN_BRACKET) {+ symbolStack.pop();+ break;+ }++ baseStack.push(symbolStack.pop()!);+ }+ }+private _checkCloseBracket(node: Nullable<string | LexerNode>) {return node === matchToken.CLOSE_BRACKET;}@@ -976,6 +1056,7 @@ export class LexerTreeBuilder extends Disposable {return false;}+ // eslint-disable-next-line max-lines-per-function, complexityprivate _nodeMaker(formulaString: string, sequenceArray?: ISequenceArray[], matchCurrentNodeIndex?: number) {if (formulaString.substring(0, 1) === operatorToken.EQUALS) {formulaString = formulaString.substring(1);@@ -1005,9 +1086,6 @@ export class LexerTreeBuilder extends Disposable {) {if (this._segmentCount() > 0 || this.isLambdaOpen()) {if (this.isLambdaClose()) {- // const subLexerNode = new LexerNode();- // subLexerNode.token = this._segment;- // this.setCurrentLexerNode(subLexerNode);this._newAndPushCurrentLexerNode(this._segment, cur);this._resetSegment();}@@ -1034,12 +1112,7 @@ export class LexerTreeBuilder extends Disposable {this._closeBracket();continue;} else if (nextCurrentString) {- // const subLexerNode = new LexerNode();- // subLexerNode.token = DEFAULT_TOKEN_TYPE_PARAMETER;- // this.setCurrentLexerNode(subLexerNode);this._newAndPushCurrentLexerNode(DEFAULT_TOKEN_TYPE_PARAMETER, cur);-- // this._pushNodeToChildren(matchToken.OPEN_BRACKET);}} else {this._pushNodeToChildren(currentString);@@ -1063,9 +1136,7 @@ export class LexerTreeBuilder extends Disposable {if (!this._setParentCurrentLexerNode() && cur !== formulaStringArrayCount - 1) {return ErrorType.VALUE;}- // const subLexerNode = new LexerNode();- // subLexerNode.token = DEFAULT_TOKEN_TYPE_LAMBDA_PARAMETER;- // this.setCurrentLexerNode(subLexerNode);+this._newAndPushCurrentLexerNode(DEFAULT_TOKEN_TYPE_LAMBDA_PARAMETER, cur, true);this._openLambda();} else {@@ -1173,9 +1244,7 @@ export class LexerTreeBuilder extends Disposable {) {return ErrorType.VALUE;}- // const subLexerNode = new LexerNode();- // subLexerNode.token = DEFAULT_TOKEN_TYPE_PARAMETER;- // this.setCurrentLexerNode(subLexerNode);+this._newAndPushCurrentLexerNode(DEFAULT_TOKEN_TYPE_PARAMETER, cur);} else {/**@@ -1215,12 +1284,6 @@ export class LexerTreeBuilder extends Disposable {this.isBracesClose() &&this.isSquareBracketClose()) {- // const subLexerNode = new LexerNode();- // subLexerNode.token = currentString;- // this.setCurrentLexerNode(subLexerNode);- // this.newAndPushCurrentLexerNode(currentString);- // this._resetSegment();-const subLexerNode_op = new LexerNode();subLexerNode_op.setToken(currentString);@@ -1345,16 +1408,6 @@ export class LexerTreeBuilder extends Disposable {const prevString = this._findPreviousToken(formulaStringArray, cur - 1) || '';if (this._negativeCondition(prevString)) {this._pushSegment(operatorToken.MINUS);-- // if (!(isZeroAdded && cur === 0)) {- // sequenceArray?.push({- // segment: this._segment,- // currentString,- // cur,- // currentLexerNode: this._currentLexerNode,- // });- // }-this._addSequenceArray(sequenceArray, currentString, cur, isZeroAdded);cur++;@@ -1363,14 +1416,6 @@ export class LexerTreeBuilder extends Disposable {} else if (this._segment.length > 0 && this._isScientificNotation(formulaStringArray, cur, currentString)) {this._pushSegment(currentString);- // if (!(isZeroAdded && cur === 0)) {- // sequenceArray?.push({- // segment: this._segment,- // currentString,- // cur,- // currentLexerNode: this._currentLexerNode,- // });- // }this._addSequenceArray(sequenceArray, currentString, cur, isZeroAdded);cur++;@@ -1398,14 +1443,6 @@ export class LexerTreeBuilder extends Disposable {this._pushSegment(currentString);}- // if (!(isZeroAdded && cur === 0)) {- // sequenceArray?.push({- // segment: this._segment,- // currentString,- // cur,- // currentLexerNode: this._currentLexerNode,- // });- // }this._addSequenceArray(sequenceArray, currentString, cur, isZeroAdded);cur++;}diff --git a/packages/engine-formula/src/engine/analysis/lexer.ts b/packages/engine-formula/src/engine/analysis/lexer.tsindex c01ce1f129..1ccc06b0af 100644--- a/packages/engine-formula/src/engine/analysis/lexer.ts+++ b/packages/engine-formula/src/engine/analysis/lexer.ts@@ -14,25 +14,22 @@* limitations under the License.*/-import type { IRange } from '@univerjs/core';-import { AbsoluteRefType, Disposable, isValidRange, IUniverInstanceService, moveRangeByOffset } from '@univerjs/core';+import { Disposable } from '@univerjs/core';import { Inject } from '@wendellhu/redi';import { IDefinedNamesService } from '../../services/defined-names.service';-import type { ISequenceArray, ISequenceNode } from '../utils/sequence';-import { generateStringWithSequence, sequenceNodeType } from '../utils/sequence';+import type { ISequenceArray } from '../utils/sequence';+import { sequenceNodeType } from '../utils/sequence';import { operatorToken } from '../../basics/token';import { IFormulaCurrentConfigService } from '../../services/current-data.service';import { ErrorType } from '../../basics/error-type';-import { deserializeRangeWithSheet, serializeRangeToRefString } from '../utils/reference';import { LexerTreeBuilder } from './lexer-tree-builder';export class Lexer extends Disposable {constructor(@IDefinedNamesService private readonly _definedNamesService: IDefinedNamesService,@Inject(LexerTreeBuilder) private readonly _lexerTreeBuilder: LexerTreeBuilder,- @IFormulaCurrentConfigService private readonly _formulaCurrentConfigService: IFormulaCurrentConfigService,- @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService+ @IFormulaCurrentConfigService private readonly _formulaCurrentConfigService: IFormulaCurrentConfigService) {super();}@@ -41,144 +38,6 @@ export class Lexer extends Disposable {return this._lexerTreeBuilder.treeBuilder(formulaString, transformSuffix, this._injectDefinedName.bind(this), this._simpleCheckDefinedName.bind(this));}- sequenceNodesBuilder(formulaString: string) {- return this._lexerTreeBuilder.sequenceNodesBuilder(formulaString, this._injectDefinedNameCheck.bind(this));- }-- convertRefersToAbsolute(formulaString: string, startAbsoluteRefType: AbsoluteRefType, endAbsoluteRefType: AbsoluteRefType) {- const nodes = this.sequenceNodesBuilder(formulaString);- if (nodes == null) {- return formulaString;- }-- let prefixToken = '';- if (formulaString.substring(0, 1) === operatorToken.EQUALS) {- prefixToken = operatorToken.EQUALS;- }-- for (let i = 0, len = nodes.length; i < len; i++) {- const node = nodes[i];- if (typeof node === 'string') {- continue;- }-- if (node.nodeType === sequenceNodeType.REFERENCE) {- const { token, endIndex } = node;- const sequenceGrid = deserializeRangeWithSheet(token);- if (sequenceGrid == null) {- continue;- }-- const { range, sheetName, unitId } = sequenceGrid;-- const newRange = {- ...range,- startAbsoluteRefType,- endAbsoluteRefType,- };-- const newToken = serializeRangeToRefString({- range: newRange,- unitId,- sheetName,- });-- const minusCount = newToken.length - token.length;-- nodes[i] = {- ...node,- token: newToken,- endIndex: endIndex + minusCount,- };-- /**- * Adjust the start and end indexes of the subsequent nodes.- */- for (let j = i + 1; j < len; j++) {- const nextNode = nodes[j];- if (typeof nextNode === 'string') {- continue;- }-- nextNode.startIndex += minusCount;- nextNode.endIndex += minusCount;- }- }- }-- return `${prefixToken}${generateStringWithSequence(nodes)}`;- }-- moveFormulaRefOffset(formulaString: string, refOffsetX: number, refOffsetY: number, ignoreAbsolute = false) {- const sequenceNodes = this.sequenceNodesBuilder(formulaString);-- if (sequenceNodes == null) {- return formulaString;- }-- const newSequenceNodes: Array<string | ISequenceNode> = [];-- for (let i = 0, len = sequenceNodes.length; i < len; i++) {- const node = sequenceNodes[i];- if (typeof node === 'string' || node.nodeType !== sequenceNodeType.REFERENCE) {- newSequenceNodes.push(node);- continue;- }-- const { token } = node;-- const sequenceGrid = deserializeRangeWithSheet(token);-- const { sheetName, unitId: sequenceUnitId } = sequenceGrid;-- let newRange: IRange = sequenceGrid.range;-- if (newRange.startAbsoluteRefType === AbsoluteRefType.ALL && newRange.endAbsoluteRefType === AbsoluteRefType.ALL) {- newSequenceNodes.push(node);- continue;- } else {- newRange = moveRangeByOffset(newRange, refOffsetX, refOffsetY, ignoreAbsolute);- }-- let newToken = '';- if (isValidRange(newRange)) {- newToken = serializeRangeToRefString({- range: newRange,- unitId: sequenceUnitId,- sheetName,- });- } else {- newToken = ErrorType.REF;- }-- newSequenceNodes.push({- ...node,- token: newToken,- });- }-- return `=${generateStringWithSequence(newSequenceNodes)}`;- }--- private _injectDefinedNameCheck(nodeToken: string) {- let executeUnitId = this._formulaCurrentConfigService.getExecuteUnitId();-- if (!executeUnitId || executeUnitId === '') {- executeUnitId = this._univerInstanceService.getCurrentUniverSheetInstance()?.getUnitId();- }-- if (!executeUnitId || executeUnitId === '') {- return false;- }-- if (this._definedNamesService.getValueByName(executeUnitId, nodeToken)) {- return true;- }-- return false;- }-private _simpleCheckDefinedName(formulaString: string) {const definedNameMap = this._formulaCurrentConfigService.getDirtyDefinedNameMap();const executeUnitId = this._formulaCurrentConfigService.getExecuteUnitId();@@ -222,7 +81,7 @@ export class Lexer extends Disposable {};}- const sequenceNodes = this._lexerTreeBuilder.getSequenceNode(sequenceArray, () => false);+ const sequenceNodes = this._lexerTreeBuilder.getSequenceNode(sequenceArray);let sequenceString = '';let hasDefinedName = false;const definedNames: string[] = [];diff --git a/packages/engine-formula/src/engine/utils/__tests__/reference.spec.ts b/packages/engine-formula/src/engine/utils/__tests__/reference.spec.tsindex 6cfdea9190..3ed61bca5e 100644--- a/packages/engine-formula/src/engine/utils/__tests__/reference.spec.ts+++ b/packages/engine-formula/src/engine/utils/__tests__/reference.spec.ts@@ -22,6 +22,7 @@ import {getAbsoluteRefTypeWithSingleString,getAbsoluteRefTypeWitString,handleRefStringInfo,+ isReferenceStringWithEffectiveColumn,needsQuoting,serializeRange,serializeRangeToRefString,@@ -312,4 +313,16 @@ describe('Test Reference', () => {unitId: 'Book-1.xlsx',});});++ it('isReferenceStringWithEffectiveColumn', () => {+ expect(isReferenceStringWithEffectiveColumn('A1:A2')).toBeTruthy();++ expect(isReferenceStringWithEffectiveColumn('AAA1')).toBeTruthy();++ expect(isReferenceStringWithEffectiveColumn('DefinedName1')).toBeFalsy();++ expect(isReferenceStringWithEffectiveColumn('XFD1')).toBeTruthy();++ expect(isReferenceStringWithEffectiveColumn('XFE1')).toBeFalsy();+ });});diff --git a/packages/engine-formula/src/engine/utils/reference.ts b/packages/engine-formula/src/engine/utils/reference.tsindex bbb7501e1f..b9e24494f5 100644--- a/packages/engine-formula/src/engine/utils/reference.ts+++ b/packages/engine-formula/src/engine/utils/reference.ts@@ -18,7 +18,7 @@ import type { IRange, IUnitRangeName } from '@univerjs/core';import { AbsoluteRefType, RANGE_TYPE, Tools } from '@univerjs/core';import { includeFormulaLexerToken } from '../../basics/match-token';-import { UNIT_NAME_REGEX } from '../../basics/regex';+import { isReferenceString, UNIT_NAME_REGEX } from '../../basics/regex';const $ROW_REGEX = /[^0-9]/g;const $COLUMN_REGEX = /[^A-Za-z]/g;@@ -287,6 +287,27 @@ export function deserializeRangeWithSheet(refString: string): IUnitRangeName {};}+export function isReferenceStringWithEffectiveColumn(refString: string) {+ if (!isReferenceString(refString)) {+ return false;+ }++ const { range } = deserializeRangeWithSheet(refString);++ /**+ * As of the latest information I have, which is up to the end of 2023,+ * the maximum limit for columns in Excel is 16,384.+ * This standard applies to Excel 2007 and later versions,+ * where each worksheet can support columns ranging from A to XFD.+ * Therefore, the symbol for the maximum column is XFD.+ */+ if (range.endColumn >= 16384) {+ return false;+ }++ return true;+}+/*** Determine whether the sheet name needs to be wrapped in quotes* Excel will quote the worksheet name if any of the following is true:diff --git a/packages/engine-formula/src/engine/utils/relative-formula.ts b/packages/engine-formula/src/engine/utils/relative-formula.tsindex 43e9dbd1ed..8baaec822f 100644--- a/packages/engine-formula/src/engine/utils/relative-formula.ts+++ b/packages/engine-formula/src/engine/utils/relative-formula.ts@@ -15,11 +15,12 @@*/import { Rectangle, Tools } from '@univerjs/core';-import type { Lexer } from '../analysis/lexer';++import type { LexerTreeBuilder } from '../analysis/lexer-tree-builder';import { generateStringWithSequence, sequenceNodeType } from './sequence';import { deserializeRangeWithSheet, serializeRange } from './reference';-export function isFormulaTransformable(lexerTreeBuilder: Lexer, formula: string) {+export function isFormulaTransformable(lexerTreeBuilder: LexerTreeBuilder, formula: string) {const originSequenceNodes = lexerTreeBuilder.sequenceNodesBuilder(formula);if (!originSequenceNodes) {return false;@@ -32,7 +33,7 @@ export function isFormulaTransformable(lexerTreeBuilder: Lexer, formula: string)return true;}-export function transformFormula(lexerTreeBuilder: Lexer, formula: string, originRow: number, originCol: number, targetRow: number, targetCol: number) {+export function transformFormula(lexerTreeBuilder: LexerTreeBuilder, formula: string, originRow: number, originCol: number, targetRow: number, targetCol: number) {if (!isFormulaTransformable(lexerTreeBuilder, formula)) {return formula;}diff --git a/packages/engine-formula/src/index.ts b/packages/engine-formula/src/index.tsindex b79720cb45..5f748ebff0 100644--- a/packages/engine-formula/src/index.ts+++ b/packages/engine-formula/src/index.ts@@ -71,7 +71,6 @@ export {export { UnregisterFunctionMutation } from './commands/mutations/unregister-function.mutation';export { LexerNode } from './engine/analysis/lexer-node';export { LexerTreeBuilder } from './engine/analysis/lexer-tree-builder';-export { Lexer } from './engine/analysis/lexer';export { BaseReferenceObject, type FunctionVariantType } from './engine/reference-object/base-reference-object';export { RangeReferenceObject } from './engine/reference-object/range-reference-object';export { deserializeRangeForR1C1 } from './engine/utils/r1c1-reference';@@ -84,6 +83,7 @@ export {serializeRangeToRefString,serializeRangeWithSheet,serializeRangeWithSpreadsheet,+ isReferenceStringWithEffectiveColumn,} from './engine/utils/reference';export { generateStringWithSequence, type ISequenceNode, sequenceNodeType } from './engine/utils/sequence';export { ArrayValueObject, ValueObjectFactory } from './engine/value-object/array-value-object';diff --git a/packages/engine-formula/src/models/formula-data.model.ts b/packages/engine-formula/src/models/formula-data.model.tsindex 17c0177d70..ef72776c95 100644--- a/packages/engine-formula/src/models/formula-data.model.ts+++ b/packages/engine-formula/src/models/formula-data.model.ts@@ -29,7 +29,8 @@ import type {IUnitData,IUnitSheetNameMap,} from '../basics/common';-import { Lexer } from '../engine/analysis/lexer';++import { LexerTreeBuilder } from '../engine/analysis/lexer-tree-builder';import type { IFormulaIdMap } from './utils/formula-data-util';import { clearArrayFormulaCellDataByCell, updateFormulaDataByCellValue } from './utils/formula-data-util';@@ -50,7 +51,7 @@ export class FormulaDataModel extends Disposable {constructor(@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,- @Inject(Lexer) private readonly _lexer: Lexer+ @Inject(LexerTreeBuilder) private readonly _lexerTreeBuilder: LexerTreeBuilder) {super();}@@ -405,7 +406,7 @@ export class FormulaDataModel extends Disposable {} else if (typeof deleteFormula === 'string') {const x = cell.x || 0;const y = cell.y || 0;- const offsetFormula = this._lexer.moveFormulaRefOffset(deleteFormula, x, y);+ const offsetFormula = this._lexerTreeBuilder.moveFormulaRefOffset(deleteFormula, x, y);deleteFormulaIdMap.set(formulaId, {r,diff --git a/packages/engine-formula/src/plugin.ts b/packages/engine-formula/src/plugin.tsindex b989733daa..ef5dcad848 100644--- a/packages/engine-formula/src/plugin.ts+++ b/packages/engine-formula/src/plugin.ts@@ -84,14 +84,14 @@ export class UniverFormulaEnginePlugin extends Plugin {[IDefinedNamesService, { useClass: DefinedNamesService }],[IActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }],[ISuperTableService, { useClass: SuperTableService }],- [IFormulaCurrentConfigService, { useClass: FormulaCurrentConfigService }],+// Models[FormulaDataModel],// Engine[LexerTreeBuilder],- [Lexer],+//Controllers[@@ -112,6 +112,7 @@ export class UniverFormulaEnginePlugin extends Plugin {[CalculateFormulaService],[IOtherFormulaManagerService, { useClass: OtherFormulaManagerService }],[IFormulaRuntimeService, { useClass: FormulaRuntimeService }],+ [IFormulaCurrentConfigService, { useClass: FormulaCurrentConfigService }],//Controller[CalculateController],@@ -122,7 +123,7 @@ export class UniverFormulaEnginePlugin extends Plugin {[FormulaDependencyGenerator],[Interpreter],[AstTreeBuilder],-+ [Lexer],// AstNode factory[AstRootNodeFactory],[FunctionNodeFactory],diff --git a/packages/sheets-conditional-formatting/src/services/calculate-unit/highlight-cell.ts b/packages/sheets-conditional-formatting/src/services/calculate-unit/highlight-cell.tsindex c23e48dbc7..67b753fbb4 100644--- a/packages/sheets-conditional-formatting/src/services/calculate-unit/highlight-cell.ts+++ b/packages/sheets-conditional-formatting/src/services/calculate-unit/highlight-cell.ts@@ -17,7 +17,7 @@import type { IStyleBase } from '@univerjs/core';import { CellValueType, ObjectMatrix, Range, Rectangle, Tools } from '@univerjs/core';import dayjs from 'dayjs';-import { deserializeRangeWithSheet, ERROR_TYPE_SET, generateStringWithSequence, Lexer, sequenceNodeType, serializeRange } from '@univerjs/engine-formula';+import { deserializeRangeWithSheet, ERROR_TYPE_SET, generateStringWithSequence, LexerTreeBuilder, sequenceNodeType, serializeRange } from '@univerjs/engine-formula';import { CFNumberOperator, CFRuleType, CFSubRuleType, CFTextOperator, CFTimePeriodOperator } from '../../base/const';import type { IAverageHighlightCell, IConditionFormattingRule, IFormulaHighlightCell, IHighlightCell, INumberHighlightCell, IRankHighlightCell, ITextHighlightCell, ITimePeriodHighlightCell } from '../../models/type';import { ConditionalFormattingFormulaService, FormulaResultStatus } from '../conditional-formatting-formula.service';@@ -92,9 +92,9 @@ export const highlightCellCalculateUnit: ICalculateUnit = {}case CFSubRuleType.formula: {const subRuleConfig = ruleConfig as IFormulaHighlightCell;- const lexer = context.accessor.get(Lexer);+ const lexerTreeBuilder = context.accessor.get(LexerTreeBuilder);const formulaString = subRuleConfig.value;- const sequenceNodes = lexer.sequenceNodesBuilder(formulaString);+ const sequenceNodes = lexerTreeBuilder.sequenceNodesBuilder(formulaString);if (!sequenceNodes) {return {sequenceNodes: null,diff --git a/packages/sheets-data-validation/src/controllers/dv-ref-range.controller.ts b/packages/sheets-data-validation/src/controllers/dv-ref-range.controller.tsindex 00e5d6c0ae..d8444a1af2 100644--- a/packages/sheets-data-validation/src/controllers/dv-ref-range.controller.ts+++ b/packages/sheets-data-validation/src/controllers/dv-ref-range.controller.ts@@ -25,7 +25,7 @@ import { distinctUntilChanged, map, switchMap } from 'rxjs/operators';import type { IRemoveDataValidationMutationParams, IUpdateDataValidationMutationParams } from '@univerjs/data-validation';import { DataValidationModel, RemoveDataValidationMutation, removeDataValidationUndoFactory, UpdateDataValidationMutation, UpdateRuleType } from '@univerjs/data-validation';import { FormulaRefRangeService } from '@univerjs/sheets-formula';-import { deserializeRangeWithSheet, isReferenceString, serializeRangeWithSpreadsheet } from '@univerjs/engine-formula';+import { deserializeRangeWithSheet, isReferenceStringWithEffectiveColumn, serializeRangeWithSpreadsheet } from '@univerjs/engine-formula';import { DataValidationCustomFormulaService } from '../services/dv-custom-formula.service';import { DataValidationFormulaService } from '../services/dv-formula.service';import { DataValidationCacheService } from '../services/dv-cache.service';@@ -214,7 +214,7 @@ export class DataValidationRefRangeController extends Disposable {return;}- if (!isReferenceString(formula1 ?? '')) {+ if (!isReferenceStringWithEffectiveColumn(formula1 ?? '')) {return;}const gridRange = deserializeRangeWithSheet(formula1 ?? '');diff --git a/packages/sheets-data-validation/src/services/dv-custom-formula.service.ts b/packages/sheets-data-validation/src/services/dv-custom-formula.service.tsindex c8f9fb600a..2d9f7bc39d 100644--- a/packages/sheets-data-validation/src/services/dv-custom-formula.service.ts+++ b/packages/sheets-data-validation/src/services/dv-custom-formula.service.ts@@ -16,7 +16,7 @@import type { IRange, ISheetDataValidationRule } from '@univerjs/core';import { DataValidationType, Disposable, isFormulaString, IUniverInstanceService, ObjectMatrix, Range } from '@univerjs/core';-import { isFormulaTransformable, Lexer, transformFormula } from '@univerjs/engine-formula';+import { isFormulaTransformable, LexerTreeBuilder, transformFormula } from '@univerjs/engine-formula';import { Inject } from '@wendellhu/redi';import { DataValidationModel } from '@univerjs/data-validation';import { RegisterOtherFormulaService } from './register-formula.service';@@ -62,7 +62,7 @@ export class DataValidationCustomFormulaService extends Disposable {constructor(@Inject(RegisterOtherFormulaService) private _registerOtherFormulaService: RegisterOtherFormulaService,- @Inject(Lexer) private _lexer: Lexer,+ @Inject(LexerTreeBuilder) private _lexerTreeBuilder: LexerTreeBuilder,@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,@Inject(DataValidationModel) private readonly _dataValidationModel: DataValidationModel,@Inject(DataValidationCacheService) private readonly _dataValidationCacheService: DataValidationCacheService@@ -181,7 +181,7 @@ export class DataValidationCustomFormulaService extends Disposable {}const isTransformable = isFormulaTransformable(- this._lexer,+ this._lexerTreeBuilder,formula);@@ -193,7 +193,7 @@ export class DataValidationCustomFormulaService extends Disposable {ranges.forEach((range) => {Range.foreach(range, (row, column) => {const relativeFormula = transformFormula(- this._lexer,+ this._lexerTreeBuilder,formula,originRow,originCol,@@ -268,7 +268,7 @@ export class DataValidationCustomFormulaService extends Disposable {}if (isTransformable) {- const relativeText = transformFormula(this._lexer, formula, originRow, originCol, row, col);+ const relativeText = transformFormula(this._lexerTreeBuilder, formula, originRow, originCol, row, col);const formulaId = this._registerFormula(unitId, subUnitId, ruleId, relativeText);formulaMap.setValue(row, col, {// formulaText: relativeText,diff --git a/packages/sheets-data-validation/src/validators/list-multiple-validator.ts b/packages/sheets-data-validation/src/validators/list-multiple-validator.tsindex a4024824a8..17221fb703 100644--- a/packages/sheets-data-validation/src/validators/list-multiple-validator.ts+++ b/packages/sheets-data-validation/src/validators/list-multiple-validator.ts@@ -18,7 +18,7 @@ import { DataValidationType, IUniverInstanceService, Tools } from '@univerjs/corimport type { CellValue, DataValidationOperator, IDataValidationRule, IDataValidationRuleBase, Nullable } from '@univerjs/core';import type { IFormulaResult, IFormulaValidResult, IValidatorCellInfo } from '@univerjs/data-validation';import { BaseDataValidator } from '@univerjs/data-validation';-import { deserializeRangeWithSheet, isReferenceString } from '@univerjs/engine-formula';+import { deserializeRangeWithSheet, isReferenceStringWithEffectiveColumn } from '@univerjs/engine-formula';import { LIST_FORMULA_INPUT_NAME } from '../views/formula-input';import { LIST_DROPDOWN_KEY } from '../views';import { DropdownMultipleWidget } from '../widgets/dropdown-multiple-widget';@@ -62,7 +62,7 @@ export class ListMultipleValidator extends BaseDataValidator {const { formula1 = '' } = rule;return {- formula1: isReferenceString(formula1) ? getSheetRangeValueSet(deserializeRangeWithSheet(formula1), this._univerInstanceService, unitId, subUnitId) : deserializeListOptions(formula1),+ formula1: isReferenceStringWithEffectiveColumn(formula1) ? getSheetRangeValueSet(deserializeRangeWithSheet(formula1), this._univerInstanceService, unitId, subUnitId) : deserializeListOptions(formula1),formula2: undefined,};}@@ -91,7 +91,7 @@ export class ListMultipleValidator extends BaseDataValidator {const worksheet = (propSubUnitId ? workbook.getSheetBySheetId(propSubUnitId) : undefined) ?? workbook.getActiveSheet();const unitId = workbook.getUnitId();const subUnitId = worksheet.getSheetId();- return isReferenceString(formula1) ? getSheetRangeValueSet(deserializeRangeWithSheet(formula1), this._univerInstanceService, unitId, subUnitId) : deserializeListOptions(formula1);+ return isReferenceStringWithEffectiveColumn(formula1) ? getSheetRangeValueSet(deserializeRangeWithSheet(formula1), this._univerInstanceService, unitId, subUnitId) : deserializeListOptions(formula1);}getListWithColor(rule: IDataValidationRule, currentUnitId?: string, currentSubUnitId?: string) {diff --git a/packages/sheets-data-validation/src/validators/list-validator.ts b/packages/sheets-data-validation/src/validators/list-validator.tsindex 318edfa45f..2557f7688b 100644--- a/packages/sheets-data-validation/src/validators/list-validator.ts+++ b/packages/sheets-data-validation/src/validators/list-validator.ts@@ -18,7 +18,7 @@ import { DataValidationRenderMode, DataValidationType, IUniverInstanceService, Timport type { CellValue, DataValidationOperator, IDataValidationRule, IDataValidationRuleBase, ISheetDataValidationRule, Nullable } from '@univerjs/core';import type { IFormulaResult, IFormulaValidResult, IValidatorCellInfo } from '@univerjs/data-validation';import { BaseDataValidator } from '@univerjs/data-validation';-import { deserializeRangeWithSheet, isReferenceString } from '@univerjs/engine-formula';+import { deserializeRangeWithSheet, isReferenceStringWithEffectiveColumn } from '@univerjs/engine-formula';import { LIST_FORMULA_INPUT_NAME } from '../views/formula-input';import { LIST_DROPDOWN_KEY } from '../views';import { DropdownWidget } from '../widgets/dropdown-widget';@@ -62,7 +62,7 @@ export class ListValidator extends BaseDataValidator {const { formula1 = '' } = rule;return {- formula1: isReferenceString(formula1) ? getSheetRangeValueSet(deserializeRangeWithSheet(formula1), this._univerInstanceService, unitId, subUnitId) : deserializeListOptions(formula1),+ formula1: isReferenceStringWithEffectiveColumn(formula1) ? getSheetRangeValueSet(deserializeRangeWithSheet(formula1), this._univerInstanceService, unitId, subUnitId) : deserializeListOptions(formula1),formula2: undefined,};}@@ -91,7 +91,7 @@ export class ListValidator extends BaseDataValidator {const worksheet = (currentSubUnitId ? workbook.getSheetBySheetId(currentSubUnitId) : undefined) ?? workbook.getActiveSheet();const unitId = workbook.getUnitId();const subUnitId = worksheet.getSheetId();- return isReferenceString(formula1)+ return isReferenceStringWithEffectiveColumn(formula1)? getSheetRangeValueSet(deserializeRangeWithSheet(formula1), this._univerInstanceService, unitId, subUnitId): deserializeListOptions(formula1);}diff --git a/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsx b/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsxindex 4b1185d94e..766e5f3b33 100644--- a/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsx+++ b/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsx@@ -17,7 +17,7 @@import { RangeSelector, useEvent } from '@univerjs/ui';import React, { useEffect, useMemo, useRef, useState } from 'react';import { DraggableList, FormLayout, Input, Radio, RadioGroup, Select } from '@univerjs/design';-import { deserializeRangeWithSheet, isReferenceString, serializeRangeWithSheet } from '@univerjs/engine-formula';+import { deserializeRangeWithSheet, isReferenceStringWithEffectiveColumn, serializeRangeWithSheet } from '@univerjs/engine-formula';import { useDependency } from '@wendellhu/redi/react-bindings';import type { IRange } from '@univerjs/core';import { createInternalEditorID, IUniverInstanceService, LocaleService, Tools } from '@univerjs/core';@@ -150,7 +150,7 @@ export function ListFormulaInput(props: IFormulaInputProps) {const { value, onChange: _onChange = () => { }, unitId, subUnitId, validResult, showError } = props;const { formula1 = '', formula2 = '' } = value || {};const containerRef = useRef<HTMLDivElement>(null);- const [isRefRange, setIsRefRange] = useState(() => isReferenceString(formula1) ? '1' : '0');+ const [isRefRange, setIsRefRange] = useState(() => isReferenceStringWithEffectiveColumn(formula1) ? '1' : '0');const [refRange, setRefRange] = useState(isRefRange === '1' ? formula1 : '');const localeService = useDependency(LocaleService);const univerInstanceService = useDependency(IUniverInstanceService);diff --git a/packages/sheets-formula/src/controllers/__tests__/create-command-test-bed.ts b/packages/sheets-formula/src/controllers/__tests__/create-command-test-bed.tsindex 65fefb8a8d..9c6c5ed69f 100644--- a/packages/sheets-formula/src/controllers/__tests__/create-command-test-bed.ts+++ b/packages/sheets-formula/src/controllers/__tests__/create-command-test-bed.ts@@ -16,7 +16,7 @@import type { IWorkbookData, Workbook } from '@univerjs/core';import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, PluginType, Univer } from '@univerjs/core';-import { CalculateFormulaService, DefinedNamesService, FormulaCurrentConfigService, FormulaDataModel, FormulaRuntimeService, IDefinedNamesService, IFormulaCurrentConfigService, IFormulaRuntimeService, Lexer, LexerTreeBuilder } from '@univerjs/engine-formula';+import { CalculateFormulaService, DefinedNamesService, FormulaCurrentConfigService, FormulaDataModel, FormulaRuntimeService, IDefinedNamesService, IFormulaCurrentConfigService, IFormulaRuntimeService, LexerTreeBuilder } from '@univerjs/engine-formula';import { SelectionManagerService, SheetInterceptorService } from '@univerjs/sheets';import type { Dependency } from '@wendellhu/redi';import { Inject, Injector } from '@wendellhu/redi';@@ -79,7 +79,6 @@ export function createCommandTestBed(workbookConfig?: IWorkbookData, dependencieinjector.add([CalculateFormulaService]);injector.add([FormulaDataModel]);injector.add([LexerTreeBuilder]);- injector.add([Lexer]);injector.add([IDefinedNamesService, { useClass: DefinedNamesService }]);injector.add([IFormulaRuntimeService, { useClass: FormulaRuntimeService }]);injector.add([IFormulaCurrentConfigService, { useClass: FormulaCurrentConfigService }]);diff --git a/packages/sheets-formula/src/controllers/__tests__/formula-clipboard.controller.spec.ts b/packages/sheets-formula/src/controllers/__tests__/formula-clipboard.controller.spec.tsindex 6b2bc040bd..9fa2104bc7 100644--- a/packages/sheets-formula/src/controllers/__tests__/formula-clipboard.controller.spec.ts+++ b/packages/sheets-formula/src/controllers/__tests__/formula-clipboard.controller.spec.ts@@ -16,7 +16,7 @@import type { ICellData, Nullable, Univer } from '@univerjs/core';import { ICommandService, IUniverInstanceService, ObjectMatrix } from '@univerjs/core';-import { Lexer } from '@univerjs/engine-formula';+import { LexerTreeBuilder } from '@univerjs/engine-formula';import { type ISetRangeValuesMutationParams, SetRangeValuesMutation } from '@univerjs/sheets';import type { ICellDataWithSpanInfo } from '@univerjs/sheets-ui';import { COPY_TYPE, ISelectionRenderService, PREDEFINED_HOOK_NAME, SelectionRenderService } from '@univerjs/sheets-ui';@@ -30,7 +30,7 @@ describe('Test paste with formula', () => {let univer: Univer;let get: Injector['get'];let commandService: ICommandService;- let lexer: Lexer;+ let lexerTreeBuilder: LexerTreeBuilder;let getValues: (startRow: number,startColumn: number,@@ -45,7 +45,7 @@ describe('Test paste with formula', () => {univer = testBed.univer;get = testBed.get;commandService = get(ICommandService);- lexer = get(Lexer);+ lexerTreeBuilder = get(LexerTreeBuilder);getValues = (startRow: number,@@ -164,7 +164,7 @@ describe('Test paste with formula', () => {matrix,accessor,copyInfo,- lexer+ lexerTreeBuilder);expect(redoUndoList).toStrictEqual(result);@@ -608,7 +608,7 @@ describe('Test paste with formula', () => {matrix,accessor,copyInfo,- lexer+ lexerTreeBuilder);// Randomly generated id, no comparison is madediff --git a/packages/sheets-formula/src/controllers/formula-auto-fill.controller.ts b/packages/sheets-formula/src/controllers/formula-auto-fill.controller.tsindex 27ba600422..7e4e2aa913 100644--- a/packages/sheets-formula/src/controllers/formula-auto-fill.controller.ts+++ b/packages/sheets-formula/src/controllers/formula-auto-fill.controller.ts@@ -24,7 +24,7 @@ import {OnLifecycle,Tools,} from '@univerjs/core';-import { Lexer } from '@univerjs/engine-formula';+import { LexerTreeBuilder } from '@univerjs/engine-formula';import type { AutoFillService, IAutoFillRule, ICopyDataInTypeIndexInfo, ICopyDataPiece } from '@univerjs/sheets-ui';import { APPLY_TYPE, DATA_TYPE, IAutoFillService } from '@univerjs/sheets-ui';import { Inject } from '@wendellhu/redi';@@ -33,7 +33,7 @@ import { Inject } from '@wendellhu/redi';export class FormulaAutoFillController extends Disposable {constructor(@IAutoFillService private readonly _autoFillService: AutoFillService,- @Inject(Lexer) private readonly _lexer: Lexer+ @Inject(LexerTreeBuilder) private readonly _lexerTreeBuilder: LexerTreeBuilder) {super();@@ -107,7 +107,7 @@ export class FormulaAutoFillController extends Disposable {formulaIdMap.set(index, formulaId);const { offsetX, offsetY } = directionToOffset(step, direction);- const shiftedFormula = this._lexer.moveFormulaRefOffset(+ const shiftedFormula = this._lexerTreeBuilder.moveFormulaRefOffset(originalFormula,offsetX,offsetYdiff --git a/packages/sheets-formula/src/controllers/formula-clipboard.controller.ts b/packages/sheets-formula/src/controllers/formula-clipboard.controller.tsindex e857bd66da..743941299b 100644--- a/packages/sheets-formula/src/controllers/formula-clipboard.controller.ts+++ b/packages/sheets-formula/src/controllers/formula-clipboard.controller.ts@@ -25,7 +25,7 @@ import {OnLifecycle,Tools,} from '@univerjs/core';-import { Lexer } from '@univerjs/engine-formula';+import { LexerTreeBuilder } from '@univerjs/engine-formula';import type { ISetRangeValuesMutationParams } from '@univerjs/sheets';import { SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '@univerjs/sheets';import type { ICellDataWithSpanInfo, ICopyPastePayload, ISheetClipboardHook, ISheetRangeLocation } from '@univerjs/sheets-ui';@@ -41,7 +41,7 @@ export const DEFAULT_PASTE_FORMULA = 'default-paste-formula';export class FormulaClipboardController extends Disposable {constructor(@IUniverInstanceService private readonly _currentUniverSheet: IUniverInstanceService,- @Inject(Lexer) private readonly _lexer: Lexer,+ @Inject(LexerTreeBuilder) private readonly _lexerTreeBuilder: LexerTreeBuilder,@ISheetClipboardService private readonly _sheetClipboardService: ISheetClipboardService,@Inject(Injector) private readonly _injector: Injector) {@@ -101,7 +101,7 @@ export class FormulaClipboardController extends Disposable {matrix,accessor,copyInfo,- this._lexer,+ this._lexerTreeBuilder,isSpecialPaste));}@@ -118,7 +118,7 @@ export function getSetCellFormulaMutations(copyRange?: IRange;pasteType: string;},- lexer: Lexer,+ lexerTreeBuilder: LexerTreeBuilder,isSpecialPaste = false) {const redoMutationsInfo: IMutationInfo[] = [];@@ -177,7 +177,7 @@ export function getSetCellFormulaMutations(const offsetX = col + startColumn - (copyRangeStartColumn + colIndex);const offsetY = row + startRow - (copyRangeStartRow + rowIndex);- const shiftedFormula = lexer.moveFormulaRefOffset(originalFormula, offsetX, offsetY);+ const shiftedFormula = lexerTreeBuilder.moveFormulaRefOffset(originalFormula, offsetX, offsetY);valueObject.si = formulaId;valueObject.f = shiftedFormula;diff --git a/packages/sheets-formula/src/controllers/formula-editor-show.controller.ts b/packages/sheets-formula/src/controllers/formula-editor-show.controller.tsindex 25d69262ee..5d9b4af700 100644--- a/packages/sheets-formula/src/controllers/formula-editor-show.controller.ts+++ b/packages/sheets-formula/src/controllers/formula-editor-show.controller.ts@@ -29,7 +29,7 @@ import {import {ErrorType,FormulaDataModel,- Lexer,+ LexerTreeBuilder,SetArrayFormulaDataMutation,SetFormulaCalculationResultMutation,} from '@univerjs/engine-formula';@@ -50,7 +50,7 @@ export class FormulaEditorShowController extends Disposable {constructor(@Inject(IEditorBridgeService) private _editorBridgeService: IEditorBridgeService,@Inject(FormulaDataModel) private readonly _formulaDataModel: FormulaDataModel,- @Inject(Lexer) private readonly _lexer: Lexer,+ @Inject(LexerTreeBuilder) private readonly _lexerTreeBuilder: LexerTreeBuilder,@Inject(ThemeService) private readonly _themeService: ThemeService,@IRenderManagerService private readonly _renderManagerService: IRenderManagerService,@ISelectionRenderService private readonly _selectionRenderService: ISelectionRenderService,@@ -115,7 +115,7 @@ export class FormulaEditorShowController extends Disposable {formulaString = originItem.f;}- const newFormulaString = this._lexer.moveFormulaRefOffset(+ const newFormulaString = this._lexerTreeBuilder.moveFormulaRefOffset(formulaString,x,ydiff --git a/packages/sheets-formula/src/controllers/prompt.controller.ts b/packages/sheets-formula/src/controllers/prompt.controller.tsindex 5afe716c01..2b8ed9a876 100644--- a/packages/sheets-formula/src/controllers/prompt.controller.ts+++ b/packages/sheets-formula/src/controllers/prompt.controller.ts@@ -53,7 +53,6 @@ import {deserializeRangeWithSheet,generateStringWithSequence,getAbsoluteRefTypeWitString,- Lexer,LexerTreeBuilder,matchRefDrawToken,matchToken,@@ -160,7 +159,6 @@ export class PromptController extends Disposable {@Inject(IEditorBridgeService) private readonly _editorBridgeService: EditorBridgeService,@Inject(IFormulaPromptService) private readonly _formulaPromptService: IFormulaPromptService,@Inject(LexerTreeBuilder) private readonly _lexerTreeBuilder: LexerTreeBuilder,- @Inject(Lexer) private readonly _lexer: Lexer,@IRenderManagerService private readonly _renderManagerService: IRenderManagerService,@Inject(ThemeService) private readonly _themeService: ThemeService,@Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService,@@ -813,7 +811,7 @@ export class PromptController extends Disposable {this._contextService.setContextValue(FOCUSING_EDITOR_INPUT_FORMULA, true);const lastSequenceNodes =- this._lexer.sequenceNodesBuilder(config.dataStream.replace(/\r/g, '').replace(/\n/g, '')) ||+ this._lexerTreeBuilder.sequenceNodesBuilder(config.dataStream.replace(/\r/g, '').replace(/\n/g, '')) ||[];this._formulaPromptService.setSequenceNodes(lastSequenceNodes);@@ -1922,7 +1920,7 @@ export class PromptController extends Disposable {});}- const lastSequenceNodes = this._lexer.sequenceNodesBuilder(formulaString) || [];+ const lastSequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString) || [];this._formulaPromptService.setSequenceNodes(lastSequenceNodes);diff --git a/packages/sheets-formula/src/controllers/update-formula.controller.ts b/packages/sheets-formula/src/controllers/update-formula.controller.tsindex aeac3a8a8d..c8312622b7 100644--- a/packages/sheets-formula/src/controllers/update-formula.controller.ts+++ b/packages/sheets-formula/src/controllers/update-formula.controller.ts@@ -39,7 +39,7 @@ import { deserializeRangeWithSheet,FormulaDataModel,generateStringWithSequence,initSheetFormulaData,- Lexer,+ LexerTreeBuilder,sequenceNodeType,serializeRangeToRefString,SetArrayFormulaDataMutation,@@ -162,7 +162,7 @@ export class UpdateFormulaController extends Disposable {constructor(@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,@ICommandService private readonly _commandService: ICommandService,- @Inject(Lexer) private readonly _lexer: Lexer,+ @Inject(LexerTreeBuilder) private readonly _lexerTreeBuilder: LexerTreeBuilder,@Inject(FormulaDataModel) private readonly _formulaDataModel: FormulaDataModel,@Inject(SheetInterceptorService) private _sheetInterceptorService: SheetInterceptorService,@Inject(SelectionManagerService) private _selectionManagerService: SelectionManagerService,@@ -674,7 +674,7 @@ export class UpdateFormulaController extends Disposable {const { f: formulaString, x, y, si } = formulaDataItem;- const sequenceNodes = this._lexer.sequenceNodesBuilder(formulaString);+ const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString);if (sequenceNodes == null) {return true;diff --git a/packages/sheets-formula/src/services/description.service.ts b/packages/sheets-formula/src/services/description.service.tsindex c7357bc2bc..77b8543913 100644--- a/packages/sheets-formula/src/services/description.service.ts+++ b/packages/sheets-formula/src/services/description.service.ts@@ -35,7 +35,7 @@ import {functionUniver,functionWeb,IFunctionService,- isReferenceString,+ isReferenceStringWithEffectiveColumn,} from '@univerjs/engine-formula';import type { IDisposable } from '@wendellhu/redi';import { createIdentifier, Inject } from '@wendellhu/redi';@@ -213,7 +213,7 @@ export class DescriptionService implements IDescriptionService, IDisposable {const token = items[0].description;return !token.split(',').every((refString) => {- return isReferenceString(refString.trim());+ return isReferenceStringWithEffectiveColumn(refString.trim());});}diff --git a/packages/sheets-formula/src/services/formula-ref-range.service.ts b/packages/sheets-formula/src/services/formula-ref-range.service.tsindex 97ef9fc5e3..9baecac623 100644--- a/packages/sheets-formula/src/services/formula-ref-range.service.ts+++ b/packages/sheets-formula/src/services/formula-ref-range.service.ts@@ -16,7 +16,7 @@import type { IMutationInfo, IRange } from '@univerjs/core';import { Disposable, DisposableCollection, IUniverInstanceService } from '@univerjs/core';-import { deserializeRangeWithSheet, ErrorType, generateStringWithSequence, Lexer, sequenceNodeType, serializeRange, serializeRangeWithSheet, serializeRangeWithSpreadsheet } from '@univerjs/engine-formula';+import { deserializeRangeWithSheet, ErrorType, generateStringWithSequence, LexerTreeBuilder, sequenceNodeType, serializeRange, serializeRangeWithSheet, serializeRangeWithSpreadsheet } from '@univerjs/engine-formula';import type { EffectRefRangeParams } from '@univerjs/sheets';import { handleDefaultRangeChangeWithEffectRefCommands, RefRangeService } from '@univerjs/sheets';import type { IDisposable } from '@wendellhu/redi';@@ -32,7 +32,7 @@ export type FormulaChangeCallback = (formulaString: string) => {export class FormulaRefRangeService extends Disposable {constructor(@Inject(RefRangeService) private readonly _refRangeService: RefRangeService,- @Inject(Lexer) private readonly _lexer: Lexer,+ @Inject(LexerTreeBuilder) private readonly _lexerTreeBuilder: LexerTreeBuilder,@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService) {super();@@ -40,7 +40,7 @@ export class FormulaRefRangeService extends Disposable {registerFormula(formula: string, callback: FormulaChangeCallback): IDisposable {const rangeMap = new Map<string, { unitId: string; subUnitId: string; range: IRange; sheetName: string }>();- const sequenceNodes = this._lexer.sequenceNodesBuilder(formula);+ const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formula);const disposableCollection = new DisposableCollection();const handleChange = (params: EffectRefRangeParams) => {const workbook = this._univerInstanceService.getCurrentUniverSheetInstance()!;diff --git a/packages/sheets-ui/src/controllers/selection.controller.ts b/packages/sheets-ui/src/controllers/selection.controller.tsindex 427334a18a..9c083a85f1 100644--- a/packages/sheets-ui/src/controllers/selection.controller.ts+++ b/packages/sheets-ui/src/controllers/selection.controller.ts@@ -42,7 +42,7 @@ import {} from '@univerjs/sheets';import { Inject } from '@wendellhu/redi';-import { deserializeRangeWithSheet, IDefinedNamesService, isReferenceString, operatorToken } from '@univerjs/engine-formula';+import { deserializeRangeWithSheet, IDefinedNamesService, isReferenceStringWithEffectiveColumn, operatorToken } from '@univerjs/engine-formula';import type { ISetZoomRatioOperationParams } from '../commands/operations/set-zoom-ratio.operation';import { SetZoomRatioOperation } from '../commands/operations/set-zoom-ratio.operation';import { VIEWPORT_KEY } from '../common/keys';@@ -120,7 +120,7 @@ export class SelectionController extends Disposable {const valueArray = formulaOrRefString.split(',');const result = valueArray.every((refString) => {- return isReferenceString(refString.trim());+ return isReferenceStringWithEffectiveColumn(refString.trim());});if (!result) {diff --git a/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx b/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsxindex 4d75697c55..80c2c67a41 100644--- a/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx+++ b/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx@@ -21,7 +21,7 @@ import type { IUnitRange, Nullable } from '@univerjs/core';import { AbsoluteRefType, createInternalEditorID, IUniverInstanceService, LocaleService, Tools } from '@univerjs/core';import { useDependency } from '@wendellhu/redi/react-bindings';import { Button, Input, Radio, RadioGroup, Select } from '@univerjs/design';-import { IDefinedNamesService, type IDefinedNamesServiceParam, IFunctionService, isReferenceString, Lexer, operatorToken, serializeRangeToRefString } from '@univerjs/engine-formula';+import { IDefinedNamesService, type IDefinedNamesServiceParam, IFunctionService, isReferenceStringWithEffectiveColumn, LexerTreeBuilder, operatorToken, serializeRangeToRefString } from '@univerjs/engine-formula';import { ErrorSingle } from '@univerjs/icons';import { hasCJKText } from '@univerjs/engine-render';import styles from './index.module.less';@@ -60,7 +60,7 @@ export const DefinedNameInput = (props: IDefinedNameInputProps) => {const localeService = useDependency(LocaleService);const definedNamesService = useDependency(IDefinedNamesService);const functionService = useDependency(IFunctionService);- const lexer = useDependency(Lexer);+ const lexerTreeBuilder = useDependency(LexerTreeBuilder);if (workbook == null) {return;@@ -111,7 +111,7 @@ export const DefinedNameInput = (props: IDefinedNameInputProps) => {const isFormula = (token: string) => {return !token.split(',').every((refString) => {- return isReferenceString(refString.trim());+ return isReferenceStringWithEffectiveColumn(refString.trim());});};@@ -153,7 +153,7 @@ export const DefinedNameInput = (props: IDefinedNameInputProps) => {return;}- if (!Tools.isValidParameter(nameValue) || (!Tools.isStartValidPosition(nameValue) && !hasCJKText(nameValue.substring(0, 1)))) {+ if (!Tools.isValidParameter(nameValue) || isReferenceStringWithEffectiveColumn(nameValue) || (!Tools.isStartValidPosition(nameValue) && !hasCJKText(nameValue.substring(0, 1)))) {setValidString(localeService.t('definedName.nameInvalid'));return;}@@ -185,7 +185,7 @@ export const DefinedNameInput = (props: IDefinedNameInputProps) => {confirm && confirm({id: id || '',name: nameValue,- formulaOrRefString: lexer.convertRefersToAbsolute(formulaOrRefStringValue, AbsoluteRefType.ALL, AbsoluteRefType.ALL),+ formulaOrRefString: lexerTreeBuilder.convertRefersToAbsolute(formulaOrRefStringValue, AbsoluteRefType.ALL, AbsoluteRefType.ALL),comment: commentValue,localSheetId: localSheetIdValue,});diff --git a/packages/ui/src/components/range-selector/RangeSelector.tsx b/packages/ui/src/components/range-selector/RangeSelector.tsxindex e14bfd820b..31ed807c79 100644--- a/packages/ui/src/components/range-selector/RangeSelector.tsx+++ b/packages/ui/src/components/range-selector/RangeSelector.tsx@@ -21,7 +21,7 @@ import { CloseSingle, DeleteSingle, IncreaseSingle, SelectRangeSingle } from '@uimport { useDependency } from '@wendellhu/redi/react-bindings';import React, { useEffect, useRef, useState } from 'react';-import { deserializeRangeWithSheet, isReferenceString, serializeRange, serializeRangeWithSheet, serializeRangeWithSpreadsheet } from '@univerjs/engine-formula';+import { deserializeRangeWithSheet, isReferenceStringWithEffectiveColumn, serializeRange, serializeRangeWithSheet, serializeRangeWithSpreadsheet } from '@univerjs/engine-formula';import clsx from 'clsx';import { TextEditor } from '../editor/TextEditor';import { IEditorService } from '../../services/editor/editor.service';@@ -225,11 +225,11 @@ export function RangeSelector(props: IRangeSelectorProps) {let result = '';const list = rangeDataList.filter((rangeRef) => {- return isReferenceString(rangeRef.trim());+ return isReferenceStringWithEffectiveColumn(rangeRef.trim());});if (list.length === 1) {const rangeRef = list[0];- if (isReferenceString(rangeRef.trim())) {+ if (isReferenceStringWithEffectiveColumn(rangeRef.trim())) {result = rangeRef.trim();}} else {@@ -261,7 +261,7 @@ export function RangeSelector(props: IRangeSelectorProps) {}const result = valueArray.every((refString) => {- return isReferenceString(refString.trim());+ return isReferenceStringWithEffectiveColumn(refString.trim());});if (!result) {diff --git a/packages/ui/src/services/editor/editor.service.ts b/packages/ui/src/services/editor/editor.service.tsindex f7c63b811e..cfe92a66d1 100644--- a/packages/ui/src/services/editor/editor.service.ts+++ b/packages/ui/src/services/editor/editor.service.ts@@ -22,7 +22,7 @@ import type { Observable } from 'rxjs';import { Subject } from 'rxjs';import type { IRender, ISuccinctTextRangeParam, Scene } from '@univerjs/engine-render';import { IRenderManagerService, UNIVER_GLOBAL_DEFAULT_FONT_SIZE } from '@univerjs/engine-render';-import { isReferenceString, LexerTreeBuilder, operatorToken } from '@univerjs/engine-formula';+import { isReferenceStringWithEffectiveColumn, LexerTreeBuilder, operatorToken } from '@univerjs/engine-formula';export interface IEditorStateParam extends Partial<IPosition> {visible?: boolean;@@ -705,7 +705,7 @@ export class EditorService extends Disposable implements IEditorService, IDisposreturn false;}const result = valueArray.every((refString) => {- return isReferenceString(refString.trim());+ return isReferenceStringWithEffectiveColumn(refString.trim());});editor.setValueLegality(result);}