ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:25442] turning off indentation warnings
@ 2009-09-06 22:53 Aaron Patterson
  2009-09-10 13:39 ` [ruby-core:25510] " Nobuyoshi Nakada
  0 siblings, 1 reply; 19+ messages in thread
From: Aaron Patterson @ 2009-09-06 22:53 UTC (permalink / raw
  To: ruby-core

Is there a way in 1.9 to turn off only indentation warnings?  I like  
to keep warnings turned on, but indentation warnings don't make sense  
when the output is generated, like with racc.

---
Aaron Patterson
http://tenderlovemaking.com

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

* [ruby-core:25510] Re: turning off indentation warnings
  2009-09-06 22:53 [ruby-core:25442] turning off indentation warnings Aaron Patterson
@ 2009-09-10 13:39 ` Nobuyoshi Nakada
  2009-09-10 14:30   ` [ruby-core:25514] " Yukihiro Matsumoto
                     ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Nobuyoshi Nakada @ 2009-09-10 13:39 UTC (permalink / raw
  To: ruby-core

Hi,

At Mon, 7 Sep 2009 07:53:27 +0900,
Aaron Patterson wrote in [ruby-core:25442]:
> Is there a way in 1.9 to turn off only indentation warnings?  I like  
> to keep warnings turned on, but indentation warnings don't make sense  
> when the output is generated, like with racc.

Currently, nothing.  How about magic comments?

\f
Index: parse.y
===================================================================
--- parse.y	(revision 24824)
+++ parse.y	(working copy)
@@ -244,4 +244,5 @@ struct parser_params {
 
     token_info *parser_token_info;
+    int parser_token_info_enabled;
 #else
     /* Ripper only */
@@ -587,4 +588,7 @@ static void ripper_compile_error(struct 
 static void token_info_push(struct parser_params*, const char *token);
 static void token_info_pop(struct parser_params*, const char *token);
+#else
+#define token_info_push(parser, token) /* nothing */
+#define token_info_pop(parser, token) /* nothing */
 #endif
 %}
@@ -2970,7 +2974,5 @@ primary_value	: primary
 k_begin		: keyword_begin
 		    {
-#ifndef RIPPER
-			if (RTEST(ruby_verbose)) token_info_push(parser, "begin");
-#endif
+			token_info_push(parser, "begin");
 		    }
 		;
@@ -2978,7 +2980,5 @@ k_begin		: keyword_begin
 k_if		: keyword_if
 		    {
-#ifndef RIPPER
-			if (RTEST(ruby_verbose)) token_info_push(parser, "if");
-#endif
+			token_info_push(parser, "if");
 		    }
 		;
@@ -2986,7 +2986,5 @@ k_if		: keyword_if
 k_unless	: keyword_unless
 		    {
-#ifndef RIPPER
-			if (RTEST(ruby_verbose)) token_info_push(parser, "unless");
-#endif
+			token_info_push(parser, "unless");
 		    }
 		;
@@ -2994,7 +2992,5 @@ k_unless	: keyword_unless
 k_while		: keyword_while
 		    {
-#ifndef RIPPER
-			if (RTEST(ruby_verbose)) token_info_push(parser, "while");
-#endif
+			token_info_push(parser, "while");
 		    }
 		;
@@ -3002,7 +2998,5 @@ k_while		: keyword_while
 k_until		: keyword_until
 		    {
-#ifndef RIPPER
-			if (RTEST(ruby_verbose)) token_info_push(parser, "until");
-#endif
+			token_info_push(parser, "until");
 		    }
 		;
@@ -3010,7 +3004,5 @@ k_until		: keyword_until
 k_case		: keyword_case
 		    {
-#ifndef RIPPER
-			if (RTEST(ruby_verbose)) token_info_push(parser, "case");
-#endif
+			token_info_push(parser, "case");
 		    }
 		;
@@ -3018,7 +3010,5 @@ k_case		: keyword_case
 k_for		: keyword_for
 		    {
-#ifndef RIPPER
-			if (RTEST(ruby_verbose)) token_info_push(parser, "for");
-#endif
+			token_info_push(parser, "for");
 		    }
 		;
@@ -3026,7 +3016,5 @@ k_for		: keyword_for
 k_class		: keyword_class
 		    {
-#ifndef RIPPER
-			if (RTEST(ruby_verbose)) token_info_push(parser, "class");
-#endif
+			token_info_push(parser, "class");
 		    }
 		;
@@ -3034,7 +3022,5 @@ k_class		: keyword_class
 k_module	: keyword_module
 		    {
-#ifndef RIPPER
-			if (RTEST(ruby_verbose)) token_info_push(parser, "module");
-#endif
+			token_info_push(parser, "module");
 		    }
 		;
@@ -3042,7 +3028,5 @@ k_module	: keyword_module
 k_def		: keyword_def
 		    {
-#ifndef RIPPER
-			if (RTEST(ruby_verbose)) token_info_push(parser, "def");
-#endif
+			token_info_push(parser, "def");
 		    }
 		;
@@ -3050,7 +3034,5 @@ k_def		: keyword_def
 k_end		: keyword_end
 		    {
-#ifndef RIPPER
-			if (RTEST(ruby_verbose)) token_info_pop(parser, "end");  /* POP */
-#endif
+			token_info_pop(parser, "end");  /* POP */
 		    }
 		;
@@ -4826,5 +4808,5 @@ token_info_push(struct parser_params *pa
     token_info *ptinfo;
 
-    if (compile_for_eval) return;
+    if (!parser->parser_token_info_enabled) return;
     ptinfo = ALLOC(token_info);
     ptinfo->token = token;
@@ -4855,7 +4837,9 @@ token_info_pop(struct parser_params *par
 	goto finish;
     }
-    rb_compile_warning(ruby_sourcefile, linenum,
-               "mismatched indentations at '%s' with '%s' at %d",
-	       token, ptinfo->token, ptinfo->linenum);
+    if (parser->parser_token_info_enabled) {
+	rb_compile_warn(ruby_sourcefile, linenum,
+			"mismatched indentations at '%s' with '%s' at %d",
+			token, ptinfo->token, ptinfo->linenum);
+    }
 
   finish:
@@ -4998,4 +4982,7 @@ yycompile0(VALUE arg, int tracing)
     parser_prepare(parser);
     deferred_nodes = 0;
+#ifndef RIPPER
+    parser->parser_token_info_enabled = !compile_for_eval && RTEST(ruby_verbose);
+#endif
     n = yyparse((void*)parser);
     ruby_debug_lines = 0;
@@ -6123,4 +6110,28 @@ magic_comment_encoding(struct parser_par
 }
 
+static void
+set_boolean(struct parser_params *parser, int *p, const char *val)
+{
+    if (strcasecmp(val, "enable") == 0 ||
+	strcasecmp(val, "yes") == 0 ||
+	strcasecmp(val, "true") == 0) {
+	*p = 1;
+    }
+    else if (strcasecmp(val, "disable") == 0 ||
+	strcasecmp(val, "no") == 0 ||
+	strcasecmp(val, "false") == 0) {
+	*p = 0;
+    }
+    else {
+	rb_compile_warning(ruby_sourcefile, ruby_sourceline, "invalid boolean %s", val);
+    }
+}
+
+static void
+parser_set_token_info(struct parser_params *parser, const char *name, const char *val)
+{
+    set_boolean(parser, &parser->parser_token_info_enabled, val);
+}
+
 struct magic_comment {
     const char *name;
@@ -6132,4 +6143,5 @@ static const struct magic_comment magic_
     {"coding", magic_comment_encoding, parser_encode_length},
     {"encoding", magic_comment_encoding, parser_encode_length},
+    {"warn-indent", parser_set_token_info},
 };
 #endif
@@ -6178,9 +6190,15 @@ parser_magic_comment(struct parser_param
 	: ((_s) = STR_NEW((_p), (_n))))
 
-    if (len <= 7) return Qfalse;
-    if (!(beg = magic_comment_marker(str, len))) return Qfalse;
-    if (!(end = magic_comment_marker(beg, str + len - beg))) return Qfalse;
-    str = beg;
-    len = end - beg - 3;
+    if (*str == '%') {
+	str++;
+	len--;
+    }
+    else {
+	if (len <= 7) return Qfalse;
+	if (!(beg = magic_comment_marker(str, len))) return Qfalse;
+	if (!(end = magic_comment_marker(beg, str + len - beg))) return Qfalse;
+	str = beg;
+	len = end - beg - 3;
+    }
 
     /* %r"([^\\s\'\":;]+)\\s*:\\s*(\"(?:\\\\.|[^\"])*\"|[^\"\\s;]+)[\\s;]*" */
\f

-- 
Nobu Nakada

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

* [ruby-core:25514] Re: turning off indentation warnings
  2009-09-10 13:39 ` [ruby-core:25510] " Nobuyoshi Nakada
