From 70cb7757f971c4c16d1b0a5585d95816cd4382e6 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Wed, 17 May 2017 15:21:25 +0200 Subject: Resolves: tdf#96426 more whitespace intersection operator in Excel syntax Handle also stacked token arrays resulting from named expressions like =range1 range2 Change-Id: I1838af155f17b5e4f941e46895303caed75b6075 --- formula/source/core/api/FormulaCompiler.cxx | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'formula') diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx index 7a28568ad590..b626039efed7 100644 --- a/formula/source/core/api/FormulaCompiler.cxx +++ b/formula/source/core/api/FormulaCompiler.cxx @@ -1245,7 +1245,7 @@ bool FormulaCompiler::GetToken() if ( nRecursion > nRecursionMax ) { SetError( FormulaError::StackOverflow ); - mpToken = new FormulaByteToken( ocStop ); + mpLastToken = mpToken = new FormulaByteToken( ocStop ); return false; } if ( bAutoCorrect && !pStack ) @@ -1258,7 +1258,6 @@ bool FormulaCompiler::GetToken() bStop = true; else { - FormulaTokenRef pCurrToken = mpToken; FormulaTokenRef pSpacesToken; short nWasColRowName; if ( pArr->nIndex > 0 && pArr->pCode[ pArr->nIndex-1 ]->GetOpCode() == ocColRowName ) @@ -1284,6 +1283,9 @@ bool FormulaCompiler::GetToken() if( pStack ) { PopTokenArray(); + // mpLastToken was popped as well and corresponds to the + // then current last token during PushTokenArray(), e.g. for + // HandleRange(). return GetToken(); } else @@ -1293,17 +1295,17 @@ bool FormulaCompiler::GetToken() { if ( nWasColRowName >= 2 && mpToken->GetOpCode() == ocColRowName ) { // convert an ocSpaces to ocIntersect in RPN - mpToken = new FormulaByteToken( ocIntersect ); + mpLastToken = mpToken = new FormulaByteToken( ocIntersect ); pArr->nIndex--; // we advanced to the second ocColRowName, step back } else if (pSpacesToken && FormulaGrammar::isExcelSyntax( meGrammar) && - pCurrToken && mpToken && - isPotentialRangeType( pCurrToken.get(), false, false) && + mpLastToken && mpToken && + isPotentialRangeType( mpLastToken.get(), false, false) && isPotentialRangeType( mpToken.get(), false, true)) { // Let IntersectionLine() <- Factor() decide how to treat this, // once the actual arguments are determined in RPN. - mpToken = pSpacesToken; + mpLastToken = mpToken = pSpacesToken; pArr->nIndex--; // step back from next non-spaces token return true; } @@ -1311,9 +1313,14 @@ bool FormulaCompiler::GetToken() } if( bStop ) { - mpToken = new FormulaByteToken( ocStop ); + mpLastToken = mpToken = new FormulaByteToken( ocStop ); return false; } + + // Remember token for next round and any PushTokenArray() calls that may + // occur in handlers. + mpLastToken = mpToken; + if ( mpToken->IsExternalRef() ) { return HandleExternalReference(*mpToken); @@ -2042,6 +2049,7 @@ void FormulaCompiler::PopTokenArray() if( p->bTemp ) delete pArr; pArr = p->pArr; + mpLastToken = p->mpLastToken; delete p; } } @@ -2602,6 +2610,7 @@ void FormulaCompiler::PushTokenArray( FormulaTokenArray* pa, bool bTemp ) FormulaArrayStack* p = new FormulaArrayStack; p->pNext = pStack; p->pArr = pArr; + p->mpLastToken = mpLastToken; p->bTemp = bTemp; pStack = p; pArr = pa; -- cgit