calc-grammar-xls-english-sc.diff: Support Excel English grammar

Support Excel English grammar needed for VBA and (probably) for xlsx filter.
This commit is contained in:
Kohei Yoshida 2010-09-16 10:05:05 +02:00 committed by Fridrich Štrba
parent 4a5b4325d7
commit 6964bfe879
3 changed files with 35 additions and 0 deletions

View file

@ -320,6 +320,7 @@ private:
void InitSymbolsEnglish() const; /// only SymbolsEnglish, maybe later
void InitSymbolsPODF() const; /// only SymbolsPODF, on demand
void InitSymbolsODFF() const; /// only SymbolsODFF, on demand
void InitSymbolsEnglishXL() const; /// only SymbolsEnglishXL, on demand
void loadSymbols(USHORT _nSymbols,FormulaGrammar::Grammar _eGrammar,NonConstOpCodeMapPtr& _xMap) const;
@ -373,6 +374,7 @@ private:
mutable NonConstOpCodeMapPtr mxSymbolsPODF; // ODF 1.1 symbols
mutable NonConstOpCodeMapPtr mxSymbolsNative; // native symbols
mutable NonConstOpCodeMapPtr mxSymbolsEnglish; // English symbols
mutable NonConstOpCodeMapPtr mxSymbolsEnglishXL; // English Excel symbols (for VBA formula parsing)
};
// =============================================================================
} // formula

View file

@ -127,6 +127,16 @@ public:
GRAM_NATIVE_XL_R1C1 = ::com::sun::star::sheet::FormulaLanguage::NATIVE |
((CONV_XL_R1C1 +
kConventionOffset) << kConventionShift),
/// English with Excel A1 reference style.
GRAM_ENGLISH_XL_A1 = ::com::sun::star::sheet::FormulaLanguage::XL_ENGLISH |
((CONV_XL_A1 +
kConventionOffset) << kConventionShift) |
kEnglishBit,
/// English with Excel R1C1 reference style.
GRAM_ENGLISH_XL_R1C1 = ::com::sun::star::sheet::FormulaLanguage::XL_ENGLISH |
((CONV_XL_R1C1 +
kConventionOffset) << kConventionShift) |
kEnglishBit,
/// Central definition of the default grammar to be used.
GRAM_DEFAULT = GRAM_NATIVE_UI,
@ -177,6 +187,8 @@ public:
case GRAM_NATIVE_ODF :
case GRAM_NATIVE_XL_A1 :
case GRAM_NATIVE_XL_R1C1 :
case GRAM_ENGLISH_XL_A1 :
case GRAM_ENGLISH_XL_R1C1:
return true;
default:
return extractFormulaLanguage( eGrammar) == GRAM_EXTERNAL;

View file

@ -568,6 +568,11 @@ FormulaCompiler::OpCodeMapPtr FormulaCompiler::GetOpCodeMap( const sal_Int32 nLa
InitSymbolsNative();
xMap = mxSymbolsNative;
break;
case FormulaLanguage::XL_ENGLISH:
if (!mxSymbolsEnglishXL)
InitSymbolsEnglishXL();
xMap = mxSymbolsEnglishXL;
break;
default:
; // nothing, NULL map returned
}
@ -680,6 +685,22 @@ void FormulaCompiler::InitSymbolsODFF() const
loadSymbols(RID_STRLIST_FUNCTION_NAMES_ENGLISH_ODFF,FormulaGrammar::GRAM_ODFF,s_sSymbol);
mxSymbolsODFF = s_sSymbol;
}
// -----------------------------------------------------------------------------
void FormulaCompiler::InitSymbolsEnglishXL() const
{
static NonConstOpCodeMapPtr s_sSymbol;
if ( !s_sSymbol.get() )
loadSymbols(RID_STRLIST_FUNCTION_NAMES_ENGLISH,FormulaGrammar::GRAM_ENGLISH,s_sSymbol);
mxSymbolsEnglishXL = s_sSymbol;
// TODO: For now, just replace the separators to the Excel English
// variants. Later, if we want to properly map Excel functions with Calc
// functions, we'll need to do a little more work here.
mxSymbolsEnglishXL->putOpCode(sal_Unicode(','), ocSep);
mxSymbolsEnglishXL->putOpCode(sal_Unicode(','), ocArrayColSep);
mxSymbolsEnglishXL->putOpCode(sal_Unicode(';'), ocArrayRowSep);
}
// -----------------------------------------------------------------------------
void FormulaCompiler::loadSymbols(USHORT _nSymbols,FormulaGrammar::Grammar _eGrammar,NonConstOpCodeMapPtr& _xMap) const
{