Commit f5e0dd37 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

Move the state information into a struct so that we can eventually get rid


2001-02-11  Jody Goldberg <jgoldberg@home.com>

	* src/parser.y : Move the state information into a struct so that we
	  can eventually get rid of the statics.
	Take a 'ParseError' as a place to return more detailed information
	  about parsing errors (Not used yet).
parent 9c2b76bc
......@@ -6,6 +6,8 @@ Release Critical
----------------
- Autoformat draw borders!
- Audit the tile iterators to ensure that we only apply to target regions
even for row/col tiles.
Long term breakage
------------------
......
2001-02-11 Jody Goldberg <jgoldberg@home.com>
* src/parser.y : Move the state information into a struct so that we
can eventually get rid of the statics.
Take a 'ParseError' as a place to return more detailed information
about parsing errors (Not used yet).
2001-02-10 Jon K Hellan <hellan@acm.org>
* src/print.c: Illustrate margin definitions.
......@@ -12,6 +19,9 @@
2001-02-10 Jody Goldberg <jgoldberg@home.com>
* src/workbook-control-gui.c (insert_bonobo_object) : help
translators.
* src/sheet-style.c (foreach_tile) : Only apply to applicable row or
col tile segments.
......
2001-02-11 Jody Goldberg <jgoldberg@home.com>
* src/parser.y : Move the state information into a struct so that we
can eventually get rid of the statics.
Take a 'ParseError' as a place to return more detailed information
about parsing errors (Not used yet).
2001-02-10 Jon K Hellan <hellan@acm.org>
* src/print.c: Illustrate margin definitions.
......@@ -12,6 +19,9 @@
2001-02-10 Jody Goldberg <jgoldberg@home.com>
* src/workbook-control-gui.c (insert_bonobo_object) : help
translators.
* src/sheet-style.c (foreach_tile) : Only apply to applicable row or
col tile segments.
......
2001-02-11 Jody Goldberg <jgoldberg@home.com>
* src/parser.y : Move the state information into a struct so that we
can eventually get rid of the statics.
Take a 'ParseError' as a place to return more detailed information
about parsing errors (Not used yet).
2001-02-10 Jon K Hellan <hellan@acm.org>
* src/print.c: Illustrate margin definitions.
......@@ -12,6 +19,9 @@
2001-02-10 Jody Goldberg <jgoldberg@home.com>
* src/workbook-control-gui.c (insert_bonobo_object) : help
translators.
* src/sheet-style.c (foreach_tile) : Only apply to applicable row or
col tile segments.
......
2001-02-11 Jody Goldberg <jgoldberg@home.com>
* src/parser.y : Move the state information into a struct so that we
can eventually get rid of the statics.
Take a 'ParseError' as a place to return more detailed information
about parsing errors (Not used yet).
2001-02-10 Jon K Hellan <hellan@acm.org>
* src/print.c: Illustrate margin definitions.
......@@ -12,6 +19,9 @@
2001-02-10 Jody Goldberg <jgoldberg@home.com>
* src/workbook-control-gui.c (insert_bonobo_object) : help
translators.
* src/sheet-style.c (foreach_tile) : Only apply to applicable row or
col tile segments.
......
2001-02-11 Jody Goldberg <jgoldberg@home.com>
* src/parser.y : Move the state information into a struct so that we
can eventually get rid of the statics.
Take a 'ParseError' as a place to return more detailed information
about parsing errors (Not used yet).
2001-02-10 Jon K Hellan <hellan@acm.org>
* src/print.c: Illustrate margin definitions.
......@@ -12,6 +19,9 @@
2001-02-10 Jody Goldberg <jgoldberg@home.com>
* src/workbook-control-gui.c (insert_bonobo_object) : help
translators.
* src/sheet-style.c (foreach_tile) : Only apply to applicable row or
col tile segments.
......
2001-02-09 Jody Goldberg <jgoldberg@home.com>
* applix-read.c (applix_read_cells) : Adjust to new signature for
parser.
2001-01-11 Jody Goldberg <jgoldberg@home.com>
* applix-read.c (applix_parse_style) : remove the border shifting
......
......@@ -968,7 +968,8 @@ applix_read_cells (ApplixReadState *state)
#endif
if (content_type == ';') {
gboolean is_array = FALSE;
gboolean is_array = FALSE;
ParseError perr;
if (*expr_string == '~') {
Sheet *start_sheet, *end_sheet;
......@@ -1000,10 +1001,13 @@ applix_read_cells (ApplixReadState *state)
continue;
}
if (PARSE_OK != gnumeric_expr_parser (expr_string+1,
parse_pos_init_cell (&pos, cell),
FALSE, TRUE, NULL, &expr)) {
expr = gnumeric_expr_parser (expr_string+1,
parse_pos_init_cell (&pos, cell),
FALSE, TRUE, NULL,
parse_error_init (&perr));
if (expr == NULL) {
(void) applix_parse_error (state, "Invalid expression");
parse_error_free (&perr);
continue;
}
......
......@@ -268,7 +268,7 @@
<menuitem name="InsertComment" verb=""
pixtype="stock" pixname="Gnumeric_CommentAdd"
_label="_Add / modify comment..."
_label="_Add / Modify comment..."
_tip="Edit the selected cell's comment"/>
<submenu name="Special" _label="S_pecial">
......@@ -574,7 +574,7 @@
<toolitem type="toggle" name="FontItalic"
pixtype="stock" pixname="Italic"
_label="Italicize"
_tip="Makes font italic"
_tip="Make font italic"
_accel="*Control*i"
verb="FontItalic"/>
......
......@@ -184,30 +184,23 @@ expr_tree_get_const_str (ExprTree const *expr)
}
ExprTree *
expr_parse_string (char const *expr, ParsePos const *pp,
expr_parse_string (char const *expr_text, ParsePos const *pp,
StyleFormat **desired_format, char **error_msg)
{
ExprTree *tree;
g_return_val_if_fail (expr != NULL, NULL);
ExprTree *tree;
ParseError perr;
switch (gnumeric_expr_parser (expr, pp, TRUE, FALSE, desired_format, &tree)) {
case PARSE_OK:
*error_msg = NULL;
return tree;
g_return_val_if_fail (expr_text != NULL, NULL);
case PARSE_ERR_SYNTAX:
tree = gnumeric_expr_parser (expr_text, pp, TRUE, FALSE, desired_format,
parse_error_init (&perr));
/* TODO : use perr when we populate it */
if (tree == NULL)
*error_msg = _("Syntax error");
break;
case PARSE_ERR_NO_QUOTE:
*error_msg = _("Missing quote");
break;
default:
g_assert_not_reached ();
*error_msg = _("Impossible!");
break;
}
return NULL;
else
*error_msg = NULL;
parse_error_free (&perr);
return tree;
}
......
......@@ -268,7 +268,7 @@
<menuitem name="InsertComment" verb=""
pixtype="stock" pixname="Gnumeric_CommentAdd"
_label="_Add / modify comment..."
_label="_Add / Modify comment..."
_tip="Edit the selected cell's comment"/>
<submenu name="Special" _label="S_pecial">
......@@ -574,7 +574,7 @@
<toolitem type="toggle" name="FontItalic"
pixtype="stock" pixname="Italic"
_label="Italicize"
_tip="Makes font italic"
_tip="Make font italic"
_accel="*Control*i"
verb="FontItalic"/>
......
......@@ -548,3 +548,20 @@ parse_text_value_or_expr (EvalPos const *pos, char const *text,
return desired_format;
}
ParseError *
parse_error_init (ParseError *pe)
{
pe->message = NULL;
return pe;
}
void
parse_error_free (ParseError *pe)
{
if (pe->message != NULL) {
g_free (pe->message)
pe->message = NULL;
}
}
......@@ -40,17 +40,17 @@ StyleFormat *parse_text_value_or_expr (EvalPos const *pos,
char const * gnumeric_char_start_expr_p (char const * c);
/* In parser.y */
typedef enum {
PARSE_OK,
PARSE_ERR_NO_QUOTE,
PARSE_ERR_SYNTAX,
PARSE_ERR_UNKNOWN
} ParseErr;
ParseErr gnumeric_expr_parser (const char *expr,
const ParsePos *pp,
gboolean use_excel_range_conventions,
gboolean create_place_holder_for_unknown_func,
StyleFormat **desired_format,
ExprTree **result);
typedef struct {
char *message;
int start_char, end_char;
} ParseError;
ParseError *parse_error_init (ParseError *pe);
void parse_error_free (ParseError *pe);
ExprTree *gnumeric_expr_parser (char const *expr_text, ParsePos const *pos,
gboolean use_excel_range_conventions,
gboolean create_place_holder_for_unknown_func,
StyleFormat **desired_format,
ParseError *pe);
#endif /* GNUMERIC_PARSE_UTIL_H */
......@@ -189,26 +189,29 @@ unregister_allocation (const void *data)
static int yylex (void);
static int yyerror (char *s);
/* The expression being parsed */
static const char *parser_expr;
typedef struct {
/* The expression being parsed */
char const *expr_text;
/* The error returned from the */
static ParseErr parser_error;
/* Location where the parsing is taking place */
ParsePos const *pos;
/* Location where the parsing is taking place */
static const ParsePos *parser_pos;
/* Locale info. */
char decimal_point;
char separator;
char array_col_separator;
/* The suggested format to use for this expression */
static StyleFormat **parser_desired_format;
/* flags */
gboolean use_excel_reference_conventions;
gboolean create_place_holder_for_unknown_func;
/* Locale info. */
static char parser_decimal_point;
static char parser_separator;
static char parser_array_col_separator;
static gboolean parser_use_excel_reference_conventions;
static gboolean parser_create_place_holder_for_unknown_func;
/* The suggested format to use for this expression */
StyleFormat **desired_format;
ExprTree *result;
} ParserState;
static ExprTree **parser_result;
/* The error returned from the */
static ParserState *state;
static ExprTree *
build_unary_op (Operation op, ExprTree *expr)
......@@ -233,7 +236,7 @@ build_array (GList *cols)
int x, mx, y;
if (!cols) {
parser_error = PARSE_ERR_SYNTAX;
/* parser_error = PARSE_ERR_SYNTAX; */
return NULL;
}
......@@ -262,7 +265,7 @@ build_array (GList *cols)
row = row->next;
}
if (x < mx || row) {
parser_error = PARSE_ERR_SYNTAX;
/* parser_error = PARSE_ERR_SYNTAX; */
value_release (array);
return NULL;
}
......@@ -304,7 +307,7 @@ parse_string_as_value_or_name (ExprTree *str)
{
NamedExpression *expr_name;
expr_name = expr_name_lookup (parser_pos, str->constant.value->v_str.val->str);
expr_name = expr_name_lookup (state->pos, str->constant.value->v_str.val->str);
if (expr_name != NULL) {
unregister_allocation (str); expr_tree_unref (str);
return register_expr_allocation (expr_tree_new_name (expr_name));
......@@ -319,7 +322,7 @@ static int
gnumeric_parse_error (void)
{
/* TODO : Get rid of ParseErr and replace it with something richer. */
parser_error = PARSE_ERR_SYNTAX;
/* parser_error = PARSE_ERR_SYNTAX; */
return ERROR;
}
......@@ -353,14 +356,13 @@ int yyparse (void);
%%
line: exp {
unregister_allocation ($1);
*parser_result = $1;
state->result = $1;
}
| error {
parser_error = PARSE_ERR_SYNTAX;
if (*parser_result) {
expr_tree_unref (*parser_result);
*parser_result = NULL;
if (state->result != NULL) {
expr_tree_unref (state->result);
state->result = NULL;
}
}
;
......@@ -396,10 +398,10 @@ exp: CONSTANT { $$ = $1; }
| STRING '(' arg_list ')' {
const char *name = $1->constant.value->v_str.val->str;
FunctionDefinition *f = func_lookup_by_name (name,
parser_pos->wb);
state->pos->wb);
/* THINK TODO: Do we want to make this workbook-local?? */
if (f == NULL && parser_create_place_holder_for_unknown_func)
if (f == NULL && state->create_place_holder_for_unknown_func)
f = function_add_placeholder (name, "");
unregister_allocation ($3);
......@@ -415,7 +417,7 @@ exp: CONSTANT { $$ = $1; }
| sheetref string_opt_quote {
NamedExpression *expr_name;
char *name = $2->constant.value->v_str.val->str;
ParsePos pos = *parser_pos;
ParsePos pos = *state->pos;
pos.sheet = $1;
expr_name = expr_name_lookup (&pos, name);
......@@ -431,7 +433,7 @@ string_opt_quote : STRING
;
sheetref: string_opt_quote SHEET_SEP {
Sheet *sheet = sheet_lookup_by_name (parser_pos->wb, $1->constant.value->v_str.val->str);
Sheet *sheet = sheet_lookup_by_name (state->pos->wb, $1->constant.value->v_str.val->str);
unregister_allocation ($1); expr_tree_unref ($1);
if (sheet == NULL)
return gnumeric_parse_error ();
......@@ -481,7 +483,7 @@ cellref: CELLREF {
$$ = register_expr_allocation
(expr_tree_new_constant
(value_new_cellrange (&($1->var.ref), &($3->var.ref),
parser_pos->eval.col, parser_pos->eval.row)));
state->pos->eval.col, state->pos->eval.row)));
expr_tree_unref ($3);
expr_tree_unref ($1);
}
......@@ -494,7 +496,7 @@ cellref: CELLREF {
$$ = register_expr_allocation
(expr_tree_new_constant
(value_new_cellrange (&($2->var.ref), &($5->var.ref),
parser_pos->eval.col, parser_pos->eval.row)));
state->pos->eval.col, state->pos->eval.row)));
expr_tree_unref ($5);
expr_tree_unref ($2);
......@@ -535,7 +537,7 @@ array_row: array_exp {
register_expr_list_allocation ($$);
}
| array_exp SEPARATOR array_row {
if (parser_array_col_separator == ',') {
if (state->array_col_separator == ',') {
unregister_allocation ($3);
unregister_allocation ($1);
$$ = g_list_prepend ($3, $1);
......@@ -544,7 +546,7 @@ array_row: array_exp {
return gnumeric_parse_error ();
}
| array_exp '\\' array_row {
if (parser_array_col_separator == '\\') {
if (state->array_col_separator == '\\') {
unregister_allocation ($3);
unregister_allocation ($1);
$$ = g_list_prepend ($3, $1);
......@@ -587,7 +589,7 @@ parse_ref_or_string (const char *string)
CellRef ref;
Value *v = NULL;
if (cellref_get (&ref, string, &parser_pos->eval)) {
if (cellref_get (&ref, string, &state->pos->eval)) {
yylval.tree = register_expr_allocation (expr_tree_new_var (&ref));
return CELLREF;
}
......@@ -604,39 +606,39 @@ yylex (void)
const char *start;
gboolean is_number = FALSE;
while (isspace ((unsigned char)*parser_expr))
parser_expr++;
while (isspace ((unsigned char)*state->expr_text))
state->expr_text++;
start = parser_expr;
c = (unsigned char) (*parser_expr++);
start = state->expr_text;
c = (unsigned char) (*state->expr_text++);
if (c == '(' || c == ')')
return c;
if (parser_use_excel_reference_conventions) {
if (state->use_excel_reference_conventions) {
if (c == ':')
return RANGE_SEP;
if (c == '!')
return SHEET_SEP;
} else {
/* Treat '..' as range sep (A1..C3) */
if (c == '.' && *parser_expr == '.') {
parser_expr++;
if (c == '.' && *state->expr_text == '.') {
state->expr_text++;
return RANGE_SEP;
}
if (c == ':')
return SHEET_SEP;
}
if (c == parser_separator)
if (c == state->separator)
return SEPARATOR;
if (c == parser_decimal_point) {
if (c == state->decimal_point) {
/* Could be a number or a stand alone */
if (!isdigit ((unsigned char)(*parser_expr)))
if (!isdigit ((unsigned char)(*state->expr_text)))
return c;
is_number = TRUE;
} else if (isdigit (c)) {
while (isdigit ((c = (unsigned char)(*parser_expr++))))
while (isdigit ((c = (unsigned char)(*state->expr_text++))))
;
is_number = TRUE;
}
......@@ -644,7 +646,7 @@ yylex (void)
if (is_number) {
Value *v = NULL;
if (c == parser_decimal_point || tolower (c) == 'e') {
if (c == state->decimal_point || tolower (c) == 'e') {
/* This is float */
char *end;
double d;
......@@ -654,7 +656,7 @@ yylex (void)
if (start != end) {
if (errno != ERANGE) {
v = value_new_float ((gnum_float)d);
parser_expr = end;
state->expr_text = end;
}
}
} else {
......@@ -673,7 +675,7 @@ yylex (void)
*/
}
v = value_new_int (l);
parser_expr = end;
state->expr_text = end;
}
}
}
......@@ -694,17 +696,17 @@ yylex (void)
char quotes_end = c;
Value *v;
p = parser_expr;
while(*parser_expr && *parser_expr != quotes_end) {
if (*parser_expr == '\\' && parser_expr [1])
parser_expr++;
parser_expr++;
p = state->expr_text;
while(*state->expr_text && *state->expr_text != quotes_end) {
if (*state->expr_text == '\\' && state->expr_text [1])
state->expr_text++;
state->expr_text++;
}
if (!*parser_expr)
if (!*state->expr_text)
return gnumeric_parse_error ();
s = string = (char *) alloca (1 + parser_expr - p);
while (p != parser_expr){
s = string = (char *) alloca (1 + state->expr_text - p);
while (p != state->expr_text){
if (*p== '\\'){
p++;
*s++ = *p++;
......@@ -712,7 +714,7 @@ yylex (void)
*s++ = *p++;
}
*s = 0;
parser_expr++;
state->expr_text++;
v = value_new_string (string);
yylval.tree = register_expr_allocation (expr_tree_new_constant (v));
......@@ -721,16 +723,16 @@ yylex (void)
}
if (isalpha ((unsigned char)c) || c == '_' || c == '$'){
const char *start = parser_expr - 1;
const char *start = state->expr_text - 1;
char *str;
int len;
while (isalnum ((unsigned char)*parser_expr) || *parser_expr == '_' ||
*parser_expr == '$' ||
(parser_use_excel_reference_conventions && *parser_expr == '.'))
parser_expr++;
while (isalnum ((unsigned char)*state->expr_text) || *state->expr_text == '_' ||
*state->expr_text == '$' ||
(state->use_excel_reference_conventions && *state->expr_text == '.'))
state->expr_text++;
len = parser_expr - start;
len = state->expr_text - start;
str = alloca (len + 1);
strncpy (str, start, len);
str [len] = 0;
......@@ -741,20 +743,20 @@ yylex (void)
return 0;
if (c == '<'){
if (*parser_expr == '='){
parser_expr++;
if (*state->expr_text == '='){
state->expr_text++;
return LTE;
}
if (*parser_expr == '>'){
parser_expr++;
if (*state->expr_text == '>'){
state->expr_text++;
return NE;
}
return c;
}
if (c == '>'){
if (*parser_expr == '='){
parser_expr++;
if (*state->expr_text == '='){
state->expr_text++;
return GTE;
}
return c;
......@@ -772,47 +774,50 @@ yyerror (char *s)
return 0;
}
ParseErr
gnumeric_expr_parser (const char *expr, const ParsePos *pp,
ExprTree *
gnumeric_expr_parser (char const *expr_text, ParsePos const *pos,
gboolean use_excel_range_conventions,
gboolean create_place_holder_for_unknown_func,
StyleFormat **desired_format, ExprTree **result)
StyleFormat **desired_format,
ParseError *error)
{
g_return_val_if_fail (pp, PARSE_ERR_UNKNOWN);
g_return_val_if_fail (expr, PARSE_ERR_UNKNOWN);
g_return_val_if_fail (result, PARSE_ERR_UNKNOWN);
ParserState pstate;
parser_error = PARSE_OK;
parser_expr = expr;
parser_pos = pp;
parser_desired_format = desired_format;
parser_result = result;
*parser_result = NULL;
pstate.expr_text = expr_text;
pstate.pos = pos;
if (parser_desired_format)
*parser_desired_format = NULL;
pstate.decimal_point = format_get_decimal ();
pstate.separator = format_get_arg_sep ();
pstate.array_col_separator = format_get_col_sep ();
parser_use_excel_reference_conventions = use_excel_range_conventions;
parser_create_place_holder_for_unknown_func = create_place_holder_for_unknown_func;
pstate.use_excel_reference_conventions = use_excel_range_conventions;
pstate.create_place_holder_for_unknown_func = create_place_holder_for_unknown_func;
parser_decimal_point = format_get_decimal ();
parser_separator = format_get_arg_sep ();
parser_array_col_separator = format_get_col_sep ();
pstate.result = NULL;
pstate.desired_format = desired_format;
if (pstate.desired_format)
*pstate.desired_format = NULL;
if (deallocate_stack == NULL)
deallocate_init ();
g_return_val_if_fail (pstate.pos != NULL, NULL);
g_return_val_if_fail (pstate.expr_text != NULL, NULL);
g_return_val_if_fail (state == NULL, NULL);
state = &pstate;
yyparse ();
state = NULL;
if (parser_error == PARSE_OK) {
if (pstate.result != NULL) {
deallocate_assert_empty ();
if (desired_format) {
StyleFormat *format;
EvalPos pos;
EvalPos tmp;
pos.sheet = pp->sheet;
pos.eval = pp->eval;
format = auto_style_format_suggest (*parser_result, &pos);
tmp.sheet = pos->sheet;
tmp.eval = pos->eval;
format = auto_style_format_suggest (pstate.result, &tmp);
if (format) {
/*
* Override the format that came from a
......@@ -825,7 +830,7 @@ gnumeric_expr_parser (const char *expr, const ParsePos *pp,
}
} else {
#if 0
fprintf (stderr, "Unable to parse '%s'\n", expr);
fprintf (stderr, "Unable to parse '%s'\n", expr_text);
#endif
deallocate_all ();
if (desired_format && *desired_format) {
......@@ -838,5 +843,5 @@ gnumeric_expr_parser (const char *expr, const ParsePos *pp,
deallocate_uninit ();
#endif
return parser_error;
return pstate.result;
}
......@@ -1451,8 +1451,8 @@ insert_bonobo_object (WorkbookControlGUI *wbcg, char const **interfaces)
scg_mode_create_object (scg, so);
return;
}
msg = g_strconcat (_("Unable to create object of type \'"),
obj_id, "\'", NULL);
msg = g_strdup_printf (_("Unable to create object of type \'%s\'"),
obj_id);
gnumeric_notice (wbcg, GNOME_MESSAGE_BOX_ERROR, msg);
g_free (msg);
}
......@@ -1981,7 +1981,7 @@ static GnomeUIInfo workbook_menu_insert [] = {
GNOMEUIINFO_SUBTREE(N_("_Name"), workbook_menu_names),
GNOMEUIINFO_ITEM_STOCK (N_("_Add\\modify comment..."),
GNOMEUIINFO_ITEM_STOCK (N_("_Add / Modify comment..."),
N_("Edit the selected cell's comment"),
cb_insert_comment, "Menu_Gnumeric_CommentEdit"),
......
......@@ -311,7 +311,7 @@ wb_view_auto_expr (WorkbookView *wbv, char const *descr, char const *expression)
char *old_num_locale, *old_monetary_locale, *old_msg_locale;
ExprTree *new_auto_expr;
ParsePos pp;
ParseErr res;
ParseError perr;
old_num_locale = g_strdup (gnumeric_setlocale (LC_NUMERIC, NULL));
gnumeric_setlocale (LC_NUMERIC, "C");
......@@ -322,10 +322,10 @@ wb_view_auto_expr (WorkbookView *wbv, char const *descr, char const *expression)
textdomain ("C");