OLD | NEW |
1 /** | 1 /** |
2 * Original by Samuel Flores | 2 * Original by Samuel Flores |
3 * | 3 * |
4 * Adds the following new token classes: | 4 * Adds the following new token classes: |
5 * constant, builtin, variable, symbol, regex | 5 * constant, builtin, variable, symbol, regex |
6 */ | 6 */ |
7 Prism.languages.ruby = Prism.languages.extend('clike', { | 7 (function(Prism) { |
8 » 'comment': /#(?!\{[^\r\n]*?\})[^\r\n]*(\r?\n|$)/, | 8 » Prism.languages.ruby = Prism.languages.extend('clike', { |
9 » '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|no
t|or|raise|redo|require|rescue|retry|return|self|super|then|throw|true|undef|unl
ess|until|when|while|yield)\b/, | 9 » » 'comment': /#(?!\{[^\r\n]*?\}).*/, |
10 » 'builtin': /\b(Array|Bignum|Binding|Class|Continuation|Dir|Exception|Fal
seClass|File|Stat|File|Fixnum|Fload|Hash|Integer|IO|MatchData|Method|Module|NilC
lass|Numeric|Object|Proc|Range|Regexp|String|Struct|TMS|Symbol|ThreadGroup|Threa
d|Time|TrueClass)\b/, | 10 » » '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|nex
t|nil|not|or|raise|redo|require|rescue|retry|return|self|super|then|throw|true|u
ndef|unless|until|when|while|yield)\b/ |
11 » 'constant': /\b[A-Z][a-zA-Z_0-9]*[?!]?\b/ | 11 » }); |
12 }); | |
13 | 12 |
14 Prism.languages.insertBefore('ruby', 'keyword', { | 13 » var interpolation = { |
15 » 'regex': { | 14 » » pattern: /#\{[^}]+\}/, |
16 » » pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\
s*($|[\r\n,.;})]))/, | 15 » » inside: { |
17 » » lookbehind: true | 16 » » » 'delimiter': { |
18 » }, | 17 » » » » pattern: /^#\{|\}$/, |
19 » 'variable': /[@$]+\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/, | 18 » » » » alias: 'tag' |
20 » 'symbol': /:\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/ | 19 » » » }, |
21 }); | 20 » » » rest: Prism.util.clone(Prism.languages.ruby) |
| 21 » » } |
| 22 » }; |
22 | 23 |
23 Prism.languages.ruby.string = { | 24 » Prism.languages.insertBefore('ruby', 'keyword', { |
24 » pattern: /("|')(#\{[^}]+\}|\\\n|\\?.)*?\1/, | 25 » » 'regex': [ |
25 » inside: { | 26 » » » { |
26 » » 'interpolation': { | 27 » » » » pattern: /%r([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\
s\S])*?\1[gim]{0,3}/, |
27 » » » pattern: /#\{[^}]+\}/, | 28 » » » » inside: { |
| 29 » » » » » 'interpolation': interpolation |
| 30 » » » » } |
| 31 » » » }, |
| 32 » » » { |
| 33 » » » » pattern: /%r\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/
, |
| 34 » » » » inside: { |
| 35 » » » » » 'interpolation': interpolation |
| 36 » » » » } |
| 37 » » » }, |
| 38 » » » { |
| 39 » » » » // Here we need to specifically allow interpolat
ion |
| 40 » » » » pattern: /%r\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\
S])*\}[gim]{0,3}/, |
| 41 » » » » inside: { |
| 42 » » » » » 'interpolation': interpolation |
| 43 » » » » } |
| 44 » » » }, |
| 45 » » » { |
| 46 » » » » pattern: /%r\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3
}/, |
| 47 » » » » inside: { |
| 48 » » » » » 'interpolation': interpolation |
| 49 » » » » } |
| 50 » » » }, |
| 51 » » » { |
| 52 » » » » pattern: /%r<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/, |
| 53 » » » » inside: { |
| 54 » » » » » 'interpolation': interpolation |
| 55 » » » » } |
| 56 » » » }, |
| 57 » » » { |
| 58 » » » » pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+
\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/, |
| 59 » » » » lookbehind: true |
| 60 » » » } |
| 61 » » ], |
| 62 » » 'variable': /[@$]+[a-zA-Z_][a-zA-Z_0-9]*(?:[?!]|\b)/, |
| 63 » » 'symbol': /:[a-zA-Z_][a-zA-Z_0-9]*(?:[?!]|\b)/ |
| 64 » }); |
| 65 |
| 66 » Prism.languages.insertBefore('ruby', 'number', { |
| 67 » » 'builtin': /\b(Array|Bignum|Binding|Class|Continuation|Dir|Excep
tion|FalseClass|File|Stat|File|Fixnum|Fload|Hash|Integer|IO|MatchData|Method|Mod
ule|NilClass|Numeric|Object|Proc|Range|Regexp|String|Struct|TMS|Symbol|ThreadGro
up|Thread|Time|TrueClass)\b/, |
| 68 » » 'constant': /\b[A-Z][a-zA-Z_0-9]*(?:[?!]|\b)/ |
| 69 » }); |
| 70 |
| 71 » Prism.languages.ruby.string = [ |
| 72 » » { |
| 73 » » » pattern: /%[qQiIwWxs]?([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\
[\s\S])*?\1/, |
28 inside: { | 74 inside: { |
29 » » » » 'delimiter': { | 75 » » » » 'interpolation': interpolation |
30 » » » » » pattern: /^#\{|\}$/, | 76 » » » } |
31 » » » » » alias: 'tag' | 77 » » }, |
32 » » » » }, | 78 » » { |
33 » » » » rest: Prism.util.clone(Prism.languages.ruby) | 79 » » » pattern: /%[qQiIwWxs]?\((?:[^()\\]|\\[\s\S])*\)/, |
| 80 » » » inside: { |
| 81 » » » » 'interpolation': interpolation |
| 82 » » » } |
| 83 » » }, |
| 84 » » { |
| 85 » » » // Here we need to specifically allow interpolation |
| 86 » » » pattern: /%[qQiIwWxs]?\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\
s\S])*\}/, |
| 87 » » » inside: { |
| 88 » » » » 'interpolation': interpolation |
| 89 » » » } |
| 90 » » }, |
| 91 » » { |
| 92 » » » pattern: /%[qQiIwWxs]?\[(?:[^\[\]\\]|\\[\s\S])*\]/, |
| 93 » » » inside: { |
| 94 » » » » 'interpolation': interpolation |
| 95 » » » } |
| 96 » » }, |
| 97 » » { |
| 98 » » » pattern: /%[qQiIwWxs]?<(?:[^<>\\]|\\[\s\S])*>/, |
| 99 » » » inside: { |
| 100 » » » » 'interpolation': interpolation |
| 101 » » » } |
| 102 » » }, |
| 103 » » { |
| 104 » » » pattern: /("|')(#\{[^}]+\}|\\(?:\r?\n|\r)|\\?.)*?\1/, |
| 105 » » » inside: { |
| 106 » » » » 'interpolation': interpolation |
34 } | 107 } |
35 } | 108 } |
36 » } | 109 » ]; |
37 }; | 110 }(Prism)); |
OLD | NEW |