LibreOffice Module formula (master) 1
grammar.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_FORMULA_GRAMMAR_HXX
21#define INCLUDED_FORMULA_GRAMMAR_HXX
22
23#include <com/sun/star/sheet/FormulaLanguage.hpp>
25#include <sal/types.h>
26
27namespace formula
28{
29
33{
34public:
36 CONV_UNSPECIFIED = -1, /* useful when we want method to choose, must be first */
37
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 */
44
45 CONV_LOTUS_A1, /* external? 3d? A1.B2 <placeholder/> */
46
47 CONV_LAST, /* for loops, must always be last */
48
49 // not a real address convention, a special case for INDIRECT function interpretation
50 // only -> try using CONV_OOO, failing that CONV_XL_A1
51 CONV_A1_XL_A1
52 };
53
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);
62
68 {
70 GRAM_UNSPECIFIED = -1,
72 GRAM_ODFF = css::sheet::FormulaLanguage::ODFF |
73 ((CONV_ODF +
74 kConventionOffset) << kConventionShift) |
75 kEnglishBit,
77 GRAM_PODF = css::sheet::FormulaLanguage::ODF_11 |
78 ((CONV_ODF +
79 kConventionOffset) << kConventionShift) |
80 kEnglishBit,
82 GRAM_ENGLISH = css::sheet::FormulaLanguage::ENGLISH |
83 ((CONV_OOO +
84 kConventionOffset) << kConventionShift) |
85 kEnglishBit,
87 GRAM_NATIVE = css::sheet::FormulaLanguage::NATIVE |
88 ((CONV_OOO +
89 kConventionOffset) << kConventionShift),
91 GRAM_ODFF_UI = css::sheet::FormulaLanguage::ODFF |
92 ((CONV_UNSPECIFIED +
93 kConventionOffset) << kConventionShift) |
94 kEnglishBit,
96 GRAM_ODFF_A1 = css::sheet::FormulaLanguage::ODFF |
97 ((CONV_OOO +
98 kConventionOffset) << kConventionShift) |
99 kEnglishBit,
101 GRAM_PODF_UI = css::sheet::FormulaLanguage::ODF_11 |
102 ((CONV_UNSPECIFIED +
103 kConventionOffset) << kConventionShift) |
104 kEnglishBit,
106 GRAM_PODF_A1 = css::sheet::FormulaLanguage::ODF_11 |
107 ((CONV_OOO +
108 kConventionOffset) << kConventionShift) |
109 kEnglishBit,
111 GRAM_NATIVE_UI = css::sheet::FormulaLanguage::NATIVE |
112 ((CONV_UNSPECIFIED +
113 kConventionOffset) << kConventionShift),
115 GRAM_NATIVE_ODF = css::sheet::FormulaLanguage::NATIVE |
116 ((CONV_ODF +
117 kConventionOffset) << kConventionShift),
119 GRAM_NATIVE_XL_A1 = css::sheet::FormulaLanguage::NATIVE |
120 ((CONV_XL_A1 +
121 kConventionOffset) << kConventionShift),
123 GRAM_NATIVE_XL_R1C1 = css::sheet::FormulaLanguage::NATIVE |
124 ((CONV_XL_R1C1 +
125 kConventionOffset) << kConventionShift),
127 GRAM_ENGLISH_XL_A1 = css::sheet::FormulaLanguage::XL_ENGLISH |
128 ((CONV_XL_A1 +
129 kConventionOffset) << kConventionShift) |
130 kEnglishBit,
132 GRAM_ENGLISH_XL_R1C1 = css::sheet::FormulaLanguage::XL_ENGLISH |
133 ((CONV_XL_R1C1 +
134 kConventionOffset) << kConventionShift) |
135 kEnglishBit,
137 GRAM_ENGLISH_XL_OOX = css::sheet::FormulaLanguage::XL_ENGLISH |
138 ((CONV_XL_OOX +
139 kConventionOffset) << kConventionShift) |
140 kEnglishBit,
142 GRAM_OOXML = css::sheet::FormulaLanguage::OOXML |
143 ((CONV_XL_OOX +
144 kConventionOffset) << kConventionShift) |
145 kEnglishBit,
147 GRAM_API = css::sheet::FormulaLanguage::API |
148 ((CONV_OOO +
149 kConventionOffset) << kConventionShift) |
150 kEnglishBit,
152 GRAM_DEFAULT = GRAM_NATIVE_UI,
153
155 GRAM_STORAGE_DEFAULT = GRAM_ODFF,
156
160 GRAM_EXTERNAL = (1 << (kConventionShift - 1))
161 };
162
164 static bool isEnglish( const Grammar eGrammar )
165 {
166 return (eGrammar & kEnglishBit) != 0;
167 }
168
171 static Grammar mapAPItoGrammar( const bool bEnglish, const bool bXML );
172
173 static bool isSupported( const Grammar eGrammar );
174
175 static sal_Int32 extractFormulaLanguage( const Grammar eGrammar )
176 {
177 return eGrammar & kFlagMask;
178 }
179
181 {
182 return static_cast<AddressConvention>(
183 ((eGrammar & ~kEnglishBit) >> kConventionShift) -
184 kConventionOffset);
185 }
186
187 static Grammar setEnglishBit( const Grammar eGrammar, const bool bEnglish );
188
189 static Grammar mergeToGrammar( const Grammar eGrammar, const AddressConvention eConv );
190
192 static bool isPODF( const Grammar eGrammar )
193 {
194 return extractFormulaLanguage( eGrammar) ==
195 css::sheet::FormulaLanguage::ODF_11;
196 }
197
199 static bool isODFF( const Grammar eGrammar )
200 {
201 return extractFormulaLanguage( eGrammar) ==
202 css::sheet::FormulaLanguage::ODFF;
203 }
204
206 static bool isOOXML( const Grammar eGrammar )
207 {
208 return extractFormulaLanguage( eGrammar) ==
209 css::sheet::FormulaLanguage::OOXML;
210 }
211
219 static bool isRefConventionOOXML( const Grammar eGrammar )
220 {
221 return extractRefConvention( eGrammar) ==
222 FormulaGrammar::AddressConvention::CONV_XL_OOX;
223 }
224
226 static bool isExcelSyntax( const Grammar eGrammar )
227 {
228 AddressConvention eConv = extractRefConvention( eGrammar );
229 switch (eConv)
230 {
231 case FormulaGrammar::AddressConvention::CONV_XL_A1:
232 case FormulaGrammar::AddressConvention::CONV_XL_R1C1:
233 case FormulaGrammar::AddressConvention::CONV_XL_OOX:
234 return true;
235 default:
236 return false;
237 }
238 }
239
240};
241
242} // formula
243
244
245#endif // INCLUDED_FORMULA_GRAMMAR_HXX
246
247/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Grammars digested by ScCompiler.
Definition: grammar.hxx:33
static bool isODFF(const Grammar eGrammar)
If grammar is of ODFF.
Definition: grammar.hxx:199
static sal_Int32 extractFormulaLanguage(const Grammar eGrammar)
Definition: grammar.hxx:175
static bool isPODF(const Grammar eGrammar)
If grammar is of ODF 1.1.
Definition: grammar.hxx:192
static bool isExcelSyntax(const Grammar eGrammar)
If grammar has an Excel syntax, determined by address convention.
Definition: grammar.hxx:226
static bool isEnglish(const Grammar eGrammar)
If English parsing/formatting is associated with a grammar.
Definition: grammar.hxx:164
Grammar
Values encoding the formula language plus address reference convention plus English parsing/formattin...
Definition: grammar.hxx:68
static AddressConvention extractRefConvention(const Grammar eGrammar)
Definition: grammar.hxx:180
static bool isRefConventionOOXML(const Grammar eGrammar)
If reference convention is OOXML.
Definition: grammar.hxx:219
static bool isOOXML(const Grammar eGrammar)
If grammar is of OOXML.
Definition: grammar.hxx:206
#define FORMULA_DLLPUBLIC
Definition: formuladllapi.h:28
Grammar