Skip to content

Commit

Permalink
Ruby: 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 d7f0ee8 commit 4902ed4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions components/prism-ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/#(?!\{[^\r\n]*?\}).*/,
/^=begin(?:\r?\n|\r)(?:.*(?:\r?\n|\r))*?=end/m
],
'keyword': /\b(alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|false|for|if|in|module|new|next|nil|not|or|raise|redo|require|rescue|retry|return|self|super|then|throw|true|undef|unless|until|when|while|yield)\b/
'keyword': /\b(?:alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|false|for|if|in|module|new|next|nil|not|or|raise|redo|require|rescue|retry|return|self|super|then|throw|true|undef|unless|until|when|while|yield)\b/
});

var interpolation = {
Expand All @@ -27,7 +27,7 @@
Prism.languages.insertBefore('ruby', 'keyword', {
'regex': [
{
pattern: /%r([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1[gim]{0,3}/,
pattern: /%r([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1[gim]{0,3}/,
greedy: true,
inside: {
'interpolation': interpolation
Expand Down Expand Up @@ -68,18 +68,18 @@
greedy: true
}
],
'variable': /[@$]+[a-zA-Z_][a-zA-Z_0-9]*(?:[?!]|\b)/,
'symbol': /:[a-zA-Z_][a-zA-Z_0-9]*(?:[?!]|\b)/
'variable': /[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/,
'symbol': /:[a-zA-Z_]\w*(?:[?!]|\b)/
});

Prism.languages.insertBefore('ruby', 'number', {
'builtin': /\b(Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Stat|File|Fixnum|Float|Hash|Integer|IO|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|String|Struct|TMS|Symbol|ThreadGroup|Thread|Time|TrueClass)\b/,
'constant': /\b[A-Z][a-zA-Z_0-9]*(?:[?!]|\b)/
'builtin': /\b(?:Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Stat|Fixnum|Float|Hash|Integer|IO|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|String|Struct|TMS|Symbol|ThreadGroup|Thread|Time|TrueClass)\b/,
'constant': /\b[A-Z]\w*(?:[?!]|\b)/
});

Prism.languages.ruby.string = [
{
pattern: /%[qQiIwWxs]?([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1/,
pattern: /%[qQiIwWxs]?([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/,
greedy: true,
inside: {
'interpolation': interpolation
Expand Down Expand Up @@ -115,7 +115,7 @@
}
},
{
pattern: /("|')(#\{[^}]+\}|\\(?:\r?\n|\r)|\\?.)*?\1/,
pattern: /("|')(?:#\{[^}]+\}|\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
greedy: true,
inside: {
'interpolation': interpolation
Expand Down
2 changes: 1 addition & 1 deletion components/prism-ruby.min.js

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

0 comments on commit 4902ed4

Please sign in to comment.