Kaydet (Commit) 70cb7757 authored tarafından Eike Rathke's avatar Eike Rathke

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
üst 6a21827e
...@@ -1245,7 +1245,7 @@ bool FormulaCompiler::GetToken() ...@@ -1245,7 +1245,7 @@ bool FormulaCompiler::GetToken()
if ( nRecursion > nRecursionMax ) if ( nRecursion > nRecursionMax )
{ {
SetError( FormulaError::StackOverflow ); SetError( FormulaError::StackOverflow );
mpToken = new FormulaByteToken( ocStop ); mpLastToken = mpToken = new FormulaByteToken( ocStop );
return false; return false;
} }
if ( bAutoCorrect && !pStack ) if ( bAutoCorrect && !pStack )
...@@ -1258,7 +1258,6 @@ bool FormulaCompiler::GetToken() ...@@ -1258,7 +1258,6 @@ bool FormulaCompiler::GetToken()
bStop = true; bStop = true;
else else
{ {
FormulaTokenRef pCurrToken = mpToken;
FormulaTokenRef pSpacesToken; FormulaTokenRef pSpacesToken;
short nWasColRowName; short nWasColRowName;
if ( pArr->nIndex > 0 && pArr->pCode[ pArr->nIndex-1 ]->GetOpCode() == ocColRowName ) if ( pArr->nIndex > 0 && pArr->pCode[ pArr->nIndex-1 ]->GetOpCode() == ocColRowName )
...@@ -1284,6 +1283,9 @@ bool FormulaCompiler::GetToken() ...@@ -1284,6 +1283,9 @@ bool FormulaCompiler::GetToken()
if( pStack ) if( pStack )
{ {
PopTokenArray(); PopTokenArray();
// mpLastToken was popped as well and corresponds to the
// then current last token during PushTokenArray(), e.g. for
// HandleRange().
return GetToken(); return GetToken();
} }
else else
...@@ -1293,17 +1295,17 @@ bool FormulaCompiler::GetToken() ...@@ -1293,17 +1295,17 @@ bool FormulaCompiler::GetToken()
{ {
if ( nWasColRowName >= 2 && mpToken->GetOpCode() == ocColRowName ) if ( nWasColRowName >= 2 && mpToken->GetOpCode() == ocColRowName )
{ // convert an ocSpaces to ocIntersect in RPN { // 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 pArr->nIndex--; // we advanced to the second ocColRowName, step back
} }
else if (pSpacesToken && FormulaGrammar::isExcelSyntax( meGrammar) && else if (pSpacesToken && FormulaGrammar::isExcelSyntax( meGrammar) &&
pCurrToken && mpToken && mpLastToken && mpToken &&
isPotentialRangeType( pCurrToken.get(), false, false) && isPotentialRangeType( mpLastToken.get(), false, false) &&
isPotentialRangeType( mpToken.get(), false, true)) isPotentialRangeType( mpToken.get(), false, true))
{ {
// Let IntersectionLine() <- Factor() decide how to treat this, // Let IntersectionLine() <- Factor() decide how to treat this,
// once the actual arguments are determined in RPN. // once the actual arguments are determined in RPN.
mpToken = pSpacesToken; mpLastToken = mpToken = pSpacesToken;
pArr->nIndex--; // step back from next non-spaces token pArr->nIndex--; // step back from next non-spaces token
return true; return true;
} }
...@@ -1311,9 +1313,14 @@ bool FormulaCompiler::GetToken() ...@@ -1311,9 +1313,14 @@ bool FormulaCompiler::GetToken()
} }
if( bStop ) if( bStop )
{ {
mpToken = new FormulaByteToken( ocStop ); mpLastToken = mpToken = new FormulaByteToken( ocStop );
return false; return false;
} }
// Remember token for next round and any PushTokenArray() calls that may
// occur in handlers.
mpLastToken = mpToken;
if ( mpToken->IsExternalRef() ) if ( mpToken->IsExternalRef() )
{ {
return HandleExternalReference(*mpToken); return HandleExternalReference(*mpToken);
...@@ -2042,6 +2049,7 @@ void FormulaCompiler::PopTokenArray() ...@@ -2042,6 +2049,7 @@ void FormulaCompiler::PopTokenArray()
if( p->bTemp ) if( p->bTemp )
delete pArr; delete pArr;
pArr = p->pArr; pArr = p->pArr;
mpLastToken = p->mpLastToken;
delete p; delete p;
} }
} }
...@@ -2602,6 +2610,7 @@ void FormulaCompiler::PushTokenArray( FormulaTokenArray* pa, bool bTemp ) ...@@ -2602,6 +2610,7 @@ void FormulaCompiler::PushTokenArray( FormulaTokenArray* pa, bool bTemp )
FormulaArrayStack* p = new FormulaArrayStack; FormulaArrayStack* p = new FormulaArrayStack;
p->pNext = pStack; p->pNext = pStack;
p->pArr = pArr; p->pArr = pArr;
p->mpLastToken = mpLastToken;
p->bTemp = bTemp; p->bTemp = bTemp;
pStack = p; pStack = p;
pArr = pa; pArr = pa;
......
...@@ -59,6 +59,7 @@ struct FormulaArrayStack ...@@ -59,6 +59,7 @@ struct FormulaArrayStack
{ {
FormulaArrayStack* pNext; FormulaArrayStack* pNext;
FormulaTokenArray* pArr; FormulaTokenArray* pArr;
FormulaTokenRef mpLastToken;
bool bTemp; bool bTemp;
}; };
...@@ -330,6 +331,7 @@ protected: ...@@ -330,6 +331,7 @@ protected:
FormulaTokenRef pCurrentFactorToken; // current factor token (of Factor() method) FormulaTokenRef pCurrentFactorToken; // current factor token (of Factor() method)
sal_uInt16 nCurrentFactorParam; // current factor token's parameter, 1-based sal_uInt16 nCurrentFactorParam; // current factor token's parameter, 1-based
FormulaTokenArray* pArr; FormulaTokenArray* pArr;
FormulaTokenRef mpLastToken; // last token
FormulaToken** pCode; FormulaToken** pCode;
FormulaArrayStack* pStack; FormulaArrayStack* pStack;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment