summaryrefslogtreecommitdiff
path: root/js/jquery.syntax.brush.ruby.js
blob: 5d37ed1c6965a0a18c45dcd41f5a98becc829488 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// brush: "ruby" aliases: []

//	This file is part of the "jQuery.Syntax" project, and is distributed under the MIT License.
//	Copyright (c) 2011 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
//	See <jquery.syntax.js> for licensing details.

Syntax.lib.rubyStyleFunction = {pattern: /(?:def\s+|\.)([a-z_][a-z0-9_]+)/gi, matches: Syntax.extractMatches({klass: 'function'})};

// We need to emulate negative lookbehind
Syntax.lib.rubyStyleSymbol = {pattern: /([:]?):\w+/g, klass: 'constant', matches: function (match, expr) {
	if (match[1] != '') return [];
	
	return [new Syntax.Match(match.index, match[0].length, expr, match[0])];
}};

Syntax.register('ruby', function(brush) {
	var keywords = ["alias", "and", "begin", "break", "case", "class", "def", "define_method", "defined?", "do", "else", "elsif", "end", "ensure", "false", "for", "if", "in", "module", "next", "not", "or", "raise", "redo", "rescue", "retry", "return", "then", "throw", "undef", "unless", "until", "when", "while", "yield", "block_given?"];
	
	var operators = ["+", "*", "/", "-", "&", "|", "~", "!", "%", "<", "=", ">"];
	var values = ["self", "super", "true", "false", "nil"];
	
	var access = ["private", "protected", "public"];
	
	brush.push(access, {klass: 'access'});
	brush.push(values, {klass: 'constant'});

	// Percent operator statements
	brush.push({
		pattern: /(\%[\S])(\{[\s\S]*?\})/g,
		matches: Syntax.extractMatches({klass: 'function'}, {klass: 'constant'})
	});
	
	brush.push({
		pattern: /`[^`]+`/g,
		klass: 'string'
	});
	
	brush.push({
		pattern: /\#\{([^\}]*)\}/g,
		matches: Syntax.extractMatches({
			brush: 'ruby',
			only: ['string']
		}),
	});
	
	// Regular expressions
	brush.push(Syntax.lib.perlStyleRegularExpression);
	
	brush.push({pattern: /(@+|\$)[\w]+/g, klass: 'variable'});
	
	brush.push(Syntax.lib.camelCaseType);
	brush.push(keywords, {klass: 'keyword'});
	brush.push(operators, {klass: 'operator'});
	
	brush.push(Syntax.lib.rubyStyleSymbol);
	
	// Comments
	brush.push(Syntax.lib.perlStyleComment);
	brush.push(Syntax.lib.webLink);
	
	// Strings
	brush.push(Syntax.lib.singleQuotedString);
	brush.push(Syntax.lib.doubleQuotedString);
	brush.push(Syntax.lib.stringEscape);
	
	// Numbers
	brush.push(Syntax.lib.decimalNumber);
	brush.push(Syntax.lib.hexNumber);
	
	// Functions
	brush.push(Syntax.lib.rubyStyleFunction);
	brush.push(Syntax.lib.cStyleFunction);
	
	// brush.processes['function'] = Syntax.lib.webLinkProcess("ruby", true);
	// brush.processes['type'] = Syntax.lib.webLinkProcess("ruby", true);
});