1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_FORMULA_GRAMMAR_HXX
21 #define INCLUDED_FORMULA_GRAMMAR_HXX
23 #include <com/sun/star/sheet/FormulaLanguage.hpp>
24 #include <formula/formuladllapi.h>
25 #include <sal/types.h>
30 /** Grammars digested by ScCompiler.
32 class FORMULA_DLLPUBLIC FormulaGrammar
35 enum AddressConvention
{
36 CONV_UNSPECIFIED
= -1, /* useful when we want method to chose, must be first */
38 /* elements must be sequential and changes should be reflected in ScCompiler::pCharTables */
39 CONV_OOO
= 0, /* 'doc'#sheet.A1:sheet2.B2 */
40 CONV_ODF
, /* ['doc'#sheet.A1:sheet2.B2] */
41 CONV_XL_A1
, /* [doc]sheet:sheet2!A1:B2 */
42 CONV_XL_R1C1
, /* [doc]sheet:sheet2!R1C1:R2C2 */
43 CONV_XL_OOX
, /* [#]sheet:sheet2!A1:B2 */
45 CONV_LOTUS_A1
, /* external? 3d? A1.B2 <placeholder/> */
47 CONV_LAST
, /* for loops, must always be last */
49 // not a real address convention, a special case for INDIRECT function interpretation
50 // only -> try using CONV_OOO, failing that CONV_XL_A1
54 //! CONV_UNSPECIFIED is a negative value!
55 static const int kConventionOffset
= - CONV_UNSPECIFIED
+ 1;
56 // Room for 32k hypothetical languages plus EXTERNAL.
57 static const int kConventionShift
= 16;
58 // Room for 256 reference conventions.
59 static const int kEnglishBit
= (1 << (kConventionShift
+ 8));
60 // Mask off all non-language bits.
61 static const int kFlagMask
= ~((~unsigned(0)) << kConventionShift
);
63 /** Values encoding the formula language plus address reference convention
64 plus English parsing/formatting
66 //! When adding new values adapt isSupported() below as well.
69 /// Used only in ScCompiler ctor and in some XML import API context.
70 GRAM_UNSPECIFIED
= -1,
71 /// ODFF with default ODF A1 bracketed references.
72 GRAM_ODFF
= css::sheet::FormulaLanguage::ODFF
|
74 kConventionOffset
) << kConventionShift
) |
76 /// ODF 1.1 with default ODF A1 bracketed references.
77 GRAM_PODF
= css::sheet::FormulaLanguage::ODF_11
|
79 kConventionOffset
) << kConventionShift
) |
81 /// English with default A1 reference style.
82 GRAM_ENGLISH
= css::sheet::FormulaLanguage::ENGLISH
|
84 kConventionOffset
) << kConventionShift
) |
86 /// Native with default A1 reference style.
87 GRAM_NATIVE
= css::sheet::FormulaLanguage::NATIVE
|
89 kConventionOffset
) << kConventionShift
),
90 /// ODFF with reference style as set in UI, may be A1 or R1C1.
91 GRAM_ODFF_UI
= css::sheet::FormulaLanguage::ODFF
|
93 kConventionOffset
) << kConventionShift
) |
95 /// ODFF with A1 reference style, unbracketed.
96 GRAM_ODFF_A1
= css::sheet::FormulaLanguage::ODFF
|
98 kConventionOffset
) << kConventionShift
) |
100 /// ODF 1.1 with reference style as set in UI, may be A1 or R1C1.
101 GRAM_PODF_UI
= css::sheet::FormulaLanguage::ODF_11
|
103 kConventionOffset
) << kConventionShift
) |
105 /// ODF 1.1 with A1 reference style, unbracketed.
106 GRAM_PODF_A1
= css::sheet::FormulaLanguage::ODF_11
|
108 kConventionOffset
) << kConventionShift
) |
110 /// Native with reference style as set in UI, may be A1 or R1C1.
111 GRAM_NATIVE_UI
= css::sheet::FormulaLanguage::NATIVE
|
113 kConventionOffset
) << kConventionShift
),
114 /// Native with ODF A1 bracketed references. Not very useful but supported.
115 GRAM_NATIVE_ODF
= css::sheet::FormulaLanguage::NATIVE
|
117 kConventionOffset
) << kConventionShift
),
118 /// Native with Excel A1 reference style.
119 GRAM_NATIVE_XL_A1
= css::sheet::FormulaLanguage::NATIVE
|
121 kConventionOffset
) << kConventionShift
),
122 /// Native with Excel R1C1 reference style.
123 GRAM_NATIVE_XL_R1C1
= css::sheet::FormulaLanguage::NATIVE
|
125 kConventionOffset
) << kConventionShift
),
126 /// English with Excel A1 reference style.
127 GRAM_ENGLISH_XL_A1
= css::sheet::FormulaLanguage::XL_ENGLISH
|
129 kConventionOffset
) << kConventionShift
) |
131 /// English with Excel R1C1 reference style.
132 GRAM_ENGLISH_XL_R1C1
= css::sheet::FormulaLanguage::XL_ENGLISH
|
134 kConventionOffset
) << kConventionShift
) |
136 /// English with Excel OOXML reference style.
137 GRAM_ENGLISH_XL_OOX
= css::sheet::FormulaLanguage::XL_ENGLISH
|
139 kConventionOffset
) << kConventionShift
) |
141 /// Excel OOXML with Excel OOXML reference style.
142 GRAM_OOXML
= css::sheet::FormulaLanguage::OOXML
|
144 kConventionOffset
) << kConventionShift
) |
146 /// API English with A1 reference style, unbracketed.
147 GRAM_API
= css::sheet::FormulaLanguage::API
|
149 kConventionOffset
) << kConventionShift
) |
151 /// Central definition of the default grammar to be used.
152 GRAM_DEFAULT
= GRAM_NATIVE_UI
,
154 /// Central definition of the default storage grammar to be used.
155 GRAM_STORAGE_DEFAULT
= GRAM_ODFF
,
157 /** OpCodeMap set by external filter and merged with reference
158 convention plus English bit on top. Plain value acts as
160 GRAM_EXTERNAL
= (1 << (kConventionShift
- 1))
163 /// If English parsing/formatting is associated with a grammar.
164 static bool isEnglish( const Grammar eGrammar
)
166 return (eGrammar
& kEnglishBit
) != 0;
169 /** Compatibility helper for old "bCompileEnglish, bCompileXML" API calls
170 to obtain the new grammar. */
171 static Grammar
mapAPItoGrammar( const bool bEnglish
, const bool bXML
);
173 static bool isSupported( const Grammar eGrammar
);
175 static sal_Int32
extractFormulaLanguage( const Grammar eGrammar
)
177 return eGrammar
& kFlagMask
;
180 static AddressConvention
extractRefConvention( const Grammar eGrammar
)
182 return static_cast<AddressConvention
>(
183 ((eGrammar
& ~kEnglishBit
) >> kConventionShift
) -
187 static Grammar
setEnglishBit( const Grammar eGrammar
, const bool bEnglish
);
189 static Grammar
mergeToGrammar( const Grammar eGrammar
, const AddressConvention eConv
);
191 /// If grammar is of ODF 1.1
192 static bool isPODF( const Grammar eGrammar
)
194 return extractFormulaLanguage( eGrammar
) ==
195 css::sheet::FormulaLanguage::ODF_11
;
198 /// If grammar is of ODFF
199 static bool isODFF( const Grammar eGrammar
)
201 return extractFormulaLanguage( eGrammar
) ==
202 css::sheet::FormulaLanguage::ODFF
;
205 /// If grammar is of OOXML
206 static bool isOOXML( const Grammar eGrammar
)
208 return extractFormulaLanguage( eGrammar
) ==
209 css::sheet::FormulaLanguage::OOXML
;
212 /// If grammar has an Excel syntax, determined by address convention.
213 static bool isExcelSyntax( const Grammar eGrammar
)
215 AddressConvention eConv
= extractRefConvention( eGrammar
);
218 case FormulaGrammar::AddressConvention::CONV_XL_A1
:
219 case FormulaGrammar::AddressConvention::CONV_XL_R1C1
:
220 case FormulaGrammar::AddressConvention::CONV_XL_OOX
:
232 #endif // INCLUDED_FORMULA_GRAMMAR_HXX
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */