ZhouShuo / google-code-prettify

Automatically exported from code.google.com/p/google-code-prettify
Apache License 2.0
0 stars 0 forks source link

ruby regexp and general delimeted input broken #131

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
/"/ and /'/ marks the rest of file (until another quote character) to be 
highlighted as string literal.
General delimeted input like %r!watever! or %q[abc] are not supported either.

Some broken examples:
1
/'/ =~ '"' 2
/"/ 3
/"/ 4
/"/ 5
'"' 6

# comment extends from ' in 2 until " in 3, similarly from 4 to 5

%r[hello]
%r!hello!
%r'hello'

%w[ a b c d 1 ]

'this is a string'
%q/this is a string/

# nothing above is supported

Original issue reported on code.google.com by mwisnicki@gmail.com on 28 Sep 2010 at 12:41

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
"comment extends" should be "string extends"

also, this is on r114

Original comment by mwisnicki@gmail.com on 28 Sep 2010 at 12:44

GoogleCodeExporter commented 9 years ago
Also, REGEX_LITERAL assumes C/C++ style comments which is not the case outside 
of JavaScript.

Original comment by mwisnicki@gmail.com on 28 Sep 2010 at 12:53

GoogleCodeExporter commented 9 years ago
You are correct about general string terminators.
I need to handle ruby strings properly as well as perl style q(...), qq(...), 
qw(...), m(...) and s(...)(...).   Does ruby have a double string form like the 
perl s/.../.../ construct?

ruby should recognize regular expression literals and hash comments though.

At line 1330 of prettify.js

  registerLangHandler(sourceDecorator({
          'keywords': RUBY_KEYWORDS,
          'hashComments': true,
          'multiLineStrings': true,
          'regexLiterals': true
        }), ['rb']);

Does this problem persist when you add lang-rb to the class along with prettify 
to specify that the language is ruby?
<pre class="prettyprint lang-rb">
# Your ruby code here?
</pre>

Original comment by mikesamuel@gmail.com on 4 Mar 2011 at 8:32

GoogleCodeExporter commented 9 years ago
No, there are only regex options which look like: /whatever/i

It seems my examples were somewhat wrong/unclear but it does not:

1. detect regex literal at the start of the line:
/whatever/

2. detect regex in 'when' construct
3. terminate empty regex // because REGEX_LITERAL at
src/prettify.js:1010 assumes they are used for C++-style comments.

Yes

Attaching patch that fixes 'when /regex/' and adds highlighting of @@,
$$ and $ variables.

I have tried replacing + with * at line 1018 to theoretically unbreak
empty regex at the cost of breaking c++ comments, however it didn't
seem to fix the problem.

I've also tried adding '|^|' to REGEXP_PRECEDER_PATTERN to fix lines
starting with regex but it broke other things like division operator.

Original comment by mwisnicki@gmail.com on 16 Mar 2011 at 3:19

GoogleCodeExporter commented 9 years ago
Seems that attachments are stripped when responding by email.

Original comment by mwisnicki@gmail.com on 16 Mar 2011 at 3:22

Attachments:

GoogleCodeExporter commented 9 years ago
Argh... and quotations were also removed.

'Yes' is a response to question about lang-rb css class.

Original comment by mwisnicki@gmail.com on 16 Mar 2011 at 3:28