Skip to content

Commit

Permalink
Rust: Regexp optimisation and simplification + don't use captures if …
Browse files Browse the repository at this point in the history
…not needed
  • Loading branch information
Golmote committed Oct 22, 2017
1 parent 4902ed4 commit cc9d874
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions components/prism-rust.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ Prism.languages.rust = {
],
'string': [
{
pattern: /b?r(#*)"(?:\\?.)*?"\1/,
pattern: /b?r(#*)"(?:\\.|(?!"\1)[^\\\r\n])*"\1/,
greedy: true
},
{
pattern: /b?("|')(?:\\?.)*?\1/,
pattern: /b?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
greedy: true
}
],
Expand All @@ -35,23 +35,23 @@ Prism.languages.rust = {
},

'function': [
/[a-z0-9_]+(?=\s*\()/i,
/\w+(?=\s*\()/,
// Macros can use parens or brackets
/[a-z0-9_]+!(?=\s*\(|\[)/i
/\w+!(?=\s*\(|\[)/
],
'macro-rules': {
pattern: /[a-z0-9_]+!/i,
pattern: /\w+!/,
alias: 'function'
},

// Hex, oct, bin, dec numbers with visual separators and type suffix
'number': /\b-?(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(\d(_?\d)*)?\.?\d(_?\d)*([Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32|64)?|f32|f64))?\b/,
'number': /\b-?(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(\d(?:_?\d)*)?\.?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32|64)?|f32|f64))?\b/,

// Closure params should not be confused with bitwise OR |
'closure-params': {
pattern: /\|[^|]*\|(?=\s*[{-])/,
inside: {
'punctuation': /[\|:,]/,
'punctuation': /[|:,]/,
'operator': /[&*]/
}
},
Expand Down
2 changes: 1 addition & 1 deletion components/prism-rust.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cc9d874

Please sign in to comment.