@ 2009-09-10 14:30   ` Yukihiro Matsumoto
  2009-09-10 14:48     ` [ruby-core:25515] " Nikolai Weibull
                       ` (2 more replies)
  2009-09-23  2:49   ` [ruby-core:25725] " Ryan Davis
  2010-10-19 23:40   ` [ruby-core:32854] " Aaron Patterson
  2 siblings, 3 replies; 19+ messages in thread
From: Yukihiro Matsumoto @ 2009-09-10 14:30 UTC (permalink / raw
  To: ruby-core

Hi,

In message "Re: [ruby-core:25510] Re: turning off indentation warnings"
    on Thu, 10 Sep 2009 22:39:50 +0900, Nobuyoshi Nakada <nobu@ruby-lang.org> writes:

|At Mon, 7 Sep 2009 07:53:27 +0900,
|Aaron Patterson wrote in [ruby-core:25442]:
|> Is there a way in 1.9 to turn off only indentation warnings?  I like  
|> to keep warnings turned on, but indentation warnings don't make sense  
|> when the output is generated, like with racc.
|
|Currently, nothing.  How about magic comments?

I am against magic comments.  How about adding command line options,
e.g.  -Wunused in gcc?

							matz.

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

* [ruby-core:25515] Re: turning off indentation warnings
  2009-09-10 14:30   ` [ruby-core:25514] " Yukihiro Matsumoto
@ 2009-09-10 14:48     ` Nikolai Weibull
  2009-09-10 15:50     ` [ruby-core:25517] " Aaron Patterson
  2009-09-10 16:58     ` [ruby-core:25521] " Ryan Davis
  2 siblings, 0 replies; 19+ messages in thread
From: Nikolai Weibull @ 2009-09-10 14:48 UTC (permalink / raw
  To: ruby-core

On Thu, Sep 10, 2009 at 16:30, Yukihiro Matsumoto<matz@ruby-lang.org> wrote:

> In message "Re: [ruby-core:25510] Re: turning off indentation warnings"
>    on Thu, 10 Sep 2009 22:39:50 +0900, Nobuyoshi Nakada <nobu@ruby-lang.org> writes:

> |At Mon, 7 Sep 2009 07:53:27 +0900,
> |Aaron Patterson wrote in [ruby-core:25442]:

> |> Is there a way in 1.9 to turn off only indentation warnings?  I like
> |> to keep warnings turned on, but indentation warnings don't make sense
> |> when the output is generated, like with racc.

> |Currently, nothing.  How about magic comments?

> I am against magic comments.  How about adding command line options,
> e.g.  -Wunused in gcc?

Or perhaps a global, like $VERBOSE, but a map between warning name and boolean?

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

* [ruby-core:25517] Re: turning off indentation warnings
  2009-09-10 14:30   ` [ruby-core:25514] " Yukihiro Matsumoto
  2009-09-10 14:48     ` [ruby-core:25515] " Nikolai Weibull
@ 2009-09-10 15:50     ` Aaron Patterson
  2009-09-10 16:58     ` [ruby-core:25521] " Ryan Davis
  2 siblings, 0 replies; 19+ messages in thread
From: Aaron Patterson @ 2009-09-10 15:50 UTC (permalink / raw
  To: ruby-core


On Sep 10, 2009, at 7:30 AM, Yukihiro Matsumoto wrote:

> Hi,
>
> In message "Re: [ruby-core:25510] Re: turning off indentation  
> warnings"
>    on Thu, 10 Sep 2009 22:39:50 +0900, Nobuyoshi Nakada <nobu@ruby-lang.org 
> > writes:
>
> |At Mon, 7 Sep 2009 07:53:27 +0900,
> |Aaron Patterson wrote in [ruby-core:25442]:
> |> Is there a way in 1.9 to turn off only indentation warnings?  I  
> like
> |> to keep warnings turned on, but indentation warnings don't make  
> sense
> |> when the output is generated, like with racc.
> |
> |Currently, nothing.  How about magic comments?
>
> I am against magic comments.  How about adding command line options,
> e.g.  -Wunused in gcc?

I'm okay with a command line option as long as it is also tied to a  
global other than $-w.  It would be nice to disable indentation  
warnings for *only* the generated file, not the rest of my code.

---
Aaron Patterson
http://tenderlovemaking.com

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

* [ruby-core:25521] Re: turning off indentation warnings
  2009-09-10 14:30   ` [ruby-core:25514] " Yukihiro Matsumoto
  2009-09-10 14:48     ` [ruby-core:25515] " Nikolai Weibull
  2009-09-10 15:50     ` [ruby-core:25517] " Aaron Patterson
@ 2009-09-10 16:58     ` Ryan Davis
  2 siblings, 0 replies; 19+ messages in thread
From: Ryan Davis @ 2009-09-10 16:58 UTC (permalink / raw
  To: ruby-core


On Sep 10, 2009, at 07:30 , Yukihiro Matsumoto wrote:

> Hi,
>
> In message "Re: [ruby-core:25510] Re: turning off indentation  
> warnings"
>    on Thu, 10 Sep 2009 22:39:50 +0900, Nobuyoshi Nakada <nobu@ruby-lang.org 
> > writes:
>
> |At Mon, 7 Sep 2009 07:53:27 +0900,
> |Aaron Patterson wrote in [ruby-core:25442]:
> |> Is there a way in 1.9 to turn off only indentation warnings?  I  
> like
> |> to keep warnings turned on, but indentation warnings don't make  
> sense
> |> when the output is generated, like with racc.
> |
> |Currently, nothing.  How about magic comments?
>
> I am against magic comments.  How about adding command line options,
> e.g.  -Wunused in gcc?

The thing is you only want to turn them off around the generated  
content. Racc outputs a LOT of code and the method bodies are usually  
indented to look good in the .y file, and those aren't correct once  
injected into a .rb file.

I don't like magic comments either. *cough*encoding*cough*

Maybe runtime variable seems better:

$-w-indent = false ?

$-w[:indent] = false ?

something...

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

* [ruby-core:25725] Re: turning off indentation warnings
  2009-09-10 13:39 ` [ruby-core:25510] " Nobuyoshi Nakada
  2009-09-10 14:30   ` [ruby-core:25514] " Yukihiro Matsumoto
@ 2009-09-23  2:49   ` Ryan Davis
  2009-09-23  3:19     ` [ruby-core:25726] " Nobuyoshi Nakada
  2010-10-19 23:40   ` [ruby-core:32854] " Aaron Patterson
  2 siblings, 1 reply; 19+ messages in thread
