ammar / regexp_parser

A regular expression parser library for Ruby
MIT License
143 stars 22 forks source link

Warnings in generated scanner.rb in some situations #10

Closed jhart-r7 closed 8 years ago

jhart-r7 commented 9 years ago

In some situations (TBD), while running unit tests for https://github.com/rapid7/recog/, we get warnings like:

/home/jhart/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/regexp_parser-0.3.0/lib/regexp_parser/scanner.rb:2463: warning: mismatched indentations at 'end' with 'begin' at 1713
... dozens of these ...
/home/jhart/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/regexp_parser-0.3.0/lib/regexp_parser/scanner.rb:2753: warning: statement not reached
/home/jhart/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/regexp_parser-0.3.0/lib/regexp_parser/scanner.rb:1648: warning: assigned but unused variable - testEof
/home/jhart/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/regexp_parser-0.3.0/lib/regexp_parser/scanner.rb:2236: warning: duplicated when clause is ignored
/home/jhart/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/regexp_parser-0.3.0/lib/regexp_parser/lexer.rb:118: warning: assigned but unused variable - replace
/home/jhart/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/regexp_parser-0.3.0/lib/regexp_parser/scanner.rb:4200: warning: instance variable @literal not initialized

I also got these with 0.2.1.

You can reproduce most of these with ruby -we 'require "regexp_parser"; Regexp::Scanner.scan(/(foo)/) do |token_parts| puts "capture" if token_parts.first == :group && ![:close, :passive].include?(token_parts[1]); end'

ammar commented 9 years ago

Thanks for the report.

Only one of these warning is caused by non-generated code (the one in lexer.rb:118). A fix for that one was just pushed to the dev branch. A new release will be made tomorrow.

For the rest, I couldn't find options that could fix the generated output, and I'm hesitant to add a post-processing step to do it. This is clearly an issue with ragel.

I will investigate a little more to see if others had to deal with this before.

backus commented 8 years ago

So I took a look at whitequark/parser's ragel compilation and they just disable indentation warnings in their generated source code using the warn-indent magic comment. I think regexp_parser should use this too

ammar commented 8 years ago

Fixed with the release of 0.3.6