rubychan / coderay

Fast and easy syntax highlighting for selected languages, written in Ruby.
http://coderay.rubychan.de/
Other
846 stars 115 forks source link

Ruby 1.9 Hash syntax is still not parsed correctly #171

Closed janko closed 10 years ago

janko commented 10 years ago
Hash[*CodeRay.scan("{:foo => 'bar', foo: 'bar'}", :ruby).tokens]
 {"{"=>:operator,
 ":foo"=>:symbol,
 " "=>:space,
 "="=>:operator,
 ">"=>:operator,
 :begin_group=>:string,
 "'"=>:delimiter,
 "bar"=>:content,
 :end_group=>:string,
 ","=>:operator,
 "foo"=>:key,        # this should be parsed as `:symbol`
 ":"=>:operator,     # and this too
 "}"=>:operator}
korny commented 10 years ago

It's intended behavior:

kyrylo commented 10 years ago

I can see your reasoning, but consider this example: https://github.com/kyrylo/pry-theme/issues/30 (the project depends on CodeRay).

Particularly, the class key is considered as a keyword.

{
  foo: 1,
  class: 2
}

By the way, GitHub sees it as a symbol.

korny commented 10 years ago

Particularly, the class key is considered as a keyword.

Not since 1.1, this was fixed in #126.

By the way, GitHub sees it as a symbol.

GitHub uses Pygments; it's an awesome highlighter written in Python, and the team is great, but it is not a Ruby reference ;-) VIM, for example, uses the same style as CodeRay; TextMate uses the GitHub style.