0

Update to 8.0

This commit is contained in:
Rogaboru Kujimoshi
2014-06-08 21:04:39 +04:00
parent 81d0115677
commit a52831ccdb
134 changed files with 10392 additions and 4999 deletions

View File

@@ -1,136 +1,82 @@
/*
Language: Ruby
Author: Anton Kovalyov <anton@kovalyov.net>
Contributors: Peter Leonov <gojpeg@yandex.ru>, Vasily Polovnyov <vast@whiteants.net>, Loren Segal <lsegal@soen.ca>
Contributors: Peter Leonov <gojpeg@yandex.ru>, Vasily Polovnyov <vast@whiteants.net>, Loren Segal <lsegal@soen.ca>, Pascal Hurni <phi@ruby-reactive.org>
*/
hljs.LANGUAGES['ruby'] = function(hljs) {
var RUBY_IDENT_RE = '[a-zA-Z_][a-zA-Z0-9_]*(\\!|\\?)?';
function(hljs) {
var RUBY_METHOD_RE = '[a-zA-Z_]\\w*[!?=]?|[-+~]\\@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?';
var RUBY_KEYWORDS = {
keyword:
'and false then defined module in return redo if BEGIN retry end for true self when ' +
'next until do begin unless END rescue nil else break undef not super class case ' +
'require yield alias while ensure elsif or include'
};
var RUBY_KEYWORDS =
'and false then defined module in return redo if BEGIN retry end for true self when ' +
'next until do begin unless END rescue nil else break undef not super class case ' +
'require yield alias while ensure elsif or include attr_reader attr_writer attr_accessor';
var YARDOCTAG = {
className: 'yardoctag',
begin: '@[A-Za-z]+'
};
var COMMENTS = [
{
className: 'comment',
begin: '#', end: '$',
contains: [YARDOCTAG]
},
{
className: 'comment',
begin: '^\\=begin', end: '^\\=end',
contains: [YARDOCTAG],
relevance: 10
},
{
className: 'comment',
begin: '^__END__', end: '\\n$'
}
];
var IRB_OBJECT = {
className: 'value',
begin: '#<', end: '>'
};
var COMMENT = {
className: 'comment',
variants: [
{
begin: '#', end: '$',
contains: [YARDOCTAG]
},
{
begin: '^\\=begin', end: '^\\=end',
contains: [YARDOCTAG],
relevance: 10
},
{
begin: '^__END__', end: '\\n$'
}
]
};
var SUBST = {
className: 'subst',
begin: '#\\{', end: '}',
lexems: RUBY_IDENT_RE,
keywords: RUBY_KEYWORDS
};
var STR_CONTAINS = [hljs.BACKSLASH_ESCAPE, SUBST];
var STRINGS = [
{
className: 'string',
begin: '\'', end: '\'',
contains: STR_CONTAINS,
relevance: 0
},
{
className: 'string',
begin: '"', end: '"',
contains: STR_CONTAINS,
relevance: 0
},
{
className: 'string',
begin: '%[qw]?\\(', end: '\\)',
contains: STR_CONTAINS
},
{
className: 'string',
begin: '%[qw]?\\[', end: '\\]',
contains: STR_CONTAINS
},
{
className: 'string',
begin: '%[qw]?{', end: '}',
contains: STR_CONTAINS
},
{
className: 'string',
begin: '%[qw]?<', end: '>',
contains: STR_CONTAINS,
relevance: 10
},
{
className: 'string',
begin: '%[qw]?/', end: '/',
contains: STR_CONTAINS,
relevance: 10
},
{
className: 'string',
begin: '%[qw]?%', end: '%',
contains: STR_CONTAINS,
relevance: 10
},
{
className: 'string',
begin: '%[qw]?-', end: '-',
contains: STR_CONTAINS,
relevance: 10
},
{
className: 'string',
begin: '%[qw]?\\|', end: '\\|',
contains: STR_CONTAINS,
relevance: 10
}
];
var FUNCTION = {
className: 'function',
beginWithKeyword: true, end: ' |$|;',
keywords: 'def',
contains: [
var STRING = {
className: 'string',
contains: [hljs.BACKSLASH_ESCAPE, SUBST],
variants: [
{begin: /'/, end: /'/},
{begin: /"/, end: /"/},
{begin: '%[qw]?\\(', end: '\\)'},
{begin: '%[qw]?\\[', end: '\\]'},
{begin: '%[qw]?{', end: '}'},
{begin: '%[qw]?<', end: '>'},
{begin: '%[qw]?/', end: '/'},
{begin: '%[qw]?%', end: '%'},
{begin: '%[qw]?-', end: '-'},
{begin: '%[qw]?\\|', end: '\\|'},
{
className: 'title',
begin: RUBY_METHOD_RE,
lexems: RUBY_IDENT_RE,
keywords: RUBY_KEYWORDS
},
{
className: 'params',
begin: '\\(', end: '\\)',
lexems: RUBY_IDENT_RE,
keywords: RUBY_KEYWORDS
// \B in the beginning suppresses recognition of ?-sequences where ?
// is the last character of a preceding identifier, as in: `func?4`
begin: /\B\?(\\\d{1,3}|\\x[A-Fa-f0-9]{1,2}|\\u[A-Fa-f0-9]{4}|\\?\S)\b/
}
].concat(COMMENTS)
]
};
var PARAMS = {
className: 'params',
begin: '\\(', end: '\\)',
keywords: RUBY_KEYWORDS
};
var RUBY_DEFAULT_CONTAINS = COMMENTS.concat(STRINGS.concat([
var RUBY_DEFAULT_CONTAINS = [
STRING,
IRB_OBJECT,
COMMENT,
{
className: 'class',
beginWithKeyword: true, end: '$|;',
keywords: 'class module',
beginKeywords: 'class module', end: '$|;',
illegal: /=/,
contains: [
{
className: 'title',
begin: '[A-Za-z_]\\w*(::\\w+)*(\\?|\\!)?',
relevance: 0
},
hljs.inherit(hljs.TITLE_MODE, {begin: '[A-Za-z_]\\w*(::\\w+)*(\\?|\\!)?'}),
{
className: 'inheritance',
begin: '<\\s*',
@@ -138,10 +84,20 @@ hljs.LANGUAGES['ruby'] = function(hljs) {
className: 'parent',
begin: '(' + hljs.IDENT_RE + '::)?' + hljs.IDENT_RE
}]
}
].concat(COMMENTS)
},
COMMENT
]
},
{
className: 'function',
beginKeywords: 'def', end: ' |$|;',
relevance: 0,
contains: [
hljs.inherit(hljs.TITLE_MODE, {begin: RUBY_METHOD_RE}),
PARAMS,
COMMENT
]
},
FUNCTION,
{
className: 'constant',
begin: '(::)?(\\b[A-Z]\\w*(::)?)+',
@@ -150,7 +106,12 @@ hljs.LANGUAGES['ruby'] = function(hljs) {
{
className: 'symbol',
begin: ':',
contains: STRINGS.concat([{begin: RUBY_IDENT_RE}]),
contains: [STRING, {begin: RUBY_METHOD_RE}],
relevance: 0
},
{
className: 'symbol',
begin: hljs.UNDERSCORE_IDENT_RE + '(\\!|\\?)?:',
relevance: 0
},
{
@@ -158,35 +119,72 @@ hljs.LANGUAGES['ruby'] = function(hljs) {
begin: '(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b',
relevance: 0
},
{
className: 'number',
begin: '\\?\\w'
},
{
className: 'variable',
begin: '(\\$\\W)|((\\$|\\@\\@?)(\\w+))'
},
{ // regexp container
begin: '(' + hljs.RE_STARTERS_RE + ')\\s*',
contains: COMMENTS.concat([
contains: [
IRB_OBJECT,
COMMENT,
{
className: 'regexp',
begin: '/', end: '/[a-z]*',
illegal: '\\n',
contains: [hljs.BACKSLASH_ESCAPE]
contains: [hljs.BACKSLASH_ESCAPE, SUBST],
illegal: /\n/,
variants: [
{begin: '/', end: '/[a-z]*'},
{begin: '%r{', end: '}[a-z]*'},
{begin: '%r\\(', end: '\\)[a-z]*'},
{begin: '%r!', end: '![a-z]*'},
{begin: '%r\\[', end: '\\][a-z]*'}
]
}
]),
],
relevance: 0
}
]));
];
SUBST.contains = RUBY_DEFAULT_CONTAINS;
FUNCTION.contains[1].contains = RUBY_DEFAULT_CONTAINS;
PARAMS.contains = RUBY_DEFAULT_CONTAINS;
var IRB_DEFAULT = [
{
relevance: 1,
className: 'output',
begin: '^\\s*=> ', end: "$",
returnBegin: true,
contains: [
{
className: 'status',
begin: '^\\s*=>'
},
{
begin: ' ', end: '$',
contains: RUBY_DEFAULT_CONTAINS
}
]
},
{
relevance: 1,
className: 'input',
begin: '^[^ ][^=>]*>+ ', end: "$",
returnBegin: true,
contains: [
{
className: 'prompt',
begin: '^[^ ][^=>]*>+'
},
{
begin: ' ', end: '$',
contains: RUBY_DEFAULT_CONTAINS
}
]
}
];
return {
defaultMode: {
lexems: RUBY_IDENT_RE,
keywords: RUBY_KEYWORDS,
contains: RUBY_DEFAULT_CONTAINS
}
aliases: ['rb', 'gemspec', 'podspec', 'thor', 'irb'],
keywords: RUBY_KEYWORDS,
contains: IRB_DEFAULT.concat(RUBY_DEFAULT_CONTAINS)
};
}(hljs);
}