deblondon / google-code-prettify

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

Rust highlighting doesn't handle lifetime parameters correctly #347

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

The highlighting for Rust does not properly handle lifetimes. It treats the 
lifetime sigil ' as the start of a string instead (even though Rust doesn't 
support single-quoted strings). This causes bad rendering.

This causes a problem on StackOverflow, when people post questions about Rust. 
For example, in a question asked 19 hours ago 
(http://stackoverflow.com/questions/24855830/how-convert-a-string-in-str-in-impl
-block-in-rust), the first code block contains a struct definition with a field 
`title: &'static str`. The rest of the code block from the ' is colored red, as 
if it were a string, when in fact 'static is a lifetime specifier.

In Rust, the ' token is either used to start a character literal, or a 
lifetime. if the ' is followed by a single unicode character (or a single 
escape, such as \n, \t, \u2022), and then another ', then it is a character 
literal. Otherwise, if it's followed by a single identifier that meets the 
identifier rules, the ' with the identifier are considered a lifetime 
(otherwise, it's assumed to be an unterminated character literal).

Original issue reported on code.google.com by kball...@gmail.com on 21 Jul 2014 at 6:35

GoogleCodeExporter commented 8 years ago
I actually don't even see a lang-rust.js file anywhere, which leads me to 
believe that SO is just using some other arbitrary language to highlight Rust 
code.

I've filed an issue in the Rust repo to implement proper Rust highlighting 
support (https://github.com/rust-lang/rust/issues/18931).

Original comment by ben.stri...@gmail.com on 13 Nov 2014 at 7:12

GoogleCodeExporter commented 8 years ago
I removed the generic references to rust from prettify.js and added a separate 
lang-rust.js file to provide better highlighting for rust.

Please review the attached diff and let me know if I need to make any further 
changes.

Original comment by nospacel...@gmail.com on 10 Dec 2014 at 6:19

Attachments: