This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [RFA] Change to parse error reporting
Michael Snyder wrote:
>
> Michael Snyder wrote:
> >
> > Folks,
> >
> > I've never liked the way in which "parse error" messages in gdb
> > always point to the token _after_ the error, instead of at the
> > token _causing_ the error.
> >
> > This change (implemented for the c/c++ parser only) will make it
> > point at the error token instead of the following token.
> > Extending the change to the other languages will be trivial,
> > if you agree with this.
> >
> > OK to commit?
>
> Does anybody have any opinion about this?
> If not I'll check it in next week.
OK, committed.
> > 2002-04-12 Michael Snyder <msnyder@redhat.com>
> >
> > * parser-defs.h (prev_lexptr): New external variable.
> > * parse.c (parse_exp_1): Set prev_lexptr to null before
> > calling the language-specific parser.
> > * c-exp.y (yylex): Set prev_lexptr to start of current token.
> > (yyerror): Use prev_lexptr in error reporting.
> >
> > Index: parse.c
> > ===================================================================
> > RCS file: /cvs/src/src/gdb/parse.c,v
> > retrieving revision 1.22
> > diff -p -r1.22 parse.c
> > *** parse.c 9 Apr 2002 22:14:39 -0000 1.22
> > --- parse.c 12 Apr 2002 19:40:35 -0000
> > *************** int arglist_len;
> > *** 76,81 ****
> > --- 76,82 ----
> > union type_stack_elt *type_stack;
> > int type_stack_depth, type_stack_size;
> > char *lexptr;
> > + char *prev_lexptr;
> > char *namecopy;
> > int paren_depth;
> > int comma_terminates;
> > *************** parse_exp_1 (char **stringptr, struct bl
> > *** 1126,1131 ****
> > --- 1127,1133 ----
> > struct cleanup *old_chain;
> >
> > lexptr = *stringptr;
> > + prev_lexptr = NULL;
> >
> > paren_depth = 0;
> > type_stack_depth = 0;
> > Index: parser-defs.h
> > ===================================================================
> > RCS file: /cvs/src/src/gdb/parser-defs.h,v
> > retrieving revision 1.7
> > diff -p -r1.7 parser-defs.h
> > *** parser-defs.h 9 Apr 2002 22:14:39 -0000 1.7
> > --- parser-defs.h 12 Apr 2002 19:40:35 -0000
> > *************** extern struct type *follow_types (struct
> > *** 150,155 ****
> > --- 150,159 ----
> >
> > extern char *lexptr;
> >
> > + /* After a token has been recognized, this variable points to it.
> > + Currently used only for error reporting. */
> > + extern char *prev_lexptr;
> > +
> > /* Tokens that refer to names do so with explicit pointer and length,
> > so they can share the storage that lexptr is parsing.
> >
> > Index: c-exp.y
> > ===================================================================
> > RCS file: /cvs/src/src/gdb/c-exp.y,v
> > retrieving revision 1.7
> > diff -p -r1.7 c-exp.y
> > *** c-exp.y 15 Nov 2001 01:55:59 -0000 1.7
> > --- c-exp.y 12 Apr 2002 19:40:35 -0000
> > *************** yylex ()
> > *** 1218,1223 ****
> > --- 1218,1224 ----
> >
> > retry:
> >
> > + prev_lexptr = lexptr;
> > unquoted_expr = 1;
> >
> > tokstart = lexptr;
> > *************** void
> > *** 1738,1742 ****
> > --- 1739,1746 ----
> > yyerror (msg)
> > char *msg;
> > {
> > + if (prev_lexptr)
> > + lexptr = prev_lexptr;
> > +
> > error ("A %s in expression, near `%s'.", (msg ? msg : "error"), lexptr);
> > }