1 #ifndef _GNM_PARSE_UTIL_H_
2 # define _GNM_PARSE_UTIL_H_
5 #include <libgnumeric.h>
9 char const *col_name (int col
);
10 char const *cols_name (int start_col
, int end_col
);
11 char const *col_parse (char const *str
, GnmSheetSize
const *ss
,
12 int *res
, unsigned char *relative
);
14 char const *row_name (int row
);
15 char const *rows_name (int start_row
, int end_row
);
16 char const *row_parse (char const *str
, GnmSheetSize
const *ss
,
17 int *res
, unsigned char *relative
);
19 char const *cellpos_as_string (GnmCellPos
const *pos
);
20 char const *cellpos_parse (char const *cell_str
, GnmSheetSize
const *ss
,
21 GnmCellPos
*res
, gboolean strict
);
22 void cellref_as_string (GnmConventionsOut
*out
,
23 GnmCellRef
const *cell_ref
,
24 gboolean no_sheetname
);
25 char const *cellref_parse (GnmCellRef
*out
, GnmSheetSize
const *ss
,
26 char const *in
, GnmCellPos
const *pos
);
28 void rangeref_as_string (GnmConventionsOut
*out
,
29 GnmRangeRef
const *ref
);
30 char const *rangeref_parse (GnmRangeRef
*res
, char const *start
,
31 GnmParsePos
const *pp
,
32 GnmConventions
const *convs
);
35 char const *cell_coord_name (int col
, int row
);
36 char const *cell_name (GnmCell
const *cell
);
38 char const *parsepos_as_string (GnmParsePos
const *pp
);
40 /* backwards compatibility version */
41 void gnm_1_0_rangeref_as_string (GnmConventionsOut
*out
,
42 GnmRangeRef
const *ref
);
45 struct _GnmConventionsOut
{
47 GnmParsePos
const *pp
;
48 GnmConventions
const *convs
;
53 PERR_MISSING_PAREN_OPEN
,
54 PERR_MISSING_PAREN_CLOSE
,
55 PERR_MISSING_CLOSING_QUOTE
,
56 PERR_INVALID_EXPRESSION
,
57 PERR_INVALID_ARRAY_SEPARATOR
,
58 PERR_UNKNOWN_WORKBOOK
,
61 PERR_UNEXPECTED_TOKEN
,
63 PERR_SHEET_IS_REQUIRED
,
66 PERR_MULTIPLE_EXPRESSIONS
,
69 PERR_SET_CONTENT_MUST_BE_RANGE
73 struct _GnmParseError
{
75 int begin_char
, end_char
;
82 GType
gnm_lexer_item_get_type (void); /* Boxed type */
84 GType
gnm_parse_error_get_type (void); /* Boxed type */
85 GnmParseError
*parse_error_init (GnmParseError
*pe
);
86 void parse_error_free (GnmParseError
*pe
);
89 GNM_EXPR_PARSE_DEFAULT
= 0, /* default is Excel */
90 GNM_EXPR_PARSE_FORCE_ABSOLUTE_REFERENCES
= 1 << 0,
91 GNM_EXPR_PARSE_FORCE_RELATIVE_REFERENCES
= 1 << 0,
92 GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES
= 1 << 2,
93 GNM_EXPR_PARSE_PERMIT_MULTIPLE_EXPRESSIONS
= 1 << 3,
94 GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_STRINGS
= 1 << 4,
95 GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_INVALID
= 1 << 5
98 struct _GnmConventions
{
103 gboolean force_absolute_col_references
;
104 gboolean force_absolute_row_references
;
105 gboolean force_explicit_sheet_references
;
107 gboolean r1c1_addresses
;
109 /* Whether function names should be translated. */
110 gboolean localized_function_names
;
112 /* Separate elements in lists, 0 will use go_locale. */
114 /* Separate array columns, 0 will use go_locale. */
115 gunichar array_col_sep
;
116 /* Separate array rows, 0 will use go_locale. */
117 gunichar array_row_sep
;
119 /* What character denotes range intersection? */
120 gunichar intersection_char
;
121 /* What character denotes range union? */
124 /* What characters are range separators? */
125 gboolean range_sep_colon
; /* A1:B2 */
126 gboolean range_sep_dotdot
; /* A1..B2 */
128 /* Separates sheet name from the cell ref */
129 gunichar sheet_name_sep
;
131 /* Formerly USE_APPLIX_CONVENTIONS. */
132 gboolean ignore_whitespace
;
134 /* Formerly more or less part of USE_APPLIX_CONVENTIONS. */
135 gboolean allow_absolute_sheet_references
;
137 /* Formerly part of USE_OPENCALC_CONVENTIONS. */
138 gboolean decode_ampersands
;
140 /* Is the decimal separator "." (as opposed to locale's)? */
141 gboolean decimal_sep_dot
;
143 /* Accept prefix #NOT# and infixs #AND# and #OR#. */
144 gboolean accept_hash_logicals
;
146 /* If TRUE, parse x^y^z as (x^y)^z. */
147 gboolean exp_is_left_associative
;
149 /* Import specific functions ------------------------------------- */
150 struct _GnmConventionsImport
{
151 /* Called a lot for anything that might be a reference. */
152 char const *(*range_ref
) (GnmRangeRef
*res
, char const *in
,
153 GnmParsePos
const *pp
,
154 GnmConventions
const *convs
);
157 /* Called to unescape strings */
158 char const *(*string
) (char const *in
, GString
*target
,
159 GnmConventions
const *convs
);
161 /* Called a lot for anything that might be a function name or
163 char const *(*name
) (char const *in
,
164 GnmConventions
const *convs
);
165 /* Returns true if a tentative expression name is legal. */
166 gboolean (*name_validate
) (const char *name
);
168 /* Must return non-NULL, and absorb the args, including the list. */
169 GnmExpr
const *(*func
) (GnmConventions
const *convs
,
170 /* make scope more useful, eg a
171 * ParsePos * to allow for
172 * sheet/object specific functions
177 Workbook
*(*external_wb
) (GnmConventions
const *convs
,
179 char const *unquoted_name
);
182 /* Export specific functions ----------------------------------- */
183 struct _GnmConventionsExport
{
188 void (*string
) (GnmConventionsOut
*out
,
189 GOString
const *str
);
190 void (*func
) (GnmConventionsOut
*out
,
191 GnmExprFunction
const *func
);
192 void (*name
) (GnmConventionsOut
*out
,
193 GnmExprName
const *name
);
194 void (*cell_ref
) (GnmConventionsOut
*out
,
195 GnmCellRef
const *cell_ref
,
196 gboolean no_sheetname
);
197 void (*range_ref
) (GnmConventionsOut
*out
,
198 GnmRangeRef
const *range_ref
);
199 void (*boolean
) (GnmConventionsOut
*out
,
202 GString
* (*quote_sheet_name
) (GnmConventions
const *convs
,
206 GType
gnm_conventions_get_type (void);
207 GnmConventions
*gnm_conventions_new (void);
208 GnmConventions
*gnm_conventions_new_full (unsigned size
);
210 GnmConventions
*gnm_conventions_ref (GnmConventions
const *c
);
211 void gnm_conventions_unref (GnmConventions
*c
);
214 GNM_VAR_DECL GnmConventions
const *gnm_conventions_default
;
215 GNM_VAR_DECL GnmConventions
const *gnm_conventions_xls_r1c1
;
217 /**********************************************/
219 void parse_util_init (void);
220 void parse_util_shutdown (void);
222 GnmExprTop
const *gnm_expr_parse_str (char const *str
, GnmParsePos
const *pp
,
223 GnmExprParseFlags flags
,
224 GnmConventions
const *convs
,
225 GnmParseError
*error
);
227 GnmLexerItem
*gnm_expr_lex_all (char const *str
, GnmParsePos
const *pp
,
228 GnmExprParseFlags flags
,
229 GnmConventions
const *convs
);
232 /* Is this string potentially the start of an expression */
233 char const *gnm_expr_char_start_p (char const *c
);
235 void parse_text_value_or_expr (GnmParsePos
const *pos
,
238 GnmExprTop
const **texpr
);
240 GString
*gnm_expr_conv_quote (GnmConventions
const *convs
, char const *str
);
244 #endif /* _GNM_PARSE_UTIL_H_ */