Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Unified Diff: lib/src/prism/components/prism-ruby.js

Issue 1418513006: update elements and fix some bugs (Closed) Base URL: git@github.com:dart-lang/polymer_elements.git@master
Patch Set: code review updates Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/prism/components/prism-rip.min.js ('k') | lib/src/prism/components/prism-ruby.min.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/prism/components/prism-ruby.js
diff --git a/lib/src/prism/components/prism-ruby.js b/lib/src/prism/components/prism-ruby.js
index 030eefe9f769088979b5bf6e8c90dc8ded591593..10e8b5002dafec2e12b807bf030630a3374f21c4 100644
--- a/lib/src/prism/components/prism-ruby.js
+++ b/lib/src/prism/components/prism-ruby.js
@@ -4,34 +4,107 @@
* Adds the following new token classes:
* constant, builtin, variable, symbol, regex
*/
-Prism.languages.ruby = Prism.languages.extend('clike', {
- 'comment': /#(?!\{[^\r\n]*?\})[^\r\n]*(\r?\n|$)/,
- '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/,
- 'builtin': /\b(Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Stat|File|Fixnum|Fload|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/
-});
+(function(Prism) {
+ Prism.languages.ruby = Prism.languages.extend('clike', {
+ 'comment': /#(?!\{[^\r\n]*?\}).*/,
+ '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/
+ });
-Prism.languages.insertBefore('ruby', 'keyword', {
- 'regex': {
- pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,
- lookbehind: true
- },
- 'variable': /[@$]+\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/,
- 'symbol': /:\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/
-});
+ var interpolation = {
+ pattern: /#\{[^}]+\}/,
+ inside: {
+ 'delimiter': {
+ pattern: /^#\{|\}$/,
+ alias: 'tag'
+ },
+ rest: Prism.util.clone(Prism.languages.ruby)
+ }
+ };
+
+ Prism.languages.insertBefore('ruby', 'keyword', {
+ 'regex': [
+ {
+ pattern: /%r([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1[gim]{0,3}/,
+ inside: {
+ 'interpolation': interpolation
+ }
+ },
+ {
+ pattern: /%r\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/,
+ inside: {
+ 'interpolation': interpolation
+ }
+ },
+ {
+ // Here we need to specifically allow interpolation
+ pattern: /%r\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/,
+ inside: {
+ 'interpolation': interpolation
+ }
+ },
+ {
+ pattern: /%r\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/,
+ inside: {
+ 'interpolation': interpolation
+ }
+ },
+ {
+ pattern: /%r<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/,
+ inside: {
+ 'interpolation': interpolation
+ }
+ },
+ {
+ pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,
+ lookbehind: true
+ }
+ ],
+ 'variable': /[@$]+[a-zA-Z_][a-zA-Z_0-9]*(?:[?!]|\b)/,
+ 'symbol': /:[a-zA-Z_][a-zA-Z_0-9]*(?:[?!]|\b)/
+ });
+
+ Prism.languages.insertBefore('ruby', 'number', {
+ 'builtin': /\b(Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Stat|File|Fixnum|Fload|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)/
+ });
-Prism.languages.ruby.string = {
- pattern: /("|')(#\{[^}]+\}|\\\n|\\?.)*?\1/,
- inside: {
- 'interpolation': {
- pattern: /#\{[^}]+\}/,
+ Prism.languages.ruby.string = [
+ {
+ pattern: /%[qQiIwWxs]?([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1/,
+ inside: {
+ 'interpolation': interpolation
+ }
+ },
+ {
+ pattern: /%[qQiIwWxs]?\((?:[^()\\]|\\[\s\S])*\)/,
+ inside: {
+ 'interpolation': interpolation
+ }
+ },
+ {
+ // Here we need to specifically allow interpolation
+ pattern: /%[qQiIwWxs]?\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/,
+ inside: {
+ 'interpolation': interpolation
+ }
+ },
+ {
+ pattern: /%[qQiIwWxs]?\[(?:[^\[\]\\]|\\[\s\S])*\]/,
+ inside: {
+ 'interpolation': interpolation
+ }
+ },
+ {
+ pattern: /%[qQiIwWxs]?<(?:[^<>\\]|\\[\s\S])*>/,
+ inside: {
+ 'interpolation': interpolation
+ }
+ },
+ {
+ pattern: /("|')(#\{[^}]+\}|\\(?:\r?\n|\r)|\\?.)*?\1/,
inside: {
- 'delimiter': {
- pattern: /^#\{|\}$/,
- alias: 'tag'
- },
- rest: Prism.util.clone(Prism.languages.ruby)
+ 'interpolation': interpolation
}
}
- }
-};
+ ];
+}(Prism));
« no previous file with comments | « lib/src/prism/components/prism-rip.min.js ('k') | lib/src/prism/components/prism-ruby.min.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698