rouge 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rouge.rb +8 -0
- data/lib/rouge/cli.rb +6 -2
- data/lib/rouge/formatter.rb +13 -0
- data/lib/rouge/formatters/html.rb +2 -0
- data/lib/rouge/formatters/terminal256.rb +152 -0
- data/lib/rouge/lexer.rb +31 -49
- data/lib/rouge/lexers/erb.rb +54 -0
- data/lib/rouge/lexers/haskell.rb +7 -0
- data/lib/rouge/lexers/html.rb +20 -2
- data/lib/rouge/lexers/make.rb +105 -0
- data/lib/rouge/lexers/perl.rb +196 -0
- data/lib/rouge/lexers/php.rb +145 -0
- data/lib/rouge/lexers/php/builtins.rb +196 -0
- data/lib/rouge/lexers/ruby.rb +25 -10
- data/lib/rouge/lexers/scheme.rb +2 -2
- data/lib/rouge/lexers/shell.rb +16 -2
- data/lib/rouge/lexers/tex.rb +71 -0
- data/lib/rouge/theme.rb +21 -2
- data/lib/rouge/themes/colorful.rb +1 -1
- data/lib/rouge/themes/thankful_eyes.rb +4 -3
- data/lib/rouge/version.rb +1 -1
- metadata +9 -2
data/lib/rouge/lexers/haskell.rb
CHANGED
@@ -38,6 +38,13 @@ module Rouge
|
|
38
38
|
rule /[-{}]/, 'Comment.Multiline'
|
39
39
|
end
|
40
40
|
|
41
|
+
state :comment_preproc do
|
42
|
+
rule /-}/, 'Comment.Preproc', :pop!
|
43
|
+
rule /{-/, 'Comment.Preproc', :comment
|
44
|
+
rule /[^-{}]+/, 'Comment.Preproc'
|
45
|
+
rule /[-{}]/, 'Comment.Preproc'
|
46
|
+
end
|
47
|
+
|
41
48
|
state :root do
|
42
49
|
mixin :basic
|
43
50
|
|
data/lib/rouge/lexers/html.rb
CHANGED
@@ -48,11 +48,29 @@ module Rouge
|
|
48
48
|
|
49
49
|
state :attr do
|
50
50
|
# TODO: are backslash escapes valid here?
|
51
|
-
rule /"
|
52
|
-
|
51
|
+
rule /"/ do
|
52
|
+
token 'Literal.String'
|
53
|
+
pop!; push :dq
|
54
|
+
end
|
55
|
+
|
56
|
+
rule /'/ do
|
57
|
+
token 'Literal.String'
|
58
|
+
pop!; push :sq
|
59
|
+
end
|
60
|
+
|
53
61
|
rule /[^\s>]+/, 'Literal.String', :pop!
|
54
62
|
end
|
55
63
|
|
64
|
+
state :dq do
|
65
|
+
rule /"/, 'Literal.String', :pop!
|
66
|
+
rule /[^"]+/, 'Literal.String'
|
67
|
+
end
|
68
|
+
|
69
|
+
state :sq do
|
70
|
+
rule /'/, 'Literal.String', :pop!
|
71
|
+
rule /[^']+/, 'Literal.String'
|
72
|
+
end
|
73
|
+
|
56
74
|
state :script_content do
|
57
75
|
rule %r(<\s*/\s*script\s*>)m, 'Name.Tag', :pop!
|
58
76
|
rule %r(.*?(?=<\s*/\s*script\s*>))m do
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module Rouge
|
2
|
+
module Lexers
|
3
|
+
class Make < RegexLexer
|
4
|
+
tag 'make'
|
5
|
+
aliases 'makefile', 'mf', 'gnumake', 'bsdmake'
|
6
|
+
filenames '*.make', 'Makefile', 'makefile', 'Makefile.*', 'GNUmakefile'
|
7
|
+
mimetypes 'text/x-makefile'
|
8
|
+
|
9
|
+
def self.analyze_text(text)
|
10
|
+
return 0.2 if text =~ /^\.PHONY:/
|
11
|
+
end
|
12
|
+
|
13
|
+
bsd_special = %w(
|
14
|
+
include undef error warning if else elif endif for endfor
|
15
|
+
)
|
16
|
+
|
17
|
+
gnu_special = %w(
|
18
|
+
ifeq ifneq ifdef ifndef else endif include -include define endef :
|
19
|
+
)
|
20
|
+
|
21
|
+
line = /(?:\\.|\\\n|[^\\\n])*/m
|
22
|
+
|
23
|
+
attr_reader :shell
|
24
|
+
def initialize(opts={})
|
25
|
+
super
|
26
|
+
@shell = Shell.new(opts)
|
27
|
+
end
|
28
|
+
|
29
|
+
state :root do
|
30
|
+
rule /^(?:[\t ]+.*\n|\n)+/ do
|
31
|
+
delegate lexer.shell
|
32
|
+
end
|
33
|
+
|
34
|
+
# rule /\$\((?:.*\\\n|.*\n)+/ do
|
35
|
+
# delegate Shell
|
36
|
+
# end
|
37
|
+
|
38
|
+
rule /\s+/, 'Text'
|
39
|
+
|
40
|
+
rule /#.*?\n/, 'Comment'
|
41
|
+
|
42
|
+
rule /(export)(\s+)(?=[a-zA-Z0-9_\${}\t -]+\n)/ do
|
43
|
+
group 'Keyword'; group 'Text'
|
44
|
+
push :export
|
45
|
+
end
|
46
|
+
|
47
|
+
rule /export\s+/, 'Keyword'
|
48
|
+
|
49
|
+
# assignment
|
50
|
+
rule /([a-zA-Z0-9_${}.-]+)(\s*)([!?:+]?=)/m do |m|
|
51
|
+
token 'Name.Variable', m[1]
|
52
|
+
token 'Text', m[2]
|
53
|
+
token 'Operator', m[3]
|
54
|
+
push :shell_line
|
55
|
+
end
|
56
|
+
|
57
|
+
rule /"(\\\\|\\.|[^"\\])*"/, 'Literal.String.Double'
|
58
|
+
rule /'(\\\\|\\.|[^'\\])*'/, 'Literal.String.Single'
|
59
|
+
rule /([^\n:]+)(:+)([ \t]*)/ do
|
60
|
+
group 'Name.Label'; group 'Operator'; group 'Text'
|
61
|
+
push :block_header
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
state :export do
|
66
|
+
rule /[\w\${}-]/, 'Name.Variable'
|
67
|
+
rule /\n/, 'Text', :pop!
|
68
|
+
rule /\s+/, 'Text'
|
69
|
+
end
|
70
|
+
|
71
|
+
state :block_header do
|
72
|
+
rule /[^,\\\n#]+/, 'Name.Function'
|
73
|
+
rule /,/, 'Punctuation'
|
74
|
+
rule /#.*?/, 'Comment'
|
75
|
+
rule /\\\n/, 'Text'
|
76
|
+
rule /\\./, 'Text'
|
77
|
+
rule /\n/ do
|
78
|
+
token 'Text'
|
79
|
+
pop!; push :block_body
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
state :block_body do
|
84
|
+
rule /(\t[\t ]*)([@-]?)/ do |m|
|
85
|
+
group 'Text'; group 'Punctuation'
|
86
|
+
push :shell_line
|
87
|
+
end
|
88
|
+
|
89
|
+
rule(//) { lexer.shell.reset!; pop! }
|
90
|
+
end
|
91
|
+
|
92
|
+
state :shell do
|
93
|
+
# macro interpolation
|
94
|
+
rule /\$\(\s*[a-z_]\w*\s*\)/i, 'Name.Variable'
|
95
|
+
rule(/.+?(?=\$\(|\)|\n)/m) { delegate lexer.shell }
|
96
|
+
rule(/\$\(|\)|\n/) { delegate lexer.shell }
|
97
|
+
end
|
98
|
+
|
99
|
+
state :shell_line do
|
100
|
+
rule /\n/, 'Text', :pop!
|
101
|
+
mixin :shell
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,196 @@
|
|
1
|
+
module Rouge
|
2
|
+
module Lexers
|
3
|
+
class Perl < RegexLexer
|
4
|
+
tag 'perl'
|
5
|
+
aliases 'pl'
|
6
|
+
|
7
|
+
filenames '*.pl', '*.pm'
|
8
|
+
mimetypes 'text/x-perl', 'application/x-perl'
|
9
|
+
|
10
|
+
def self.analyze_text(text)
|
11
|
+
return 1 if text.shebang? 'perl'
|
12
|
+
return 0.9 if text.include? 'my $'
|
13
|
+
end
|
14
|
+
|
15
|
+
keywords = %w(
|
16
|
+
case continue do else elsif for foreach if last my next our
|
17
|
+
redo reset then unless until while use print new BEGIN CHECK
|
18
|
+
INIT END return
|
19
|
+
)
|
20
|
+
|
21
|
+
builtins = %w(
|
22
|
+
abs accept alarm atan2 bind binmode bless caller chdir chmod
|
23
|
+
chomp chop chown chr chroot close closedir connect continue cos
|
24
|
+
crypt dbmclose dbmopen defined delete die dump each endgrent
|
25
|
+
endhostent endnetent endprotoent endpwent endservent eof eval
|
26
|
+
exec exists exit exp fcntl fileno flock fork format formline getc
|
27
|
+
getgrent getgrgid getgrnam gethostbyaddr gethostbyname gethostent
|
28
|
+
getlogin getnetbyaddr getnetbyname getnetent getpeername
|
29
|
+
getpgrp getppid getpriority getprotobyname getprotobynumber
|
30
|
+
getprotoent getpwent getpwnam getpwuid getservbyname getservbyport
|
31
|
+
getservent getsockname getsockopt glob gmtime goto grep hex
|
32
|
+
import index int ioctl join keys kill last lc lcfirst length
|
33
|
+
link listen local localtime log lstat map mkdir msgctl msgget
|
34
|
+
msgrcv msgsnd my next no oct open opendir ord our pack package
|
35
|
+
pipe pop pos printf prototype push quotemeta rand read readdir
|
36
|
+
readline readlink readpipe recv redo ref rename require reverse
|
37
|
+
rewinddir rindex rmdir scalar seek seekdir select semctl semget
|
38
|
+
semop send setgrent sethostent setnetent setpgrp setpriority
|
39
|
+
setprotoent setpwent setservent setsockopt shift shmctl shmget
|
40
|
+
shmread shmwrite shutdown sin sleep socket socketpair sort splice
|
41
|
+
split sprintf sqrt srand stat study substr symlink syscall sysopen
|
42
|
+
sysread sysseek system syswrite tell telldir tie tied time times
|
43
|
+
tr truncate uc ucfirst umask undef unlink unpack unshift untie
|
44
|
+
utime values vec wait waitpid wantarray warn write
|
45
|
+
)
|
46
|
+
|
47
|
+
re_tok = 'Literal.String.Regex'
|
48
|
+
|
49
|
+
state :balanced_regex do
|
50
|
+
rule %r(/(\\\\|\\/|[^/])*/[egimosx]*)m, re_tok, :pop!
|
51
|
+
rule %r(!(\\\\|\\!|[^!])*![egimosx]*)m, re_tok, :pop!
|
52
|
+
rule %r(\\(\\\\|[^\\])*\\[egimosx]*)m, re_tok, :pop!
|
53
|
+
rule %r({(\\\\|\\}|[^}])*}[egimosx]*), re_tok, :pop!
|
54
|
+
rule %r(<(\\\\|\\>|[^>])*>[egimosx]*), re_tok, :pop!
|
55
|
+
rule %r(\[(\\\\|\\\]|[^\]])*\][egimosx]*), re_tok, :pop!
|
56
|
+
rule %r(\((\\\\|\\\)|[^\)])*\)[egimosx]*), re_tok, :pop!
|
57
|
+
rule %r(@(\\\\|\\\@|[^\@])*@[egimosx]*), re_tok, :pop!
|
58
|
+
rule %r(%(\\\\|\\\%|[^\%])*%[egimosx]*), re_tok, :pop!
|
59
|
+
rule %r(\$(\\\\|\\\$|[^\$])*\$[egimosx]*), re_tok, :pop!
|
60
|
+
end
|
61
|
+
|
62
|
+
state :root do
|
63
|
+
rule /#.*?$/, 'Comment.Single'
|
64
|
+
rule /^=[a-zA-Z0-9]+\s+.*?\n=cut/, 'Comment.Multiline'
|
65
|
+
rule /(?:#{keywords.join('|')})\b/, 'Keyword'
|
66
|
+
|
67
|
+
rule /(format)(\s+)([a-zA-Z0-9_]+)(\s*)(=)(\s*\n)/ do
|
68
|
+
group 'Keyword'; group 'Text'
|
69
|
+
group 'Name'; group 'Text'
|
70
|
+
group 'Punctuation'; group 'Text'
|
71
|
+
|
72
|
+
push :format
|
73
|
+
end
|
74
|
+
|
75
|
+
rule /(?:eq|lt|gt|le|ge|ne|not|and|or|cmp)\b/, 'Operator.Word'
|
76
|
+
|
77
|
+
# common delimiters
|
78
|
+
rule %r(s/(\\\\|\\/|[^/])*/(\\\\|\\/|[^/])*/[egimosx]*), re_tok
|
79
|
+
rule %r(s!(\\\\|\\!|[^!])*!(\\\\|\\!|[^!])*![egimosx]*), re_tok
|
80
|
+
rule %r(s\\(\\\\|[^\\])*\\(\\\\|[^\\])*\\[egimosx]*), re_tok
|
81
|
+
rule %r(s@(\\\\|\\@|[^@])*@(\\\\|\\@|[^@])*@[egimosx]*), re_tok
|
82
|
+
rule %r(s%(\\\\|\\%|[^%])*%(\\\\|\\%|[^%])*%[egimosx]*), re_tok
|
83
|
+
|
84
|
+
# balanced delimiters
|
85
|
+
rule %r(s{(\\\\|\\}|[^}])*}\s*), re_tok, :balanced_regex
|
86
|
+
rule %r(s<(\\\\|\\>|[^>])*>\s*), re_tok, :balanced_regex
|
87
|
+
rule %r(s\[(\\\\|\\\]|[^\]])*\]\s*), re_tok, :balanced_regex
|
88
|
+
rule %r(s\((\\\\|\\\)|[^\)])*\)\s*), re_tok, :balanced_regex
|
89
|
+
|
90
|
+
rule %r(m?/(\\\\|\\/|[^/\n])*/[gcimosx]*), re_tok
|
91
|
+
rule %r(m(?=[/!\\{<\[\(@%\$])), re_tok, :balanced_regex
|
92
|
+
rule %r(((?<==~)|(?<=\())\s*/(\\\\|\\/|[^/])*/[gcimosx]*),
|
93
|
+
re_tok, :balanced_regex
|
94
|
+
|
95
|
+
rule /\s+/, 'Text'
|
96
|
+
rule /(?:#{builtins.join('|')})\b/, 'Name.Builtin'
|
97
|
+
rule /((__(DATA|DIE|WARN)__)|(STD(IN|OUT|ERR)))\b/,
|
98
|
+
'Name.Builtin.Pseudo'
|
99
|
+
|
100
|
+
rule /<<([\'"]?)([a-zA-Z_][a-zA-Z0-9_]*)\1;?\n.*?\n\2\n/m,
|
101
|
+
'Literal.String'
|
102
|
+
|
103
|
+
rule /__END__\b/, 'Comment.Preproc', :end_part
|
104
|
+
rule /\$\^[ADEFHILMOPSTWX]/, 'Name.Variable.Global'
|
105
|
+
rule /\$[\\"\[\]'&`+*.,;=%~?@$!<>(^\|\/-](?!\w)/, 'Name.Variable.Global'
|
106
|
+
rule /[$@%#]+/, 'Name.Variable', :varname
|
107
|
+
|
108
|
+
rule /0_?[0-7]+(_[0-7]+)*/, 'Literal.Number.Oct'
|
109
|
+
rule /0x[0-9A-Fa-f]+(_[0-9A-Fa-f]+)*/, 'Literal.Number.Hex'
|
110
|
+
rule /0b[01]+(_[01]+)*/, 'Literal.Number.Bin'
|
111
|
+
rule /(\d*(_\d*)*\.\d+(_\d*)*|\d+(_\d*)*\.\d+(_\d*)*)(e[+-]?\d+)?/i,
|
112
|
+
'Literal.Number.Float'
|
113
|
+
rule /\d+(_\d*)*e[+-]?\d+(_\d*)*/i, 'Literal.Number.Float'
|
114
|
+
rule /\d+(_\d+)*/, 'Literal.Number.Integer'
|
115
|
+
|
116
|
+
rule /'(\\\\|\\'|[^'])*'/, 'Literal.String'
|
117
|
+
rule /"(\\\\|\\"|[^"])*"/, 'Literal.String'
|
118
|
+
rule /`(\\\\|\\`|[^`])*`/, 'Literal.String.Backtick'
|
119
|
+
rule /<([^\s>]+)>/, re_tok
|
120
|
+
rule /(q|qq|qw|qr|qx)\{/, 'Literal.String.Other', :cb_string
|
121
|
+
rule /(q|qq|qw|qr|qx)\(/, 'Literal.String.Other', :rb_string
|
122
|
+
rule /(q|qq|qw|qr|qx)\[/, 'Literal.String.Other', :sb_string
|
123
|
+
rule /(q|qq|qw|qr|qx)</, 'Literal.String.Other', :lt_string
|
124
|
+
rule /(q|qq|qw|qr|qx)([^a-zA-Z0-9])(.|\n)*?\2/, 'Literal.String.Other'
|
125
|
+
|
126
|
+
rule /package\s+/, 'Keyword', :modulename
|
127
|
+
rule /sub\s+/, 'Keyword', :funcname
|
128
|
+
rule /\[\]|\*\*|::|<<|>>|>=|<=|<=>|={3}|!=|=~|!~|&&?|\|\||\.{1,3}/,
|
129
|
+
'Operator'
|
130
|
+
rule /[-+\/*%=<>&^\|!\\~]=?/, 'Operator'
|
131
|
+
rule /[()\[\]:;,<>\/?{}]/, 'Punctuation'
|
132
|
+
rule(/(?=\w)/) { push :name }
|
133
|
+
end
|
134
|
+
|
135
|
+
state :format do
|
136
|
+
rule /\.\n/, 'Literal.String.Interpol', :pop!
|
137
|
+
rule /.*?\n/, 'Literal.String.Interpol'
|
138
|
+
end
|
139
|
+
|
140
|
+
state :name_common do
|
141
|
+
rule /\w+::/, 'Name.Namespace'
|
142
|
+
rule /[\w:]+/, 'Name.Variable', :pop!
|
143
|
+
end
|
144
|
+
|
145
|
+
state :varname do
|
146
|
+
rule /\s+/, 'Text'
|
147
|
+
rule /\{/, 'Punctuation', :pop! # hash syntax
|
148
|
+
rule /\)|,/, 'Punctuation', :pop! # arg specifier
|
149
|
+
mixin :name_common
|
150
|
+
end
|
151
|
+
|
152
|
+
state :name do
|
153
|
+
mixin :name_common
|
154
|
+
rule /[A-Z_]+(?=[^a-zA-Z0-9_])/, 'Name.Constant', :pop!
|
155
|
+
rule(/(?=\W)/) { pop! }
|
156
|
+
end
|
157
|
+
|
158
|
+
state :modulename do
|
159
|
+
rule /[a-z_]\w*/i, 'Name.Namespace', :pop!
|
160
|
+
end
|
161
|
+
|
162
|
+
state :funcname do
|
163
|
+
rule /[a-zA-Z_]\w*[!?]?/, 'Name.Function'
|
164
|
+
rule /\s+/, 'Text'
|
165
|
+
|
166
|
+
# argument declaration
|
167
|
+
rule /(\([$@%]*\))(\s*)/ do
|
168
|
+
group 'Punctuation'
|
169
|
+
group 'Text'
|
170
|
+
end
|
171
|
+
|
172
|
+
rule /.*?{/, 'Punctuation', :pop!
|
173
|
+
rule /;/, 'Punctuation', :pop!
|
174
|
+
end
|
175
|
+
|
176
|
+
[[:cb, '\{', '\}'],
|
177
|
+
[:rb, '\(', '\)'],
|
178
|
+
[:sb, '\[', '\]'],
|
179
|
+
[:lt, '<', '>']].each do |name, open, close|
|
180
|
+
tok = 'Literal.String.Other'
|
181
|
+
state :"#{name}_string" do
|
182
|
+
rule /\\[#{open}#{close}\\]/, tok
|
183
|
+
rule /\\/, tok
|
184
|
+
rule(/#{open}/) { token tok; push }
|
185
|
+
rule /#{close}/, tok, :pop!
|
186
|
+
rule /[^#{open}#{close}\\]+/, tok
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
state :end_part do
|
191
|
+
# eat the rest of the stream
|
192
|
+
rule /.+/m, 'Comment.Preproc', :pop!
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
module Rouge
|
2
|
+
module Lexers
|
3
|
+
class PHP < RegexLexer
|
4
|
+
tag 'php'
|
5
|
+
aliases 'php', 'php3', 'php4', 'php5'
|
6
|
+
filenames '*.php', '*.php[345]'
|
7
|
+
mimetypes 'text/x-php'
|
8
|
+
|
9
|
+
def initialize(opts={})
|
10
|
+
# if truthy, the lexer starts highlighting with php code
|
11
|
+
# (no <?php required)
|
12
|
+
@start_inline = opts.delete(:start_inline)
|
13
|
+
@funcnamehighlighting = opts.delete(:funcnamehighlighting) { true }
|
14
|
+
@disabledmodules = opts.delete(:disabledmodules) { [] }
|
15
|
+
end
|
16
|
+
|
17
|
+
def builtins
|
18
|
+
return [] unless @funcnamehighlighting
|
19
|
+
|
20
|
+
@builtins ||= Set.new.tap do |builtins|
|
21
|
+
require Pathname.new(__FILE__).dirname.join('php/builtins.rb')
|
22
|
+
|
23
|
+
self.class.builtins.each do |mod, fns|
|
24
|
+
next if @disabledmodules.include? mod
|
25
|
+
builtins.merge(fns)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def start_inline?
|
31
|
+
!!@start_inline
|
32
|
+
end
|
33
|
+
|
34
|
+
start do
|
35
|
+
push :php if lexer.start_inline?
|
36
|
+
end
|
37
|
+
|
38
|
+
keywords = %w(
|
39
|
+
and E_PARSE old_function E_ERROR or as E_WARNING parent eval
|
40
|
+
PHP_OS break exit case extends PHP_VERSION cfunction FALSE
|
41
|
+
print for require continue foreach require_once declare return
|
42
|
+
default static do switch die stdClass echo else TRUE elseif
|
43
|
+
var empty if xor enddeclare include virtual endfor include_once
|
44
|
+
while endforeach global __FILE__ endif list __LINE__ endswitch
|
45
|
+
new __sleep endwhile not array __wakeup E_ALL NULL final
|
46
|
+
php_user_filter interface implements public private protected
|
47
|
+
abstract clone try catch throw this use namespace
|
48
|
+
)
|
49
|
+
|
50
|
+
state :root do
|
51
|
+
rule /<\?(php)?/, 'Comment.Preproc', :php
|
52
|
+
rule /.*?(?=<\?)/, 'Other'
|
53
|
+
rule /</, 'Other'
|
54
|
+
end
|
55
|
+
|
56
|
+
state :php do
|
57
|
+
rule /\?>/, 'Comment.Preproc', :pop!
|
58
|
+
# heredocs
|
59
|
+
rule /<<<('?)([a-z_]\w*)\1\n.*?\n\2;?\n/im, 'String'
|
60
|
+
rule /\s+/, 'Text'
|
61
|
+
rule /#.*?\n/, 'Comment.Single'
|
62
|
+
rule %r(//.*?\n), 'Comment.Single'
|
63
|
+
# empty comment, otherwise seen as the start of a docstring
|
64
|
+
rule %r(/\*\*/)
|
65
|
+
rule %r(/\*\*.*?\*/)m, 'Literal.String.Doc'
|
66
|
+
rule %r(/\*.*?\*/)m, 'Comment.Multiline'
|
67
|
+
rule /(->|::)(\s*)([a-zA-Z_][a-zA-Z0-9_]*)/ do
|
68
|
+
group 'Operator'; group 'Text'; group 'Name.Attribute'
|
69
|
+
end
|
70
|
+
|
71
|
+
rule /[~!%^&*+=\|:.<>\/?@-]+/, 'Operator'
|
72
|
+
rule /[\[\]{}();,]+/, 'Punctuation'
|
73
|
+
rule /class\b/, 'Keyword', :classname
|
74
|
+
# anonymous functions
|
75
|
+
rule /(function)(\s*)(?=\()/ do
|
76
|
+
group 'Keyword'; group 'Text'
|
77
|
+
end
|
78
|
+
|
79
|
+
# named functions
|
80
|
+
rule /(function)(\s+)(&?)(\s*)/ do
|
81
|
+
group 'Keyword'; group 'Text'; group 'Operator'; group 'Text'
|
82
|
+
push :funcname
|
83
|
+
end
|
84
|
+
|
85
|
+
rule /(const)(\s+)([a-zA-Z_]\w*)/i do
|
86
|
+
group 'Keyword'; group 'Text'; group 'Name.Constant'
|
87
|
+
end
|
88
|
+
|
89
|
+
rule /(?:#{keywords.join('|')})\b/, 'Keyword'
|
90
|
+
rule /(true|false|null)\b/, 'Keyword.Constant'
|
91
|
+
rule /\$\{\$+[a-z_]\w*\}/i, 'Name.Variable'
|
92
|
+
rule /\$+[a-z_]\w*/i, 'Name.Variable'
|
93
|
+
|
94
|
+
# may be intercepted for builtin highlighting
|
95
|
+
rule /[\\a-z_][\\\w]*/i, 'Name.Other'
|
96
|
+
|
97
|
+
rule /(\d+\.\d*|\d*\.\d+)(e[+-]?\d+)?/i, 'Literal.Number.Float'
|
98
|
+
rule /\d+e[+-]?\d+/i, 'Literal.Number.Float'
|
99
|
+
rule /0[0-7]+/, 'Literal.Number.Oct'
|
100
|
+
rule /0x[a-f0-9]+/i, 'Literal.Number.Hex'
|
101
|
+
rule /\d+/, 'Literal.Number.Integer'
|
102
|
+
rule /'([^'\\]*(?:\\.[^'\\]*)*)'/, 'Literal.String.Single'
|
103
|
+
rule /`([^`\\]*(?:\\.[^`\\]*)*)`/, 'Literal.String.Backtick'
|
104
|
+
rule /"/, 'Literal.String.Double', :string
|
105
|
+
end
|
106
|
+
|
107
|
+
state :classname do
|
108
|
+
rule /\s+/, 'Text'
|
109
|
+
rule /[a-z_][\\\w]*/i, 'Name.Class', :pop!
|
110
|
+
end
|
111
|
+
|
112
|
+
state :funcname do
|
113
|
+
rule /[a-z_]\w*/i, 'Name.Function', :pop!
|
114
|
+
end
|
115
|
+
|
116
|
+
state :string do
|
117
|
+
rule /"/, 'Literal.String.Double', :pop!
|
118
|
+
rule /[^\\{$"]+/, 'Literal.String.Double'
|
119
|
+
rule /\\([nrt\"$\\]|[0-7]{1,3}|x[0-9A-Fa-f]{1,2})/,
|
120
|
+
'Literal.String.Escape'
|
121
|
+
rule /\$[a-zA-Z_][a-zA-Z0-9_]*(\[\S+\]|->[a-zA-Z_][a-zA-Z0-9_]*)?/
|
122
|
+
|
123
|
+
lsi = 'Literal.String.Interpol'
|
124
|
+
rule /\{\$\{/, lsi, :interp_double
|
125
|
+
rule /\{(?=\$)/, lsi, :interp_single
|
126
|
+
rule /(\{)(\S+)(\})/ do
|
127
|
+
group lsi; group 'Name.Variable'; group lsi
|
128
|
+
end
|
129
|
+
|
130
|
+
rule /[${\\]+/, 'Literal.String.Double'
|
131
|
+
end
|
132
|
+
|
133
|
+
def stream_tokens(source, &b)
|
134
|
+
super(source) do |tok, val|
|
135
|
+
if tok.name == 'Name.Other' and builtins.include? val
|
136
|
+
yield [Token['Name.Builtin'], val]
|
137
|
+
else
|
138
|
+
yield [tok, val]
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|