1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-02-13 13:28:27 +02:00

Rust multi-line strings

Quoting Rust documentation

> Line-breaks are allowed in string literals. A line-break is either a newline
> (U+000A) or a pair of carriage return and newline (U+000D, U+000A).

https://doc.rust-lang.org/reference/tokens.html#string-literals
This commit is contained in:
Steven Penny 2020-11-06 14:45:10 -06:00 committed by Alec Thomas
parent ab61726cdb
commit 552ad244cf
3 changed files with 27 additions and 3 deletions

View File

@ -28,8 +28,8 @@ var Rust = internal.Register(MustNewLexer(
{`/\*\*(\n|[^/*])`, LiteralStringDoc, Push("doccomment")},
{`/\*!`, LiteralStringDoc, Push("doccomment")},
{`/\*`, CommentMultiline, Push("comment")},
{`r#*"(?:\\.|[^\\\r\n;])*"#*`, LiteralString, nil},
{`"(?:\\.|[^\\\r\n"])*"`, LiteralString, nil},
{`r#*"(?:\\.|[^\\;])*"#*`, LiteralString, nil},
{`"(?:\\.|[^\\"])*"`, LiteralString, nil},
{`\$([a-zA-Z_]\w*|\(,?|\),?|,?)`, CommentPreproc, nil},
{Words(``, `\b`, `as`, `async`, `await`, `const`, `crate`, `else`, `extern`, `for`, `if`, `impl`, `in`, `loop`, `match`, `move`, `mut`, `pub`, `ref`, `return`, `static`, `super`, `trait`, `unsafe`, `use`, `where`, `while`), Keyword, nil},
{Words(``, `\b`, `abstract`, `become`, `box`, `do`, `final`, `macro`, `override`, `priv`, `try`, `typeof`, `unsized`, `virtual`, `yield`), KeywordReserved, nil},

View File

@ -14,4 +14,10 @@ fn main() {
let r#type = "valid";
let i: i128 = 1117;
let s = "March
April";
let s = r"March
April";
}

View File

@ -86,7 +86,25 @@
{"type":"TextWhitespace","value":" "},
{"type":"LiteralNumberInteger","value":"1117"},
{"type":"Punctuation","value":";"},
{"type":"TextWhitespace","value":"\n"},
{"type":"TextWhitespace","value":"\n\n "},
{"type":"KeywordDeclaration","value":"let"},
{"type":"TextWhitespace","value":" "},
{"type":"Name","value":"s"},
{"type":"TextWhitespace","value":" "},
{"type":"Operator","value":"="},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralString","value":"\"March\nApril\""},
{"type":"Punctuation","value":";"},
{"type":"TextWhitespace","value":"\n "},
{"type":"KeywordDeclaration","value":"let"},
{"type":"TextWhitespace","value":" "},
{"type":"Name","value":"s"},
{"type":"TextWhitespace","value":" "},
{"type":"Operator","value":"="},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralString","value":"r\"March\nApril\""},
{"type":"Punctuation","value":";"},
{"type":"TextWhitespace","value":"\n\n"},
{"type":"Punctuation","value":"}"},
{"type":"TextWhitespace","value":"\n"}
]