This is a multi-part message in MIME format. --------------090401050005030602070105 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 18.04.10 16:10, Benoit Daloze wrote: > Sure, but that's why I showed that any variable which is also a method > in a scope can cause this problem. I agree that it's a problematic part of Ruby's syntax. I think it comes partly from method-call parentheses being optional. It's a trade-off. > If there is more spaces at left than right of the 'operator' it should > be a method. > p % [a] # operator > p %[a] # method > p%[a] # operator +1. I think this rule should ony distinguish "no space" and "one ore more spaces". Otherwise, we'd have to start counting spaces. Fun for the next obfuscation contest. > This idea is valid only if the right part is a literal expression: > p % a , p %a , p%a are in all cases operators. I'm not sure whether the lexer can look ahead this far. > Would it be possible to implement a rule like that: > "if more spaces at left than right and right is a literal expression, > consider left as a method" (instead of always as an operator) As far as I understood nobus patch, it does exactly that. > Are you thinking the same way to consider theses expressions ? I think everything should be evaluated "intuitively", whatever this means ;) The rules you outlined seem much more intuitive to me. > This change is only an improvement to my opinion, so I don't see when it > can cause problems. Incompatibility is a problem. I wouldn't start to write code that's only valid in Ruby 1.9.2, because 1.8.7 is so much more popular. But it doesn't seem to be a problem yet. I checked the syntax of 20K Ruby files in 300 gems before and after nobu's patch. The diff is attached. Only obscure code (like Caleb's rubylexer examples ;) and ERB templates (which are invalid anyway) seem to be hit. [murphy] --------------090401050005030602070105 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name yntax-check-r27387vs27388.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename yntax-check-r27387vs27388.diff" --- syntax-check-ruby192-r27387-errors 2010-04-18 19:08:02.000000000 +0200 +++ syntax-check-ruby192-r27388-errors 2010-04-18 18:58:26.000000000 +0200 @@ -352,12 +352,18 @@ ./has_many_polymorphs-2.13/generators/tagging/templates/tag.rb:20: syntax error, unexpected tIDENTIFIER, expecting keyword_end <% if options[:self_referential] -%> :a... ^ -./has_many_polymorphs-2.13/generators/tagging/templates/tag.rb:20: syntax error, unexpected ':', expecting keyword_end +./has_many_polymorphs-2.13/generators/tagging/templates/tag.rb:20: syntax error, unexpected tSYMBEG, expecting keyword_end ...lf_referential] -%> :as :<% arent_association_name -... ... ^ -./has_many_polymorphs-2.13/generators/tagging/templates/tag.rb:22: syntax error, unexpected ',', expecting keyword_end +./has_many_polymorphs-2.13/generators/tagging/templates/tag.rb:22: syntax error, unexpected tASSOC, expecting keyword_end + :skip_duplicates false, + ^ +./has_many_polymorphs-2.13/generators/tagging/templates/tag.rb:22: Can't assign to false :skip_duplicates false, ^ +./has_many_polymorphs-2.13/generators/tagging/templates/tag.rb:23: syntax error, unexpected tASSOC, expecting tCOLON2 or '[' or '.' + :parent_extend proc { + ^ ./has_many_polymorphs-2.13/generators/tagging/templates/tag_test.rb:12: syntax error, unexpected tIDENTIFIER, expecting keyword_end ... "imperial pale", <% odel_two -%>.find(:first).tags.to_s ... ^ @@ -611,13 +617,13 @@ ./merb-gen-1.0.15/lib/generators/templates/application/merb_core/config/init.rb:6: syntax error, unexpected '<' <% # " unless orm ! none %> use_orm :<% rm %> ^ -./merb-gen-1.0.15/lib/generators/templates/application/merb_core/config/init.rb:6: syntax error, unexpected ':', expecting $end +./merb-gen-1.0.15/lib/generators/templates/application/merb_core/config/init.rb:6: syntax error, unexpected tSYMBEG, expecting $end <% # " unless orm ! none %> use_orm :<% rm %> ^ ./merb-gen-1.0.15/lib/generators/templates/application/merb_flat/config/init.rb:3: syntax error, unexpected '<' <% # " unless orm ! none %> use_orm :<% rm %> ^ -./merb-gen-1.0.15/lib/generators/templates/application/merb_flat/config/init.rb:3: syntax error, unexpected ':', expecting $end +./merb-gen-1.0.15/lib/generators/templates/application/merb_flat/config/init.rb:3: syntax error, unexpected tSYMBEG, expecting $end <% # " unless orm ! none %> use_orm :<% rm %> ^ ./merb-gen-1.0.15/lib/generators/templates/application/merb_plugin/lib/%base_name%/merbtasks.rb:1: syntax error, unexpected tOP_ASGN, expecting $end @@ -2197,6 +2203,9 @@ ^ ./rubylexer-0.7.7/test/data/jarh.rb:189: warning: string literal in condition ./rubylexer-0.7.7/test/data/jarh.rb:189: warning: string literal in condition +./rubylexer-0.7.7/test/data/jarh.rb:349: syntax error, unexpected tSYMBEG, expecting ':' +print true ? "Just another Ruby hacker," :-P + ^ ./rubylexer-0.7.7/test/data/newsyntax.rb:11: syntax error, unexpected ';', expecting ')' p($/ '; Array( "i'm in your house" )) ^ @@ -2230,6 +2239,15 @@ ./rubylexer-0.7.7/test/data/regtest.rb:457: warning: ambiguous first argument; put parentheses or even spaces ./rubylexer-0.7.7/test/data/regtest.rb:458: warning: ambiguous first argument; put parentheses or even spaces ./rubylexer-0.7.7/test/data/regtest.rb:607: warning: mismatched indentations at 'end' with 'class' at 12 +./rubylexer-0.7.7/test/data/s.rb:171: syntax error, unexpected tSYMBEG, expecting ':' +false ? 2 :O + ^ +./rubylexer-0.7.7/test/data/s.rb:183: syntax error, unexpected tSYMBEG, expecting ':' +eof??nil :true + ^ +./rubylexer-0.7.7/test/data/s.rb:193: syntax error, unexpected tSYMBEG, expecting ':' +eof!?nil :true + ^ ruby19: Permission denied -- ./rubymacros-0.1.5/example/__dir__.rb (LoadError) ruby19: Permission denied -- ./rubymacros-0.1.5/example/__dir___wrap.rb (LoadError) ./rubymacros-0.1.5/example/andand.rb:2: syntax error, unexpected '(', expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END @@ -2312,9 +2330,9 @@ ./rubymacros-0.1.5/example/linenum.rb:2: syntax error, unexpected ')', expecting $end ruby19: Permission denied -- ./rubymacros-0.1.5/example/loop.rb (LoadError) ruby19: Permission denied -- ./rubymacros-0.1.5/example/loop_wrap.rb (LoadError) -./rubymacros-0.1.5/example/simple.rb:1: syntax error, unexpected '^' +./rubymacros-0.1.5/example/simple.rb:1: syntax error, unexpected tSYMBEG, expecting $end macro simple(a,b) :(^a+^b) end - ^ + ^ ruby19: Permission denied -- ./rubymacros-0.1.5/example/with.rb (LoadError) ruby19: Permission denied -- ./rubymacros-0.1.5/example/with_wrap.rb (LoadError) ./rubymacros-0.1.5/lib/macro.rb:129: syntax error, unexpected tLABEL --------------090401050005030602070105--