Update Spanish translation
[gnumeric.git] / src / parse-util.h
blob4fec6362c4d1019d2ff2cdb0f34ae40c7b41266f
1 #ifndef _GNM_PARSE_UTIL_H_
2 # define _GNM_PARSE_UTIL_H_
4 #include <gnumeric.h>
5 #include <libgnumeric.h>
7 G_BEGIN_DECLS
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);
33 /* GError **err); */
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 {
46 GString *accum;
47 GnmParsePos const *pp;
48 GnmConventions const *convs;
51 typedef enum {
52 PERR_NONE,
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,
59 PERR_UNKNOWN_SHEET,
60 PERR_UNKNOWN_NAME,
61 PERR_UNEXPECTED_TOKEN,
62 PERR_OUT_OF_RANGE,
63 PERR_SHEET_IS_REQUIRED,
64 PERR_SINGLE_RANGE,
65 PERR_3D_NAME,
66 PERR_MULTIPLE_EXPRESSIONS,
67 PERR_INVALID_EMPTY,
68 PERR_ASYMETRIC_ARRAY,
69 PERR_SET_CONTENT_MUST_BE_RANGE
70 } ParseErrorID;
72 /* In parser.y */
73 struct _GnmParseError {
74 GError *err;
75 int begin_char, end_char;
78 typedef struct {
79 gsize start, end;
80 int token;
81 } GnmLexerItem;
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);
88 typedef enum {
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
96 } GnmExprParseFlags;
98 struct _GnmConventions {
99 int ref_count;
101 #if 0
102 /* Not yet. */
103 gboolean force_absolute_col_references;
104 gboolean force_absolute_row_references;
105 gboolean force_explicit_sheet_references;
106 #endif
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. */
113 gunichar arg_sep;
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? */
122 gunichar union_char;
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);
155 /* GError **err); */
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
162 * defined name. */
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
173 * */
174 Workbook *scope,
175 char const *name,
176 GnmExprList *args);
177 Workbook *(*external_wb) (GnmConventions const *convs,
178 Workbook *ref_wb,
179 char const *unquoted_name);
180 } input;
182 /* Export specific functions ----------------------------------- */
183 struct _GnmConventionsExport {
184 int decimal_digits;
186 gboolean translated;
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,
200 gboolean val);
202 GString * (*quote_sheet_name) (GnmConventions const *convs,
203 char const *name);
204 } output;
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,
236 char const *text,
237 GnmValue **val,
238 GnmExprTop const **texpr);
240 GString *gnm_expr_conv_quote (GnmConventions const *convs, char const *str);
242 G_END_DECLS
244 #endif /* _GNM_PARSE_UTIL_H_ */