1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 #ifndef _GNM_PARSE_UTIL_H_
3 # define _GNM_PARSE_UTIL_H_
6 #include "libgnumeric.h"
10 char const *col_name (int col
);
11 char const *cols_name (int start_col
, int end_col
);
12 char const *col_parse (char const *str
, GnmSheetSize
const *ss
,
13 int *res
, unsigned char *relative
);
15 char const *row_name (int row
);
16 char const *rows_name (int start_row
, int end_row
);
17 char const *row_parse (char const *str
, GnmSheetSize
const *ss
,
18 int *res
, unsigned char *relative
);
20 char const *cellpos_as_string (GnmCellPos
const *pos
);
21 char const *cellpos_parse (char const *cell_str
, GnmSheetSize
const *ss
,
22 GnmCellPos
*res
, gboolean strict
);
23 void cellref_as_string (GnmConventionsOut
*out
,
24 GnmCellRef
const *cell_ref
,
25 gboolean no_sheetname
);
26 char const *cellref_parse (GnmCellRef
*out
, GnmSheetSize
const *ss
,
27 char const *in
, GnmCellPos
const *pos
);
29 void rangeref_as_string (GnmConventionsOut
*out
,
30 GnmRangeRef
const *ref
);
31 char const *rangeref_parse (GnmRangeRef
*res
, char const *start
,
32 GnmParsePos
const *pp
,
33 GnmConventions
const *convs
);
36 char const *cell_coord_name (int col
, int row
);
37 char const *cell_name (GnmCell
const *cell
);
39 char const *parsepos_as_string (GnmParsePos
const *pp
);
41 /* backwards compatibility version */
42 void gnm_1_0_rangeref_as_string (GnmConventionsOut
*out
,
43 GnmRangeRef
const *ref
);
46 struct _GnmConventionsOut
{
48 GnmParsePos
const *pp
;
49 GnmConventions
const *convs
;
54 PERR_MISSING_PAREN_OPEN
,
55 PERR_MISSING_PAREN_CLOSE
,
56 PERR_MISSING_CLOSING_QUOTE
,
57 PERR_INVALID_EXPRESSION
,
58 PERR_INVALID_ARRAY_SEPARATOR
,
59 PERR_UNKNOWN_WORKBOOK
,
62 PERR_UNEXPECTED_TOKEN
,
64 PERR_SHEET_IS_REQUIRED
,
67 PERR_MULTIPLE_EXPRESSIONS
,
70 PERR_SET_CONTENT_MUST_BE_RANGE
74 struct _GnmParseError
{
76 int begin_char
, end_char
;
83 GType
gnm_lexer_item_get_type (void); /* Boxed type */
85 GType
gnm_parse_error_get_type (void); /* Boxed type */
86 GnmParseError
*parse_error_init (GnmParseError
*pe
);
87 void parse_error_free (GnmParseError
*pe
);
90 GNM_EXPR_PARSE_DEFAULT
= 0, /* default is Excel */
91 GNM_EXPR_PARSE_FORCE_ABSOLUTE_REFERENCES
= 1 << 0,
92 GNM_EXPR_PARSE_FORCE_RELATIVE_REFERENCES
= 1 << 0,
93 GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES
= 1 << 2,
94 GNM_EXPR_PARSE_PERMIT_MULTIPLE_EXPRESSIONS
= 1 << 3,
95 GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_STRINGS
= 1 << 4,
96 GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_INVALID
= 1 << 5
99 struct _GnmConventions
{
104 gboolean force_absolute_col_references
;
105 gboolean force_absolute_row_references
;
106 gboolean force_explicit_sheet_references
;
108 gboolean r1c1_addresses
;
110 /* Whether function names should be translated. */
111 gboolean localized_function_names
;
113 /* Separate elements in lists, 0 will use go_locale. */
115 /* Separate array columns, 0 will use go_locale. */
116 gunichar array_col_sep
;
117 /* Separate array rows, 0 will use go_locale. */
118 gunichar array_row_sep
;
120 /* What character denotes range intersection? */
121 gunichar intersection_char
;
122 /* What character denotes range union? */
125 /* What characters are range separators? */
126 gboolean range_sep_colon
; /* A1:B2 */
127 gboolean range_sep_dotdot
; /* A1..B2 */
129 /* Separates sheet name from the cell ref */
130 gunichar sheet_name_sep
;
132 /* Formerly USE_APPLIX_CONVENTIONS. */
133 gboolean ignore_whitespace
;
135 /* Formerly more or less part of USE_APPLIX_CONVENTIONS. */
136 gboolean allow_absolute_sheet_references
;
138 /* Formerly part of USE_OPENCALC_CONVENTIONS. */
139 gboolean decode_ampersands
;
141 /* Is the decimal separator "." (as opposed to locale's)? */
142 gboolean decimal_sep_dot
;
144 /* Accept prefix #NOT# and infixs #AND# and #OR#. */
145 gboolean accept_hash_logicals
;
147 /* If TRUE, parse x^y^z as (x^y)^z. */
148 gboolean exp_is_left_associative
;
150 /* Import specific functions ------------------------------------- */
151 struct _GnmConventionsImport
{
152 /* Called a lot for anything that might be a reference. */
153 char const *(*range_ref
) (GnmRangeRef
*res
, char const *in
,
154 GnmParsePos
const *pp
,
155 GnmConventions
const *convs
);
158 /* Called to unescape strings */
159 char const *(*string
) (char const *in
, GString
*target
,
160 GnmConventions
const *convs
);
162 /* Called a lot for anything that might be a function name or
164 char const *(*name
) (char const *in
,
165 GnmConventions
const *convs
);
166 /* Returns true if a tentative expression name is legal. */
167 gboolean (*name_validate
) (const char *name
);
169 /* Must return non-NULL, and absorb the args, including the list. */
170 GnmExpr
const *(*func
) (GnmConventions
const *convs
,
171 /* make scope more useful, eg a
172 * ParsePos * to allow for
173 * sheet/object specific functions
178 Workbook
*(*external_wb
) (GnmConventions
const *convs
,
180 char const *unquoted_name
);
183 /* Export specific functions ----------------------------------- */
184 struct _GnmConventionsExport
{
189 void (*string
) (GnmConventionsOut
*out
,
190 GOString
const *str
);
191 void (*func
) (GnmConventionsOut
*out
,
192 GnmExprFunction
const *func
);
193 void (*name
) (GnmConventionsOut
*out
,
194 GnmExprName
const *name
);
195 void (*cell_ref
) (GnmConventionsOut
*out
,
196 GnmCellRef
const *cell_ref
,
197 gboolean no_sheetname
);
198 void (*range_ref
) (GnmConventionsOut
*out
,
199 GnmRangeRef
const *range_ref
);
200 void (*boolean
) (GnmConventionsOut
*out
,
203 GString
* (*quote_sheet_name
) (GnmConventions
const *convs
,
207 GType
gnm_conventions_get_type (void);
208 GnmConventions
*gnm_conventions_new (void);
209 GnmConventions
*gnm_conventions_new_full (unsigned size
);
211 GnmConventions
*gnm_conventions_ref (GnmConventions
*c
);
212 void gnm_conventions_unref (GnmConventions
*c
);
215 GNM_VAR_DECL GnmConventions
const *gnm_conventions_default
;
216 GNM_VAR_DECL GnmConventions
const *gnm_conventions_xls_r1c1
;
218 /**********************************************/
220 void parse_util_init (void);
221 void parse_util_shutdown (void);
223 GnmExprTop
const *gnm_expr_parse_str (char const *str
, GnmParsePos
const *pp
,
224 GnmExprParseFlags flags
,
225 GnmConventions
const *convs
,
226 GnmParseError
*error
);
228 GnmLexerItem
*gnm_expr_lex_all (char const *str
, GnmParsePos
const *pp
,
229 GnmExprParseFlags flags
,
230 GnmConventions
const *convs
);
233 /* Is this string potentially the start of an expression */
234 char const *gnm_expr_char_start_p (char const *c
);
236 void parse_text_value_or_expr (GnmParsePos
const *pos
,
239 GnmExprTop
const **texpr
);
241 GString
*gnm_expr_conv_quote (GnmConventions
const *convs
, char const *str
);
245 #endif /* _GNM_PARSE_UTIL_H_ */