From: Ryan Davis @ 2009-09-23  2:49 UTC (permalink / raw
  To: ruby-core


On Sep 10, 2009, at 06:39 , Nobuyoshi Nakada wrote:

> Hi,
>
> At Mon, 7 Sep 2009 07:53:27 +0900,
> Aaron Patterson wrote in [ruby-core:25442]:
>> Is there a way in 1.9 to turn off only indentation warnings?  I like
>> to keep warnings turned on, but indentation warnings don't make sense
>> when the output is generated, like with racc.
>
> Currently, nothing.  How about magic comments?

I like this. It allows us to generate code that can bypass these  
warnings w/o too much extra work.

I've looked into adding a global variable. I think it looks better,  
but it requires modifying the parser to evaluate SOME expressions at  
parse time and I think that is a can of worms we don't want to open.

I do have some feedback inline below:

> Index: parse.y
> ===================================================================
> --- parse.y	(revision 24824)
> +++ parse.y	(working copy)
> @@ -244,4 +244,5 @@ struct parser_params {
>
>     token_info *parser_token_info;
> +    int parser_token_info_enabled;
> #else
>     /* Ripper only */
> @@ -587,4 +588,7 @@ static void ripper_compile_error(struct
> static void token_info_push(struct parser_params*, const char *token);
> static void token_info_pop(struct parser_params*, const char *token);
> +#else
> +#define token_info_push(parser, token) /* nothing */
> +#define token_info_pop(parser, token) /* nothing */
> #endif
> %}
> @@ -2970,7 +2974,5 @@ primary_value	: primary
> k_begin		: keyword_begin
> 		    {
> -#ifndef RIPPER
> -			if (RTEST(ruby_verbose)) token_info_push(parser, "begin");
> -#endif
> +			token_info_push(parser, "begin");
> 		    }
> 		;
> @@ -2978,7 +2980,5 @@ k_begin		: keyword_begin
> k_if		: keyword_if
> 		    {
> -#ifndef RIPPER
> -			if (RTEST(ruby_verbose)) token_info_push(parser, "if");
> -#endif
> +			token_info_push(parser, "if");
> 		    }
> 		;
> @@ -2986,7 +2986,5 @@ k_if		: keyword_if
> k_unless	: keyword_unless
> 		    {
> -#ifndef RIPPER
> -			if (RTEST(ruby_verbose)) token_info_push(parser, "unless");
> -#endif
> +			token_info_push(parser, "unless");
> 		    }
> 		;
> @@ -2994,7 +2992,5 @@ k_unless	: keyword_unless
> k_while		: keyword_while
> 		    {
> -#ifndef RIPPER
> -			if (RTEST(ruby_verbose)) token_info_push(parser, "while");
> -#endif
> +			token_info_push(parser, "while");
> 		    }
> 		;
> @@ -3002,7 +2998,5 @@ k_while		: keyword_while
> k_until		: keyword_until
> 		    {
> -#ifndef RIPPER
> -			if (RTEST(ruby_verbose)) token_info_push(parser, "until");
> -#endif
> +			token_info_push(parser, "until");
> 		    }
> 		;
> @@ -3010,7 +3004,5 @@ k_until		: keyword_until
> k_case		: keyword_case
> 		    {
> -#ifndef RIPPER
> -			if (RTEST(ruby_verbose)) token_info_push(parser, "case");
> -#endif
> +			token_info_push(parser, "case");
> 		    }
> 		;
> @@ -3018,7 +3010,5 @@ k_case		: keyword_case
> k_for		: keyword_for
> 		    {
> -#ifndef RIPPER
> -			if (RTEST(ruby_verbose)) token_info_push(parser, "for");
> -#endif
> +			token_info_push(parser, "for");
> 		    }
> 		;
> @@ -3026,7 +3016,5 @@ k_for		: keyword_for
> k_class		: keyword_class
> 		    {
> -#ifndef RIPPER
> -			if (RTEST(ruby_verbose)) token_info_push(parser, "class");
> -#endif
> +			token_info_push(parser, "class");
> 		    }
> 		;
> @@ -3034,7 +3022,5 @@ k_class		: keyword_class
> k_module	: keyword_module
> 		    {
> -#ifndef RIPPER
> -			if (RTEST(ruby_verbose)) token_info_push(parser, "module");
> -#endif
> +			token_info_push(parser, "module");
> 		    }
> 		;
> @@ -3042,7 +3028,5 @@ k_module	: keyword_module
> k_def		: keyword_def
> 		    {
> -#ifndef RIPPER
> -			if (RTEST(ruby_verbose)) token_info_push(parser, "def");
> -#endif
> +			token_info_push(parser, "def");
> 		    }
> 		;
> @@ -3050,7 +3034,5 @@ k_def		: keyword_def
> k_end		: keyword_end
> 		    {
> -#ifndef RIPPER
> -			if (RTEST(ruby_verbose)) token_info_pop(parser, "end");  /* POP */
> -#endif
> +			token_info_pop(parser, "end");  /* POP */
> 		    }
> 		;

I like this a lot. It makes it a lot more readable.

That last comment is completely unnecessary.

> @@ -4826,5 +4808,5 @@ token_info_push(struct parser_params *pa
>     token_info *ptinfo;
>
> -    if (compile_for_eval) return;
> +    if (!parser->parser_token_info_enabled) return;
>     ptinfo = ALLOC(token_info);
>     ptinfo->token = token;
> @@ -4855,7 +4837,9 @@ token_info_pop(struct parser_params *par
> 	goto finish;
>     }
> -    rb_compile_warning(ruby_sourcefile, linenum,
> -               "mismatched indentations at '%s' with '%s' at %d",
> -	       token, ptinfo->token, ptinfo->linenum);
> +    if (parser->parser_token_info_enabled) {
> +	rb_compile_warn(ruby_sourcefile, linenum,
> +			"mismatched indentations at '%s' with '%s' at %d",
> +			token, ptinfo->token, ptinfo->linenum);
> +    }
>
>   finish:
> @@ -4998,4 +4982,7 @@ yycompile0(VALUE arg, int tracing)
>     parser_prepare(parser);
>     deferred_nodes = 0;
> +#ifndef RIPPER
> +    parser->parser_token_info_enabled = !compile_for_eval && RTEST 
> (ruby_verbose);
> +#endif
>     n = yyparse((void*)parser);
>     ruby_debug_lines = 0;
> @@ -6123,4 +6110,28 @@ magic_comment_encoding(struct parser_par
> }
>
> +static void
> +set_boolean(struct parser_params *parser, int *p, const char *val)
> +{
> +    if (strcasecmp(val, "enable") == 0 ||
> +	strcasecmp(val, "yes") == 0 ||
> +	strcasecmp(val, "true") == 0) {
> +	*p = 1;
> +    }
> +    else if (strcasecmp(val, "disable") == 0 ||
> +	strcasecmp(val, "no") == 0 ||
> +	strcasecmp(val, "false") == 0) {
> +	*p = 0;
> +    }
> +    else {
> +	rb_compile_warning(ruby_sourcefile, ruby_sourceline, "invalid  
> boolean %s", val);
> +    }
> +}

Is this really necessary? I'd rather stick to ruby values and remove  
enable/yes/disable/no.

Also, it is only being used once, so why bother abstracting it? Matz  
is (rightfully) against using magic comments, so why enable them  
further?

> +
> +static void
> +parser_set_token_info(struct parser_params *parser, const char  
> *name, const char *val)
> +{
> +    set_boolean(parser, &parser->parser_token_info_enabled, val);
> +}
> +
> struct magic_comment {
>     const char *name;
> @@ -6132,4 +6143,5 @@ static const struct magic_comment magic_
>     {"coding", magic_comment_encoding, parser_encode_length},
>     {"encoding", magic_comment_encoding, parser_encode_length},
> +    {"warn-indent", parser_set_token_info},
> };
> #endif
> @@ -6178,9 +6190,15 @@ parser_magic_comment(struct parser_param
> 	: ((_s) = STR_NEW((_p), (_n))))
>
> -    if (len <= 7) return Qfalse;
> -    if (!(beg = magic_comment_marker(str, len))) return Qfalse;
> -    if (!(end = magic_comment_marker(beg, str + len - beg))) return  
> Qfalse;
> -    str = beg;
> -    len = end - beg - 3;
> +    if (*str == '%') {
> +	str++;
> +	len--;
> +    }
> +    else {
> +	if (len <= 7) return Qfalse;
> +	if (!(beg = magic_comment_marker(str, len))) return Qfalse;
> +	if (!(end = magic_comment_marker(beg, str + len - beg))) return  
> Qfalse;
> +	str = beg;
> +	len = end - beg - 3;
> +    }

What is this change? I don't get the '%' part. It could use a comment  
for clarification because it isn't obvious in this area.

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

* [ruby-core:25726] Re: turning off indentation warnings
  2009-09-23  2:49   ` [ruby-core:25725] " Ryan Davis
@ 2009-09-23  3:19     ` Nobuyoshi Nakada
  2009-09-23  6:10       ` [ruby-core:25727] " Ryan Davis
  2009-09-24 19:01       ` [ruby-core:25752] " Aaron Patterson
  0 siblings, 2 replies; 19+ messages in thread
From: Nobuyoshi Nakada @ 2009-09-23  3:19 UTC (permalink / raw
  To: ruby-core

Hi,

At Wed, 23 Sep 2009 11:49:45 +0900,
Ryan Davis wrote in [ruby-core:25725]:
> I've looked into adding a global variable. I think it looks better,  
> but it requires modifying the parser to evaluate SOME expressions at  
> parse time and I think that is a can of worms we don't want to open.

I agree it's a worst idea.
> > +static void
> > +set_boolean(struct parser_params *parser, int *p, const char *val)
> 
> Is this really necessary? I'd rather stick to ruby values and remove  
> enable/yes/disable/no.

What do you mean by `ruby values'?

> Also, it is only being used once, so why bother abstracting it? Matz  
> is (rightfully) against using magic comments, so why enable them  
> further?

Because it seemed more readable to me at that time.

> > +    if (*str == '%') {
> > +	str++;
> > +	len--;
> > +    }
> > +    else {
> > +	if (len <= 7) return Qfalse;
> > +	if (!(beg = magic_comment_marker(str, len))) return Qfalse;
> > +	if (!(end = magic_comment_marker(beg, str + len - beg))) return  
> > Qfalse;
> > +	str = beg;
> > +	len = end - beg - 3;
> > +    }
> 
> What is this change? I don't get the '%' part. It could use a comment  
> for clarification because it isn't obvious in this area.

No matter, it was just the trace of an experiment.

-- 
Nobu Nakada

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

* [ruby-core:25727] Re: turning off indentation warnings
  2009-09-23  3:19     ` [ruby-core:25726] " Nobuyoshi Nakada
@ 2009-09-23  6:10       ` Ryan Davis
  2009-09-24 19:01       ` [ruby-core:25752] " Aaron Patterson
  1 sibling, 0 replies; 19+ messages in thread
From: Ryan Davis @ 2009-09-23  6:10 UTC (permalink / raw
  To: ruby-core


On Sep 22, 2009, at 20:19 , Nobuyoshi Nakada wrote:

>>> +static void
>>> +set_boolean(struct parser_params *parser, int *p, const char *val)
>> Is this really necessary? I'd rather stick to ruby values and remove
>> enable/yes/disable/no.
> What do you mean by `ruby values'?

ruby literals: true | false

>> Also, it is only being used once, so why bother abstracting it? Matz
>> is (rightfully) against using magic comments, so why enable them
>> further?
>
> Because it seemed more readable to me at that time.

yeah, but I think that is mitigated in part by only allowing true/false.

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

* [ruby-core:25752] Re: turning off indentation warnings
  2009-09-23  3:19     ` [ruby-core:25726] " Nobuyoshi Nakada
  2009-09-23  6:10       ` [ruby-core:25727] " Ryan Davis
@ 2009-09-24 19:01       ` Aaron Patterson
  2009-10-06 17:56         ` [ruby-core:25975] " Aaron Patterson
  1 sibling, 1 reply; 19+ messages in thread
From: Aaron Patterson @ 2009-09-24 19:01 UTC (permalink / raw
  To: ruby-core

On Sep 22, 2009, at 8:19 PM, Nobuyoshi Nakada wrote:

> Hi,
>
> At Wed, 23 Sep 2009 11:49:45 +0900,
> Ryan Davis wrote in [ruby-core:25725]:
>> I've looked into adding a global variable. I think it looks better,
>> but it requires modifying the parser to evaluate SOME expressions at
>> parse time and I think that is a can of worms we don't want to open.
>
> I agree it's a worst idea.

Yes, the global variable seems too hard.  Can we get this patch  
applied (using magic comments)?  I will open a ticket if it helps.

>>> +static void
>>> +set_boolean(struct parser_params *parser, int *p, const char *val)
>>
>> Is this really necessary? I'd rather stick to ruby values and remove
>> enable/yes/disable/no.
>
> What do you mean by `ruby values'?

I think just "true" or "false" would be best, but I'm happy with  
something that works.  ;-)

---
Aaron Patterson
http://tenderlovemaking.com

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

* [ruby-core:25975] Re: turning off indentation warnings
  2009-09-24 19:01       ` [ruby-core:25752] " Aaron Patterson
@ 2009-10-06 17:56         ` Aaron Patterson
  2009-10-06 23:11           ` [ruby-core:25976] " Roger Pack
  0 siblings, 1 reply; 19+ messages in thread
From: Aaron Patterson @ 2009-10-06 17:56 UTC (permalink / raw
  To: ruby-core

On Sep 24, 2009, at 12:01 PM, Aaron Patterson wrote:

> On Sep 22, 2009, at 8:19 PM, Nobuyoshi Nakada wrote:
>
>> Hi,
>>
>> At Wed, 23 Sep 2009 11:49:45 +0900,
>> Ryan Davis wrote in [ruby-core:25725]:
>>> I've looked into adding a global variable. I think it looks better,
>>> but it requires modifying the parser to evaluate SOME expressions at
>>> parse time and I think that is a can of worms we don't want to open.
>>
>> I agree it's a worst idea.
>
> Yes, the global variable seems too hard.  Can we get this patch  
> applied (using magic comments)?  I will open a ticket if it helps.
>
>>>> +static void
>>>> +set_boolean(struct parser_params *parser, int *p, const char *val)
>>>
>>> Is this really necessary? I'd rather stick to ruby values and remove
>>> enable/yes/disable/no.
>>
>> What do you mean by `ruby values'?
>
> I think just "true" or "false" would be best, but I'm happy with  
> something that works.  ;-)

Bump...

---
Aaron Patterson
http://tenderlovemaking.com

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

* [ruby-core:25976] Re: turning off indentation warnings
  2009-10-06 17:56         ` [ruby-core:25975] " Aaron Patterson
@ 2009-10-06 23:11           ` Roger Pack
  2009-10-07  6:00             ` [ruby-core:25985] " Ryan Davis
  2009-10-07 20:37             ` [ruby-core:26001] " Aaron Patterson
  0 siblings, 2 replies; 19+ messages in thread
From: Roger Pack @ 2009-10-06 23:11 UTC (permalink / raw
  To: ruby-core

>>>> I've looked into adding a global variable. I think it looks better,
>>>> but it requires modifying the parser to evaluate SOME expressions at
>>>> parse time and I think that is a can of worms we don't want to open.
>>>
>>> I agree it's a worst idea.

One idea might be, if you don't want formatting warnings, to
"pre-format" code before you require it.
(ruby prettifier or ruby2ruby(ruby_parser) it).

Or perhaps redirect:
$alias ruby=ruby_wrapper_script_which_swallows_indentation_warnings
GL.
-r

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

* [ruby-core:25985] Re: turning off indentation warnings
  2009-10-06 23:11           ` [ruby-core:25976] " Roger Pack
@ 2009-10-07  6:00             ` Ryan Davis
  2009-10-07 15:51               ` [ruby-core:25994] " Roger Pack
  2009-10-07 20:37             ` [ruby-core:26001] " Aaron Patterson
  1 sibling, 1 reply; 19+ messages in thread
From: Ryan Davis @ 2009-10-07  6:00 UTC (permalink / raw
  To: ruby-core


On Oct 6, 2009, at 16:11 , Roger Pack wrote:

> One idea might be, if you don't want formatting warnings, to
> "pre-format" code before you require it.
> (ruby prettifier or ruby2ruby(ruby_parser) it).

That's an awful idea, and I wrote both ruby2ruby and ruby_parser.

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

* [ruby-core:25994] Re: turning off indentation warnings
  2009-10-07  6:00             ` [ruby-core:25985] " Ryan Davis
@ 2009-10-07 15:51               ` Roger Pack
  2009-10-07 20:27                 ` [ruby-core:26000] " Ryan Davis
  0 siblings, 1 reply; 19+ messages in thread
From: Roger Pack @ 2009-10-07 15:51 UTC (permalink / raw
  To: ruby-core

>> One idea might be, if you don't want formatting warnings, to
>> "pre-format" code before you require it.
>> (ruby prettifier or ruby2ruby(ruby_parser) it).
>
> That's an awful idea, and I wrote both ruby2ruby and ruby_parser.

Why do you consider it so?

Also, another option would be generate properly formatted code.

-r

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

* [ruby-core:26000] Re: turning off indentation warnings
  2009-10-07 15:51               ` [ruby-core:25994] " Roger Pack
@ 2009-10-07 20:27                 ` Ryan Davis
  0 siblings, 0 replies; 19+ messages in thread
From: Ryan Davis @ 2009-10-07 20:27 UTC (permalink / raw
  To: ruby-core


On Oct 7, 2009, at 08:51 , Roger Pack wrote:

>>> One idea might be, if you don't want formatting warnings, to
>>> "pre-format" code before you require it.
>>> (ruby prettifier or ruby2ruby(ruby_parser) it).
>>
>> That's an awful idea, and I wrote both ruby2ruby and ruby_parser.
>
> Why do you consider it so?
>
> Also, another option would be generate properly formatted code.

Please stop generating "options" for us. We understand the problem.

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

* [ruby-core:26001] Re: turning off indentation warnings
  2009-10-06 23:11           ` [ruby-core:25976] " Roger Pack
  2009-10-07  6:00             ` [ruby-core:25985] " Ryan Davis
@ 2009-10-07 20:37             ` Aaron Patterson
  2009-10-07 20:50               ` [ruby-core:26003] " Roger Pack
  1 sibling, 1 reply; 19+ messages in thread
From: Aaron Patterson @ 2009-10-07 20:37 UTC (permalink / raw
  To: ruby-core

On Oct 6, 2009, at 4:11 PM, Roger Pack wrote:

>>>>> I've looked into adding a global variable. I think it looks  
>>>>> better,
>>>>> but it requires modifying the parser to evaluate SOME  
>>>>> expressions at
>>>>> parse time and I think that is a can of worms we don't want to  
>>>>> open.
>>>>
>>>> I agree it's a worst idea.
>
> One idea might be, if you don't want formatting warnings, to
> "pre-format" code before you require it.
> (ruby prettifier or ruby2ruby(ruby_parser) it).

No.  Then line number information is lost when the code is generated.   
Think of the fun you would have tracking down exceptions when the line  
numbers are meaningless.

> Or perhaps redirect:
> $alias ruby=ruby_wrapper_script_which_swallows_indentation_warnings

This doesn't make sense.  If I distribute the generated code (which I  
always do), should I expect my users to do this?

---
Aaron Patterson
http://tenderlovemaking.com

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

* [ruby-core:26003] Re: turning off indentation warnings
  2009-10-07 20:37             ` [ruby-core:26001] " Aaron Patterson
@ 2009-10-07 20:50               ` Roger Pack
  2009-10-07 21:16                 ` [ruby-core:26004] " Aaron Patterson
  0 siblings, 1 reply; 19+ messages in thread
From: Roger Pack @ 2009-10-07 20:50 UTC (permalink / raw
  To: ruby-core

> No.  Then line number information is lost when the code is generated.  Think
> of the fun you would have tracking down exceptions when the line numbers are
> meaningless.

I think I understand.  You thought I meant "pretty format those files
at runtime just before requiring them" to avoid the indentation
warnings--is that right?

If so--I was suggesting that it might be possible to pretty format
them as an end part of the generate phase.
Sorry for the confusion.

-roger

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

* [ruby-core:26004] Re: turning off indentation warnings
  2009-10-07 20:50               ` [ruby-core:26003] " Roger Pack
@ 2009-10-07 21:16                 ` Aaron Patterson
  0 siblings, 0 replies; 19+ messages in thread
From: Aaron Patterson @ 2009-10-07 21:16 UTC (permalink / raw
  To: ruby-core

On Oct 7, 2009, at 1:50 PM, Roger Pack wrote:

>> No.  Then line number information is lost when the code is  
>> generated.  Think
>> of the fun you would have tracking down exceptions when the line  
>> numbers are
>> meaningless.
>
> I think I understand.  You thought I meant "pretty format those files
> at runtime just before requiring them" to avoid the indentation
> warnings--is that right?
>
> If so--I was suggesting that it might be possible to pretty format
> them as an end part of the generate phase.
> Sorry for the confusion.

No, pretty formatting them at any time is a bad idea.  Any  
reformatting at any time will make tracking down exceptions a giant  
PITA.

---
Aaron Patterson
http://tenderlovemaking.com

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

* [ruby-core:32854] Re: turning off indentation warnings
  2009-09-10 13:39 ` [ruby-core:25510] " Nobuyoshi Nakada
  2009-09-10 14:30   ` [ruby-core:25514] " Yukihiro Matsumoto
  2009-09-23  2:49   ` [ruby-core:25725] " Ryan Davis
@ 2010-10-19 23:40   ` Aaron Patterson
  2 siblings, 0 replies; 19+ messages in thread
From: Aaron Patterson @ 2010-10-19 23:40 UTC (permalink / raw
  To: ruby-core

[-- Attachment #1: Type: text/plain, Size: 805 bytes --]

On Thu, Sep 10, 2009 at 10:39:50PM +0900, Nobuyoshi Nakada wrote:
> Hi,
> 
> At Mon, 7 Sep 2009 07:53:27 +0900,
> Aaron Patterson wrote in [ruby-core:25442]:
> > Is there a way in 1.9 to turn off only indentation warnings?  I like  
> > to keep warnings turned on, but indentation warnings don't make sense  
> > when the output is generated, like with racc.
> 
> Currently, nothing.  How about magic comments?

*bump*

This is still a thorn in my side.  People report bugs against nokogiri,
when this is really because Ruby shouldn't emit warnings when we know
that Ruby code is generated like with Racc.

Here is a ticket where someone reported the issue with nokogiri:

  http://github.com/tenderlove/nokogiri/issues/#issue/314

-- 
Aaron Patterson
http://tenderlovemaking.com/

[-- Attachment #2: Type: application/pgp-signature, Size: 487 bytes --]

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

end of thread, other threads:[~2010-10-19 23:42 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-06 22:53 [ruby-core:25442] turning off indentation warnings Aaron Patterson
2009-09-10 13:39 ` [ruby-core:25510] " Nobuyoshi Nakada
2009-09-10 14:30   ` [ruby-core:25514] " Yukihiro Matsumoto
2009-09-10 14:48     ` [ruby-core:25515] " Nikolai Weibull
2009-09-10 15:50     ` [ruby-core:25517] " Aaron Patterson
2009-09-10 16:58     ` [ruby-core:25521] " Ryan Davis
2009-09-23  2:49   ` [ruby-core:25725] " Ryan Davis
2009-09-23  3:19     ` [ruby-core:25726] " Nobuyoshi Nakada
2009-09-23  6:10       ` [ruby-core:25727] " Ryan Davis
2009-09-24 19:01       ` [ruby-core:25752] " Aaron Patterson
2009-10-06 17:56         ` [ruby-core:25975] " Aaron Patterson
2009-10-06 23:11           ` [ruby-core:25976] " Roger Pack
2009-10-07  6:00             ` [ruby-core:25985] " Ryan Davis
2009-10-07 15:51               ` [ruby-core:25994] " Roger Pack
2009-10-07 20:27                 ` [ruby-core:26000] " Ryan Davis
2009-10-07 20:37             ` [ruby-core:26001] " Aaron Patterson
2009-10-07 20:50               ` [ruby-core:26003] " Roger Pack
2009-10-07 21:16                 ` [ruby-core:26004] " Aaron Patterson
2010-10-19 23:40   ` [ruby-core:32854] " Aaron Patterson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).