[#7708] Bug in libsnmp-ruby1.8 — Hadmut Danisch <hadmut@...>

Hi,

8 messages 2006/04/11
[#7709] Re: Bug in libsnmp-ruby1.8 — Eric Hodel <drbrain@...7.net> 2006/04/11

On Apr 11, 2006, at 6:23 AM, Hadmut Danisch wrote:

[#7770] Re: possible defect in array.c — "Brown, Warren" <warrenbrown@...>

> rb_range_beg_len (in range.c) does set beg and len.

13 messages 2006/04/26
[#7771] Re: possible defect in array.c — "Pat Eyler" <rubypate@...> 2006/04/26

On 4/26/06, Brown, Warren <warrenbrown@aquire.com> wrote:

Re: [PATCH] parse.y: literal strings for tokens

From: Robin Stocker <robin@...>
Date: 2006-04-08 16:51:38 UTC
List: ruby-core #7688
Hi again,

Attached is my second patch which works like this:

parse.y: use one line and %token declaration per token
Makefile.in: strip literal token strings if we don't have bison yacc

The patch is against the ruby_1_8 branch, tested with bison, yacc and 
byacc. If the patch is ok, I can create one for HEAD too.

$ ./ruby -e 'p() p'
# with patch:
-e:1: syntax error, unexpected identifier, expecting end of file
# without patch:
-e:1: syntax error, unexpected tIDENTIFIER, expecting $end

Regards,
   Robin Stocker

Attachments (1)

pretty-syntax-errors.patch (5.31 KB, text/x-diff)
Index: Makefile.in
===================================================================
RCS file: /src/ruby/Makefile.in,v
retrieving revision 1.55.2.12
diff -u -r1.55.2.12 Makefile.in
--- Makefile.in	10 Nov 2005 23:22:03 -0000	1.55.2.12
+++ Makefile.in	8 Apr 2006 16:26:13 -0000
@@ -154,9 +154,15 @@
 	cp "$(srcdir)/$@" .
 
 .y.c:
-	$(YACC) $<
+ifeq ($(firstword $(YACC)), bison)
+	cp $< $<.tmp
+else
+# If we don't have a bison yacc, strip the literal strings
+	sed '/^%token/ s|"[^"]*"||' $< > $<.tmp	
+endif
+	$(YACC) $<.tmp
 	sed '/^#/s|y\.tab\.c|$@|' y.tab.c > $@
-	rm -f y.tab.c
+	rm -f $<.tmp y.tab.c
 
 .c.@OBJEXT@:
 	$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
Index: parse.y
===================================================================
RCS file: /src/ruby/parse.y,v
retrieving revision 1.307.2.31
diff -u -r1.307.2.31 parse.y
--- parse.y	21 Feb 2006 05:19:34 -0000	1.307.2.31
+++ parse.y	8 Apr 2006 16:26:17 -0000
@@ -213,58 +213,68 @@
     struct RVarmap *vars;
 }
 
-%token  kCLASS
-	kMODULE
-	kDEF
-	kUNDEF
-	kBEGIN
-	kRESCUE
-	kENSURE
-	kEND
-	kIF
-	kUNLESS
-	kTHEN
-	kELSIF
-	kELSE
-	kCASE
-	kWHEN
-	kWHILE
-	kUNTIL
-	kFOR
-	kBREAK
-	kNEXT
-	kREDO
-	kRETRY
-	kIN
-	kDO
-	kDO_COND
-	kDO_BLOCK
-	kRETURN
-	kYIELD
-	kSUPER
-	kSELF
-	kNIL
-	kTRUE
-	kFALSE
-	kAND
-	kOR
-	kNOT
-	kIF_MOD
-	kUNLESS_MOD
-	kWHILE_MOD
-	kUNTIL_MOD
-	kRESCUE_MOD
-	kALIAS
-	kDEFINED
-	klBEGIN
-	klEND
-	k__LINE__
-	k__FILE__
-
-%token <id>   tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR
-%token <node> tINTEGER tFLOAT tSTRING_CONTENT
-%token <node> tNTH_REF tBACK_REF
-%token <num>  tREGEXP_END
+%token TOKEN_EOF 0	"end of file"
+
+%token kCLASS		"class"
+%token kMODULE		"module"
+%token kDEF		"def"
+%token kUNDEF		"undef"
+%token kBEGIN		"begin"
+%token kRESCUE		"rescue"
+%token kENSURE		"ensure"
+%token kEND		"end"
+%token kIF		"if"
+%token kUNLESS		"unless"
+%token kTHEN		"then"
+%token kELSIF		"elsif"
+%token kELSE		"else"
+%token kCASE		"case"
+%token kWHEN		"when"
+%token kWHILE		"while"
+%token kUNTIL		"until"
+%token kFOR		"for"
+%token kBREAK		"break"
+%token kNEXT		"next"
+%token kREDO		"redo"
+%token kRETRY		"retry"
+%token kIN		"in"
+%token kDO		"do"
+%token kDO_COND		"do condition"
+%token kDO_BLOCK	"do block"
+%token kRETURN		"return"
+%token kYIELD		"yield"
+%token kSUPER		"super"
+%token kSELF		"self"
+%token kNIL		"nil"
+%token kTRUE		"true"
+%token kFALSE		"false"
+%token kAND		"and"
+%token kOR		"or"
+%token kNOT		"not"
+%token kIF_MOD		"if modifier"
+%token kUNLESS_MOD	"unless modifier"
+%token kWHILE_MOD	"while modifier"
+%token kUNTIL_MOD	"until modifier"
+%token kRESCUE_MOD	"rescue modifier"
+%token kALIAS		"alias"
+%token kDEFINED		"defined"
+%token klBEGIN		"BEGIN"
+%token klEND		"END"
+%token k__LINE__	"__LINE__"
+%token k__FILE__	"__FILE__"
+
+%token <id> tIDENTIFIER	"identifier"
+%token <id> tFID
+%token <id> tGVAR	"global variable"
+%token <id> tIVAR	"instance variable"
+%token <id> tCONSTANT	"constant"
+%token <id> tCVAR	"class variable"
+%token <node> tINTEGER	"integer"
+%token <node> tFLOAT	"float"
+%token <node> tSTRING_CONTENT	"string content"
+%token <node> tNTH_REF
+%token <node> tBACK_REF
+%token <num>  tREGEXP_END	"regexp end"
 
 %type <node> singleton strings string string1 xstring regexp
 %type <node> string_contents xstring_contents string_content
@@ -283,34 +293,47 @@
 %type <id>   fsym variable sym symbol operation operation2 operation3
 %type <id>   cname fname op
 %type <num>  f_norm_arg f_arg
-%token tUPLUS 		/* unary+ */
-%token tUMINUS 		/* unary- */
-%token tPOW		/* ** */
-%token tCMP  		/* <=> */
-%token tEQ  		/* == */
-%token tEQQ  		/* === */
-%token tNEQ  		/* != */
-%token tGEQ  		/* >= */
-%token tLEQ  		/* <= */
-%token tANDOP tOROP	/* && and || */
-%token tMATCH tNMATCH	/* =~ and !~ */
-%token tDOT2 tDOT3	/* .. and ... */
-%token tAREF tASET	/* [] and []= */
-%token tLSHFT tRSHFT	/* << and >> */
-%token tCOLON2		/* :: */
-%token tCOLON3		/* :: at EXPR_BEG */
-%token <id> tOP_ASGN	/* +=, -=  etc. */
-%token tASSOC		/* => */
-%token tLPAREN		/* ( */
-%token tLPAREN_ARG	/* ( */
-%token tRPAREN		/* ) */
-%token tLBRACK		/* [ */
-%token tLBRACE		/* { */
-%token tLBRACE_ARG	/* { */
-%token tSTAR		/* * */
-%token tAMPER		/* & */
-%token tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tWORDS_BEG tQWORDS_BEG
-%token tSTRING_DBEG tSTRING_DVAR tSTRING_END
+
+%token tUPLUS 		"unary +"
+%token tUMINUS 		"unary -"
+%token tPOW		"**"
+%token tCMP  		"<=>"
+%token tEQ  		"=="
+%token tEQQ  		"==="
+%token tNEQ  		"!="
+%token tGEQ  		">="
+%token tLEQ  		"<="
+%token tANDOP		"&&"
+%token tOROP		"||"
+%token tMATCH		"=~"
+%token tNMATCH		"!~"
+%token tDOT2		".."
+%token tDOT3		"..."
+%token tAREF		"[]"
+%token tASET		"[]="
+%token tLSHFT		"<<"
+%token tRSHFT		">>"
+%token tCOLON2		"::"
+%token tCOLON3		"::" /* at EXPR_BEG */
+%token <id> tOP_ASGN	"assignment operator" /* +=, -=  etc. */
+%token tASSOC		"=>"
+%token tLPAREN		"("
+%token tLPAREN_ARG	"("
+%token tRPAREN		")"
+%token tLBRACK		"["
+%token tLBRACE		"{"
+%token tLBRACE_ARG	"{"
+%token tSTAR		"*"
+%token tAMPER		"&"
+%token tSYMBEG		"beginning of symbol"
+%token tSTRING_BEG	"beginning of string"
+%token tXSTRING_BEG	"beginning of execution string"
+%token tREGEXP_BEG	"beginning of regexp"
+%token tWORDS_BEG	"%w"
+%token tQWORDS_BEG	"%W"
+%token tSTRING_DBEG	"string interpolation"
+%token tSTRING_DVAR	"string interpolation"
+%token tSTRING_END	"end of string"
 
 /*
  *	precedence table

In This Thread