Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] Change to parse error reporting
@ 2002-04-12 12:43 Michael Snyder
  2002-04-13  2:05 ` [RFA] lin-lwp.c change to avoid obscure hanging Paul N. Hilfinger
  2002-04-19 11:54 ` [RFA] Change to parse error reporting Michael Snyder
  0 siblings, 2 replies; 7+ messages in thread
From: Michael Snyder @ 2002-04-12 12:43 UTC (permalink / raw)
  To: gdb-patches


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?


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);
  }


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-04-24 22:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-12 12:43 [RFA] Change to parse error reporting Michael Snyder
2002-04-13  2:05 ` [RFA] lin-lwp.c change to avoid obscure hanging Paul N. Hilfinger
2002-04-15 18:10   ` Michael Snyder
2002-04-17  2:52     ` Paul N. Hilfinger
2002-04-19 11:53       ` Michael Snyder
2002-04-19 11:54 ` [RFA] Change to parse error reporting Michael Snyder
2002-04-24 15:23   ` Michael Snyder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox