Skip to content

Commit

Permalink
Ruby: Added missing regex flags (#2845)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Apr 3, 2021
1 parent 48ab42b commit 3786f39
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
14 changes: 7 additions & 7 deletions components/prism-ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@
'regex': [
{
pattern: RegExp(/%r/.source + '(?:' + [
/([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1[gim]{0,3}/.source,
/\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/.source,
/([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
/\((?:[^()\\]|\\[\s\S])*\)/.source,
// Here we need to specifically allow interpolation
/\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/.source,
/\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/.source,
/<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/.source
].join('|') + ')'),
/\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/.source,
/\[(?:[^\[\]\\]|\\[\s\S])*\]/.source,
/<(?:[^<>\\]|\\[\s\S])*>/.source
].join('|') + ')' + /[egimnosux]{0,6}/.source),
greedy: true,
inside: {
'interpolation': interpolation
}
},
{
pattern: /(^|[^/])\/(?!\/)(?:\[[^\r\n\]]+\]|\\.|[^[/\\\r\n])+\/[gim]{0,3}(?=\s*(?:$|[\r\n,.;})#]))/,
pattern: /(^|[^/])\/(?!\/)(?:\[[^\r\n\]]+\]|\\.|[^[/\\\r\n])+\/[egimnosux]{0,6}(?=\s*(?:$|[\r\n,.;})#]))/,
lookbehind: true,
greedy: true,
inside: {
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.

27 changes: 26 additions & 1 deletion tests/languages/ruby/regex_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/[bar]/,
/./i;
/foo#{bar}/;
/ab+c/ix
%r!foo?bar#{39+3}!
%r(foo?bar#{39+3})
%r{foo?bar#{39+3}}
Expand All @@ -11,6 +12,17 @@
/foo/ # comment
/foo#{bar}/ # comment

# flags
/abc/e
/abc/g
/abc/i
/abc/m
/abc/n
/abc/o
/abc/s
/abc/u
/abc/x

----------------------------------------------------

[
Expand All @@ -33,6 +45,8 @@
]],
["punctuation", ";"],

["regex", ["/ab+c/ix"]],

["regex", [
"%r!foo?bar",
["interpolation", [
Expand Down Expand Up @@ -105,7 +119,18 @@
]],
"/"
]],
["comment", "# comment"]
["comment", "# comment"],

["comment", "# flags"],
["regex", ["/abc/e"]],
["regex", ["/abc/g"]],
["regex", ["/abc/i"]],
["regex", ["/abc/m"]],
["regex", ["/abc/n"]],
["regex", ["/abc/o"]],
["regex", ["/abc/s"]],
["regex", ["/abc/u"]],
["regex", ["/abc/x"]]
]

----------------------------------------------------
Expand Down

0 comments on commit 3786f39

Please sign in to comment.