Ticket #243 (closed defect: fixed)

Opened 5 months ago

Last modified 1 week ago

Ruby: Quotes inside regex literals cause incorrect code parsing

Reported by: xhochy Assigned to:
Priority: like Milestone: current
Component: parser Version: current
Severity: bad Keywords: ruby comments unrecognized
Cc: uwelk@xhochy.org

Description

When I use ohcount on my ruby code, serveral comments are recognized as code, I didn't figured out, where the failure is.

I'll attach the file and the output of ohcount -a <file>

My System:

Ubuntu 7.10 x64 Ruby: 1.8.2-1 Rake: 0.7.1-2

I tested ohcount 1.0.0 and the git revision changeset:11653d2154f46ac5076effeccc5e8a9db11cbdc8

Attachments

packer.rb (8.9 kB) - added by xhochy on 03/20/2008 11:14:53 AM.
ruby sourcecode with the unrecognized comments
ohcount_output.txt (11.6 kB) - added by xhochy on 03/20/2008 11:16:14 AM.
The output of ohcount -a

Change History

03/20/2008 11:14:53 AM changed by xhochy

  • attachment packer.rb added.

ruby sourcecode with the unrecognized comments

03/20/2008 11:15:26 AM changed by xhochy

  • keywords set to ruby comments unrecognized.

03/20/2008 11:16:14 AM changed by xhochy

  • attachment ohcount_output.txt added.

The output of ohcount -a

03/20/2008 11:24:37 AM changed by xhochy

  • cc set to uwelk@xhochy.org.

03/20/2008 03:26:57 PM changed by robin@ohloh.net

I can confirm the bug. It applies to any Ruby file that includes quote characters inside of regular expression literals.

Try this:

/'/
# This should be a comment

The unmatched quote inside the regular expression leads the parser to interpret the entire remainder of the file as part of an unterminated string.

The parser requires a new kind of string delimiter, treating / as a string delimiter, similar to ' or ".

03/20/2008 03:28:20 PM changed by robin@ohloh.net

  • summary changed from Not all ruby comments are recognized to Ruby: Quotes inside regex literals cause incorrect code parsing.

03/20/2008 03:30:31 PM changed by xhochy

'/' cannot always be treated as a string delimiter since it could be used for divisions too, so that there needs to be some code that detects regular expressions and treats only those as string, but mathematical operation shouldn't be treated as strings.

03/28/2008 05:59:54 PM changed by robin@ohloh.net

  • owner deleted.

07/07/2008 02:15:06 PM changed by robin@ohloh.net

  • status changed from new to closed.
  • resolution set to fixed.

The ruby parser has been considerably improved in the Ragel branch. The sample above now parses correctly.

Although not perfect, the parser is improved enough to close this bug.

08/12/2008 08:19:29 AM changed by add

http://www.salewroughtiron.cn installing metal stair rails Interior stair handrail installing metal stair rails Interior stair handrail exterior baluster Glass wood stainless wrought CONTEMPORARY designs stairways aluminum modern log banister DECK outdoor price posts vinyl curved rails http://www.china-made-door.com.cn door gate http://www.beijing-door.cn wrought CONTEMPORARY designs stairways installing metal stair rails Interior stair handrail exterior baluster Glass wood stainless wrought CONTEMPORARY designs stairways aluminum modern log banister DECK outdoor price posts vinyl curved rails http://www.hebei-railings.cn aluminum modern log banister DECK outdoor price installing metal stair rails Interior stair handrail exterior baluster Glass wood stainless wrought CONTEMPORARY designs stairways aluminum modern log banister DECK outdoor price posts vinyl curved rails posts vinyl curved rails