rugments 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +52 -0
- data/README.md +195 -0
- data/bin/rugmentize +6 -0
- data/lib/rugments/cli.rb +357 -0
- data/lib/rugments/formatter.rb +29 -0
- data/lib/rugments/formatters/html.rb +142 -0
- data/lib/rugments/formatters/null.rb +17 -0
- data/lib/rugments/formatters/terminal256.rb +174 -0
- data/lib/rugments/lexer.rb +431 -0
- data/lib/rugments/lexers/apache/keywords.yml +453 -0
- data/lib/rugments/lexers/apache.rb +67 -0
- data/lib/rugments/lexers/apple_script.rb +366 -0
- data/lib/rugments/lexers/c.rb +210 -0
- data/lib/rugments/lexers/clojure.rb +109 -0
- data/lib/rugments/lexers/coffeescript.rb +172 -0
- data/lib/rugments/lexers/common_lisp.rb +343 -0
- data/lib/rugments/lexers/conf.rb +22 -0
- data/lib/rugments/lexers/cpp.rb +63 -0
- data/lib/rugments/lexers/csharp.rb +85 -0
- data/lib/rugments/lexers/css.rb +269 -0
- data/lib/rugments/lexers/dart.rb +102 -0
- data/lib/rugments/lexers/diff.rb +39 -0
- data/lib/rugments/lexers/elixir.rb +105 -0
- data/lib/rugments/lexers/erb.rb +54 -0
- data/lib/rugments/lexers/erlang.rb +116 -0
- data/lib/rugments/lexers/factor.rb +300 -0
- data/lib/rugments/lexers/gherkin/keywords.rb +13 -0
- data/lib/rugments/lexers/gherkin.rb +135 -0
- data/lib/rugments/lexers/go.rb +176 -0
- data/lib/rugments/lexers/groovy.rb +102 -0
- data/lib/rugments/lexers/haml.rb +226 -0
- data/lib/rugments/lexers/handlebars.rb +77 -0
- data/lib/rugments/lexers/haskell.rb +181 -0
- data/lib/rugments/lexers/html.rb +92 -0
- data/lib/rugments/lexers/http.rb +78 -0
- data/lib/rugments/lexers/ini.rb +55 -0
- data/lib/rugments/lexers/io.rb +66 -0
- data/lib/rugments/lexers/java.rb +74 -0
- data/lib/rugments/lexers/javascript.rb +258 -0
- data/lib/rugments/lexers/literate_coffeescript.rb +31 -0
- data/lib/rugments/lexers/literate_haskell.rb +34 -0
- data/lib/rugments/lexers/llvm.rb +82 -0
- data/lib/rugments/lexers/lua/builtins.rb +21 -0
- data/lib/rugments/lexers/lua.rb +120 -0
- data/lib/rugments/lexers/make.rb +114 -0
- data/lib/rugments/lexers/markdown.rb +151 -0
- data/lib/rugments/lexers/matlab/builtins.rb +10 -0
- data/lib/rugments/lexers/matlab.rb +70 -0
- data/lib/rugments/lexers/moonscript.rb +108 -0
- data/lib/rugments/lexers/nginx.rb +69 -0
- data/lib/rugments/lexers/nim.rb +149 -0
- data/lib/rugments/lexers/objective_c.rb +188 -0
- data/lib/rugments/lexers/ocaml.rb +109 -0
- data/lib/rugments/lexers/perl.rb +195 -0
- data/lib/rugments/lexers/php/builtins.rb +192 -0
- data/lib/rugments/lexers/php.rb +162 -0
- data/lib/rugments/lexers/plain_text.rb +23 -0
- data/lib/rugments/lexers/prolog.rb +62 -0
- data/lib/rugments/lexers/properties.rb +53 -0
- data/lib/rugments/lexers/puppet.rb +126 -0
- data/lib/rugments/lexers/python.rb +225 -0
- data/lib/rugments/lexers/qml.rb +70 -0
- data/lib/rugments/lexers/r.rb +55 -0
- data/lib/rugments/lexers/racket.rb +540 -0
- data/lib/rugments/lexers/ruby.rb +413 -0
- data/lib/rugments/lexers/rust.rb +188 -0
- data/lib/rugments/lexers/sass/common.rb +172 -0
- data/lib/rugments/lexers/sass.rb +72 -0
- data/lib/rugments/lexers/scala.rb +140 -0
- data/lib/rugments/lexers/scheme.rb +109 -0
- data/lib/rugments/lexers/scss.rb +32 -0
- data/lib/rugments/lexers/sed.rb +167 -0
- data/lib/rugments/lexers/shell.rb +150 -0
- data/lib/rugments/lexers/slim.rb +222 -0
- data/lib/rugments/lexers/smalltalk.rb +114 -0
- data/lib/rugments/lexers/sml.rb +345 -0
- data/lib/rugments/lexers/sql.rb +138 -0
- data/lib/rugments/lexers/swift.rb +153 -0
- data/lib/rugments/lexers/tcl.rb +189 -0
- data/lib/rugments/lexers/tex.rb +70 -0
- data/lib/rugments/lexers/toml.rb +68 -0
- data/lib/rugments/lexers/vb.rb +162 -0
- data/lib/rugments/lexers/viml/keywords.rb +11 -0
- data/lib/rugments/lexers/viml.rb +99 -0
- data/lib/rugments/lexers/xml.rb +57 -0
- data/lib/rugments/lexers/yaml.rb +362 -0
- data/lib/rugments/plugins/redcarpet.rb +28 -0
- data/lib/rugments/regex_lexer.rb +432 -0
- data/lib/rugments/template_lexer.rb +23 -0
- data/lib/rugments/text_analyzer.rb +46 -0
- data/lib/rugments/theme.rb +202 -0
- data/lib/rugments/themes/base16.rb +128 -0
- data/lib/rugments/themes/colorful.rb +65 -0
- data/lib/rugments/themes/github.rb +69 -0
- data/lib/rugments/themes/monokai.rb +88 -0
- data/lib/rugments/themes/monokai_sublime.rb +89 -0
- data/lib/rugments/themes/thankful_eyes.rb +69 -0
- data/lib/rugments/token.rb +180 -0
- data/lib/rugments/util.rb +99 -0
- data/lib/rugments/version.rb +3 -0
- data/lib/rugments.rb +33 -0
- metadata +149 -0
@@ -0,0 +1,258 @@
|
|
1
|
+
module Rugments
|
2
|
+
module Lexers
|
3
|
+
class Javascript < RegexLexer
|
4
|
+
title 'JavaScript'
|
5
|
+
desc 'JavaScript, the browser scripting language'
|
6
|
+
|
7
|
+
tag 'javascript'
|
8
|
+
aliases 'js'
|
9
|
+
filenames '*.js'
|
10
|
+
mimetypes 'application/javascript', 'application/x-javascript',
|
11
|
+
'text/javascript', 'text/x-javascript'
|
12
|
+
|
13
|
+
def self.analyze_text(text)
|
14
|
+
return 1 if text.shebang?('node')
|
15
|
+
return 1 if text.shebang?('jsc')
|
16
|
+
# TODO: rhino, spidermonkey, etc
|
17
|
+
end
|
18
|
+
|
19
|
+
state :comments_and_whitespace do
|
20
|
+
rule /\s+/, Text
|
21
|
+
rule /<!--/, Comment # really...?
|
22
|
+
rule %r{//.*?$}, Comment::Single
|
23
|
+
rule %r{/\*.*?\*/}m, Comment::Multiline
|
24
|
+
end
|
25
|
+
|
26
|
+
state :expr_start do
|
27
|
+
mixin :comments_and_whitespace
|
28
|
+
|
29
|
+
rule %r{/} do
|
30
|
+
token Str::Regex
|
31
|
+
goto :regex
|
32
|
+
end
|
33
|
+
|
34
|
+
rule /[{]/, Punctuation, :object
|
35
|
+
|
36
|
+
rule //, Text, :pop!
|
37
|
+
end
|
38
|
+
|
39
|
+
state :regex do
|
40
|
+
rule %r{/} do
|
41
|
+
token Str::Regex
|
42
|
+
goto :regex_end
|
43
|
+
end
|
44
|
+
|
45
|
+
rule %r{[^/]\n}, Error, :pop!
|
46
|
+
|
47
|
+
rule /\n/, Error, :pop!
|
48
|
+
rule /\[\^/, Str::Escape, :regex_group
|
49
|
+
rule /\[/, Str::Escape, :regex_group
|
50
|
+
rule /\\./, Str::Escape
|
51
|
+
rule %r{[(][?][:=<!]}, Str::Escape
|
52
|
+
rule /[{][\d,]+[}]/, Str::Escape
|
53
|
+
rule /[()?]/, Str::Escape
|
54
|
+
rule /./, Str::Regex
|
55
|
+
end
|
56
|
+
|
57
|
+
state :regex_end do
|
58
|
+
rule /[gim]+/, Str::Regex, :pop!
|
59
|
+
rule(//) { pop! }
|
60
|
+
end
|
61
|
+
|
62
|
+
state :regex_group do
|
63
|
+
# specially highlight / in a group to indicate that it doesn't
|
64
|
+
# close the regex
|
65
|
+
rule /\//, Str::Escape
|
66
|
+
|
67
|
+
rule %r{[^/]\n} do
|
68
|
+
token Error
|
69
|
+
pop! 2
|
70
|
+
end
|
71
|
+
|
72
|
+
rule /\]/, Str::Escape, :pop!
|
73
|
+
rule /\\./, Str::Escape
|
74
|
+
rule /./, Str::Regex
|
75
|
+
end
|
76
|
+
|
77
|
+
state :bad_regex do
|
78
|
+
rule /[^\n]+/, Error, :pop!
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.keywords
|
82
|
+
@keywords ||= Set.new %w(
|
83
|
+
for in while do break return continue switch case default
|
84
|
+
if else throw try catch finally new delete typeof instanceof
|
85
|
+
void this
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.declarations
|
90
|
+
@declarations ||= Set.new %w(var let with function)
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.reserved
|
94
|
+
@reserved ||= Set.new %w(
|
95
|
+
abstract boolean byte char class const debugger double enum
|
96
|
+
export extends final float goto implements import int interface
|
97
|
+
long native package private protected public short static
|
98
|
+
super synchronized throws transient volatile
|
99
|
+
)
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.constants
|
103
|
+
@constants ||= Set.new %w(true false null NaN Infinity undefined)
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.builtins
|
107
|
+
@builtins ||= %w(
|
108
|
+
Array Boolean Date Error Function Math netscape
|
109
|
+
Number Object Packages RegExp String sun decodeURI
|
110
|
+
decodeURIComponent encodeURI encodeURIComponent
|
111
|
+
Error eval isFinite isNaN parseFloat parseInt document this
|
112
|
+
window
|
113
|
+
)
|
114
|
+
end
|
115
|
+
|
116
|
+
id = /[$a-zA-Z_][a-zA-Z0-9_]*/
|
117
|
+
|
118
|
+
state :root do
|
119
|
+
rule /\A\s*#!.*?\n/m, Comment::Preproc, :statement
|
120
|
+
rule /\n/, Text, :statement
|
121
|
+
rule %r{(?<=\n)(?=\s|/|<!--)}, Text, :expr_start
|
122
|
+
mixin :comments_and_whitespace
|
123
|
+
rule %r{\+\+ | -- | ~ | && | \|\| | \\(?=\n) | << | >>>? | ===
|
124
|
+
| !== }x,
|
125
|
+
Operator, :expr_start
|
126
|
+
rule %r{[-<>+*%&|\^/!=]=?}, Operator, :expr_start
|
127
|
+
rule /[(\[,]/, Punctuation, :expr_start
|
128
|
+
rule /;/, Punctuation, :statement
|
129
|
+
rule /[)\].]/, Punctuation
|
130
|
+
|
131
|
+
rule /[?]/ do
|
132
|
+
token Punctuation
|
133
|
+
push :ternary
|
134
|
+
push :expr_start
|
135
|
+
end
|
136
|
+
|
137
|
+
rule /[{}]/, Punctuation, :statement
|
138
|
+
|
139
|
+
rule id do |m|
|
140
|
+
if self.class.keywords.include? m[0]
|
141
|
+
token Keyword
|
142
|
+
push :expr_start
|
143
|
+
elsif self.class.declarations.include? m[0]
|
144
|
+
token Keyword::Declaration
|
145
|
+
push :expr_start
|
146
|
+
elsif self.class.reserved.include? m[0]
|
147
|
+
token Keyword::Reserved
|
148
|
+
elsif self.class.constants.include? m[0]
|
149
|
+
token Keyword::Constant
|
150
|
+
elsif self.class.builtins.include? m[0]
|
151
|
+
token Name::Builtin
|
152
|
+
else
|
153
|
+
token Name::Other
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
rule /[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?/, Num::Float
|
158
|
+
rule /0x[0-9a-fA-F]+/, Num::Hex
|
159
|
+
rule /[0-9]+/, Num::Integer
|
160
|
+
rule /"(\\\\|\\"|[^"])*"/, Str::Double
|
161
|
+
rule /'(\\\\|\\'|[^'])*'/, Str::Single
|
162
|
+
end
|
163
|
+
|
164
|
+
# braced parts that aren't object literals
|
165
|
+
state :statement do
|
166
|
+
rule /(#{id})(\s*)(:)/ do
|
167
|
+
groups Name::Label, Text, Punctuation
|
168
|
+
end
|
169
|
+
|
170
|
+
rule /[{}]/, Punctuation
|
171
|
+
|
172
|
+
mixin :expr_start
|
173
|
+
end
|
174
|
+
|
175
|
+
# object literals
|
176
|
+
state :object do
|
177
|
+
mixin :comments_and_whitespace
|
178
|
+
rule /[}]/ do
|
179
|
+
token Punctuation
|
180
|
+
goto :statement
|
181
|
+
end
|
182
|
+
|
183
|
+
rule /(#{id})(\s*)(:)/ do
|
184
|
+
groups Name::Attribute, Text, Punctuation
|
185
|
+
push :expr_start
|
186
|
+
end
|
187
|
+
|
188
|
+
rule /:/, Punctuation
|
189
|
+
mixin :root
|
190
|
+
end
|
191
|
+
|
192
|
+
# ternary expressions, where <id>: is not a label!
|
193
|
+
state :ternary do
|
194
|
+
rule /:/ do
|
195
|
+
token Punctuation
|
196
|
+
goto :expr_start
|
197
|
+
end
|
198
|
+
|
199
|
+
mixin :root
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
class JSON < RegexLexer
|
204
|
+
desc 'JavaScript Object Notation (json.org)'
|
205
|
+
tag 'json'
|
206
|
+
filenames '*.json'
|
207
|
+
mimetypes 'application/json'
|
208
|
+
|
209
|
+
# TODO: is this too much of a performance hit? JSON is quite simple,
|
210
|
+
# so I'd think this wouldn't be too bad, but for large documents this
|
211
|
+
# could mean doing two full lexes.
|
212
|
+
def self.analyze_text(text)
|
213
|
+
return 0.8 if text =~ /\A\s*{/m && text.lexes_cleanly?(self)
|
214
|
+
end
|
215
|
+
|
216
|
+
state :root do
|
217
|
+
mixin :whitespace
|
218
|
+
# special case for empty objects
|
219
|
+
rule /(\{)(\s*)(\})/m do
|
220
|
+
groups Punctuation, Text::Whitespace, Punctuation
|
221
|
+
end
|
222
|
+
rule /(?:true|false|null)\b/, Keyword::Constant
|
223
|
+
rule /{/, Punctuation, :object_key
|
224
|
+
rule /\[/, Punctuation, :array
|
225
|
+
rule /-?(?:0|[1-9]\d*)\.\d+(?:e[+-]\d+)?/i, Num::Float
|
226
|
+
rule /-?(?:0|[1-9]\d*)(?:e[+-]\d+)?/i, Num::Integer
|
227
|
+
mixin :has_string
|
228
|
+
end
|
229
|
+
|
230
|
+
state :whitespace do
|
231
|
+
rule /\s+/m, Text::Whitespace
|
232
|
+
end
|
233
|
+
|
234
|
+
state :has_string do
|
235
|
+
rule /"(\\.|[^"])*"/, Str::Double
|
236
|
+
end
|
237
|
+
|
238
|
+
state :object_key do
|
239
|
+
mixin :whitespace
|
240
|
+
mixin :has_string
|
241
|
+
rule /:/, Punctuation, :object_val
|
242
|
+
rule /}/, Error, :pop!
|
243
|
+
end
|
244
|
+
|
245
|
+
state :object_val do
|
246
|
+
rule /,/, Punctuation, :pop!
|
247
|
+
rule(/}/) { token Punctuation; pop!(2) }
|
248
|
+
mixin :root
|
249
|
+
end
|
250
|
+
|
251
|
+
state :array do
|
252
|
+
rule /\]/, Punctuation, :pop!
|
253
|
+
rule /,/, Punctuation
|
254
|
+
mixin :root
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Rugments
|
2
|
+
module Lexers
|
3
|
+
class LiterateCoffeescript < RegexLexer
|
4
|
+
tag 'literate_coffeescript'
|
5
|
+
title 'Literate CoffeeScript'
|
6
|
+
desc 'Literate coffeescript'
|
7
|
+
aliases 'litcoffee'
|
8
|
+
filenames '*.litcoffee'
|
9
|
+
|
10
|
+
def markdown
|
11
|
+
@markdown ||= Markdown.new(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def coffee
|
15
|
+
@coffee ||= Coffeescript.new(options)
|
16
|
+
end
|
17
|
+
|
18
|
+
start { markdown.reset!; coffee.reset! }
|
19
|
+
|
20
|
+
state :root do
|
21
|
+
rule /^( .*?\n)+/m do
|
22
|
+
delegate coffee
|
23
|
+
end
|
24
|
+
|
25
|
+
rule /^([ ]{0,3}(\S.*?|)\n)*/m do
|
26
|
+
delegate markdown
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Rugments
|
2
|
+
module Lexers
|
3
|
+
class LiterateHaskell < RegexLexer
|
4
|
+
title 'Literate Haskell'
|
5
|
+
desc 'Literate haskell'
|
6
|
+
tag 'literate_haskell'
|
7
|
+
aliases 'lithaskell', 'lhaskell', 'lhs'
|
8
|
+
filenames '*.lhs'
|
9
|
+
mimetypes 'text/x-literate-haskell'
|
10
|
+
|
11
|
+
def haskell
|
12
|
+
@haskell ||= Haskell.new(options)
|
13
|
+
end
|
14
|
+
|
15
|
+
start { haskell.reset! }
|
16
|
+
|
17
|
+
# TODO: support TeX versions as well.
|
18
|
+
state :root do
|
19
|
+
rule /\s*?\n(?=>)/, Text, :code
|
20
|
+
rule /.*?\n/, Text
|
21
|
+
rule /.+\z/, Text
|
22
|
+
end
|
23
|
+
|
24
|
+
state :code do
|
25
|
+
rule /(>)( .*?(\n|\z))/ do |m|
|
26
|
+
token Name::Label, m[1]
|
27
|
+
delegate haskell, m[2]
|
28
|
+
end
|
29
|
+
|
30
|
+
rule /\s*\n(?=\s*[^>])/, Text, :pop!
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Rugments
|
2
|
+
module Lexers
|
3
|
+
class LLVM < RegexLexer
|
4
|
+
title 'LLVM'
|
5
|
+
desc 'The LLVM Compiler Infrastructure (http://llvm.org/)'
|
6
|
+
tag 'llvm'
|
7
|
+
|
8
|
+
filenames '*.ll'
|
9
|
+
mimetypes 'text/x-llvm'
|
10
|
+
|
11
|
+
def self.analyze_text(text)
|
12
|
+
return 0.1 if text =~ /\A%\w+\s=\s/
|
13
|
+
end
|
14
|
+
|
15
|
+
string = /"[^"]*?"/
|
16
|
+
identifier = /([-a-zA-Z$._][-a-zA-Z$._0-9]*|#{string})/
|
17
|
+
|
18
|
+
state :basic do
|
19
|
+
rule /;.*?$/, Comment::Single
|
20
|
+
rule /\s+/, Text
|
21
|
+
|
22
|
+
rule /#{identifier}\s*:/, Name::Label
|
23
|
+
|
24
|
+
rule /@(#{identifier}|\d+)/, Name::Variable::Global
|
25
|
+
rule /(%|!)#{identifier}/, Name::Variable
|
26
|
+
rule /(%|!)\d+/, Name::Variable
|
27
|
+
|
28
|
+
rule /c?#{string}/, Str
|
29
|
+
|
30
|
+
rule /0[xX][a-fA-F0-9]+/, Num
|
31
|
+
rule /-?\d+(?:[.]\d+)?(?:[eE][-+]?\d+(?:[.]\d+)?)?/, Num
|
32
|
+
|
33
|
+
rule /[=<>{}\[\]()*.,!]|x/, Punctuation
|
34
|
+
end
|
35
|
+
|
36
|
+
builtin_types = %w(
|
37
|
+
void float double half x86_fp80 x86mmx fp128 ppc_fp128 label metadata
|
38
|
+
)
|
39
|
+
|
40
|
+
state :types do
|
41
|
+
rule /i[1-9]\d*/, Keyword::Type
|
42
|
+
rule /#{builtin_types.join('|')}/, Keyword::Type
|
43
|
+
end
|
44
|
+
|
45
|
+
builtin_keywords = %w(
|
46
|
+
begin end true false declare define global constant personality private
|
47
|
+
landingpad linker_private internal available_externally linkonce_odr
|
48
|
+
linkonce weak weak_odr appending dllimport dllexport common default
|
49
|
+
hidden protected extern_weak external thread_local zeroinitializer
|
50
|
+
undef null to tail target triple datalayout volatile nuw nsw nnan ninf
|
51
|
+
nsz arcp fast exact inbounds align addrspace section alias module asm
|
52
|
+
sideeffect gc dbg ccc fastcc coldcc x86_stdcallcc x86_fastcallcc
|
53
|
+
arm_apcscc arm_aapcscc arm_aapcs_vfpcc ptx_device ptx_kernel cc
|
54
|
+
c signext zeroext inreg sret nounwind noreturn noalias nocapture byval
|
55
|
+
nest readnone readonly inlinehint noinline alwaysinline optsize ssp
|
56
|
+
sspreq noredzone noimplicitfloat naked type opaque eq ne slt sgt sle
|
57
|
+
sge ult ugt ule uge oeq one olt ogt ole oge ord uno unnamed_addr ueq
|
58
|
+
une uwtable x
|
59
|
+
)
|
60
|
+
|
61
|
+
builtin_instructions = %w(
|
62
|
+
add fadd sub fsub mul fmul udiv sdiv fdiv urem srem frem shl lshr ashr
|
63
|
+
and or xor icmp fcmp phi call catch trunc zext sext fptrunc fpext
|
64
|
+
uitofp sitofp fptoui fptosi inttoptr ptrtoint bitcast select va_arg ret
|
65
|
+
br switch invoke unwind unreachable malloc alloca free load store
|
66
|
+
getelementptr extractelement insertelement shufflevector getresult
|
67
|
+
extractvalue insertvalue cleanup resume
|
68
|
+
)
|
69
|
+
|
70
|
+
state :keywords do
|
71
|
+
rule /#{builtin_instructions.join('|')}/, Keyword
|
72
|
+
rule /#{builtin_keywords.join('|')}/, Keyword
|
73
|
+
end
|
74
|
+
|
75
|
+
state :root do
|
76
|
+
mixin :basic
|
77
|
+
mixin :keywords
|
78
|
+
mixin :types
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# automatically generated by `rake builtins:lua`
|
2
|
+
module Rugments
|
3
|
+
module Lexers
|
4
|
+
class Lua
|
5
|
+
def self.builtins
|
6
|
+
@builtins ||= {}.tap do |b|
|
7
|
+
b['basic'] = Set.new %w(_G _VERSION assert collectgarbage dofile error getmetatable ipairs load loadfile next pairs pcall print rawequal rawget rawlen rawset select setmetatable tonumber tostring type xpcall file:close file:flush file:lines file:read file:seek file:setvbuf file:write)
|
8
|
+
b['modules'] = Set.new %w(require package.config package.cpath package.loaded package.loadlib package.path package.preload package.searchers package.searchpath)
|
9
|
+
b['bit32'] = Set.new %w(bit32.arshift bit32.band bit32.bnot bit32.bor bit32.btest bit32.bxor bit32.extract bit32.lrotate bit32.lshift bit32.replace bit32.rrotate bit32.rshift)
|
10
|
+
b['coroutine'] = Set.new %w(coroutine.create coroutine.resume coroutine.running coroutine.status coroutine.wrap coroutine.yield)
|
11
|
+
b['debug'] = Set.new %w(debug.debug debug.getuservalue debug.gethook debug.getinfo debug.getlocal debug.getmetatable debug.getregistry debug.getupvalue debug.setuservalue debug.sethook debug.setlocal debug.setmetatable debug.setupvalue debug.traceback debug.upvalueid debug.upvaluejoin)
|
12
|
+
b['io'] = Set.new %w(io.close io.flush io.input io.lines io.open io.output io.popen io.read io.stderr io.stdin io.stdout io.tmpfile io.type io.write)
|
13
|
+
b['math'] = Set.new %w(math.abs math.acos math.asin math.atan math.atan2 math.ceil math.cos math.cosh math.deg math.exp math.floor math.fmod math.frexp math.huge math.ldexp math.log math.max math.min math.modf math.pi math.pow math.rad math.random math.randomseed math.sin math.sinh math.sqrt math.tan math.tanh)
|
14
|
+
b['os'] = Set.new %w(os.clock os.date os.difftime os.execute os.exit os.getenv os.remove os.rename os.setlocale os.time os.tmpname)
|
15
|
+
b['string'] = Set.new %w(string.byte string.char string.dump string.find string.format string.gmatch string.gsub string.len string.lower string.match string.rep string.reverse string.sub string.upper)
|
16
|
+
b['table'] = Set.new %w(table.concat table.insert table.pack table.remove table.sort table.unpack)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
module Rugments
|
2
|
+
module Lexers
|
3
|
+
class Lua < RegexLexer
|
4
|
+
title 'Lua'
|
5
|
+
desc 'Lua (http://www.lua.org)'
|
6
|
+
tag 'lua'
|
7
|
+
filenames '*.lua', '*.wlua'
|
8
|
+
|
9
|
+
mimetypes 'text/x-lua', 'application/x-lua'
|
10
|
+
|
11
|
+
def initialize(opts = {})
|
12
|
+
@function_highlighting = opts.delete(:function_highlighting) { true }
|
13
|
+
@disabled_modules = opts.delete(:disabled_modules) { [] }
|
14
|
+
super(opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.analyze_text(text)
|
18
|
+
return 1 if text.shebang? 'lua'
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.builtins
|
22
|
+
load Pathname.new(__FILE__).dirname.join('lua/builtins.rb')
|
23
|
+
builtins
|
24
|
+
end
|
25
|
+
|
26
|
+
def builtins
|
27
|
+
return [] unless @function_highlighting
|
28
|
+
|
29
|
+
@builtins ||= Set.new.tap do |builtins|
|
30
|
+
self.class.builtins.each do |mod, fns|
|
31
|
+
next if @disabled_modules.include? mod
|
32
|
+
builtins.merge(fns)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
state :root do
|
38
|
+
# lua allows a file to start with a shebang
|
39
|
+
rule %r{#!(.*?)$}, Comment::Preproc
|
40
|
+
rule //, Text, :base
|
41
|
+
end
|
42
|
+
|
43
|
+
state :base do
|
44
|
+
rule %r{--\[(=*)\[.*?\]\1\]}m, Comment::Multiline
|
45
|
+
rule %r{--.*$}, Comment::Single
|
46
|
+
|
47
|
+
rule %r{(?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?'}, Num::Float
|
48
|
+
rule %r{(?i)\d+e[+-]?\d+}, Num::Float
|
49
|
+
rule %r{(?i)0x[0-9a-f]*}, Num::Hex
|
50
|
+
rule %r{\d+}, Num::Integer
|
51
|
+
|
52
|
+
rule %r{\n}, Text
|
53
|
+
rule %r{[^\S\n]}, Text
|
54
|
+
# multiline strings
|
55
|
+
rule %r{\[(=*)\[.*?\]\1\]}m, Str
|
56
|
+
|
57
|
+
rule %r{(==|~=|<=|>=|\.\.\.|\.\.|[=+\-*/%^<>#])}, Operator
|
58
|
+
rule %r([\[\]\{\}\(\)\.,:;]), Punctuation
|
59
|
+
rule %r{(and|or|not)\b}, Operator::Word
|
60
|
+
|
61
|
+
rule %r{(break|do|else|elseif|end|for|if|in|repeat|return|then|until|while)\b}, Keyword
|
62
|
+
rule %r{(local)\b}, Keyword::Declaration
|
63
|
+
rule %r{(true|false|nil)\b}, Keyword::Constant
|
64
|
+
|
65
|
+
rule %r{(function)\b}, Keyword, :function_name
|
66
|
+
|
67
|
+
rule %r{[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?} do |m|
|
68
|
+
name = m[0]
|
69
|
+
if self.builtins.include?(name)
|
70
|
+
token Name::Builtin
|
71
|
+
elsif name =~ /\./
|
72
|
+
a, b = name.split('.', 2)
|
73
|
+
token Name, a
|
74
|
+
token Punctuation, '.'
|
75
|
+
token Name, b
|
76
|
+
else
|
77
|
+
token Name
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
rule %r{'}, Str::Single, :escape_sqs
|
82
|
+
rule %r{"}, Str::Double, :escape_dqs
|
83
|
+
end
|
84
|
+
|
85
|
+
state :function_name do
|
86
|
+
rule /\s+/, Text
|
87
|
+
rule %r{(?:([A-Za-z_][A-Za-z0-9_]*)(\.))?([A-Za-z_][A-Za-z0-9_]*)} do
|
88
|
+
groups Name::Class, Punctuation, Name::Function
|
89
|
+
pop!
|
90
|
+
end
|
91
|
+
# inline function
|
92
|
+
rule %r{\(}, Punctuation, :pop!
|
93
|
+
end
|
94
|
+
|
95
|
+
state :escape_sqs do
|
96
|
+
mixin :string_escape
|
97
|
+
mixin :sqs
|
98
|
+
end
|
99
|
+
|
100
|
+
state :escape_dqs do
|
101
|
+
mixin :string_escape
|
102
|
+
mixin :dqs
|
103
|
+
end
|
104
|
+
|
105
|
+
state :string_escape do
|
106
|
+
rule %r(\\([abfnrtv\\"']|\d{1,3})), Str::Escape
|
107
|
+
end
|
108
|
+
|
109
|
+
state :sqs do
|
110
|
+
rule %r{'}, Str::Single, :pop!
|
111
|
+
rule %r{[^']+}, Str::Single
|
112
|
+
end
|
113
|
+
|
114
|
+
state :dqs do
|
115
|
+
rule %r{"}, Str::Double, :pop!
|
116
|
+
rule %r{[^"]+}, Str::Double
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module Rugments
|
2
|
+
module Lexers
|
3
|
+
class Make < RegexLexer
|
4
|
+
title 'Make'
|
5
|
+
desc 'Makefile syntax'
|
6
|
+
tag 'make'
|
7
|
+
aliases 'makefile', 'mf', 'gnumake', 'bsdmake'
|
8
|
+
filenames '*.make', 'Makefile', 'makefile', 'Makefile.*', 'GNUmakefile'
|
9
|
+
mimetypes 'text/x-makefile'
|
10
|
+
|
11
|
+
def self.analyze_text(text)
|
12
|
+
return 0.6 if text =~ /^\.PHONY:/
|
13
|
+
end
|
14
|
+
|
15
|
+
bsd_special = %w(
|
16
|
+
include undef error warning if else elif endif for endfor
|
17
|
+
)
|
18
|
+
|
19
|
+
gnu_special = %w(
|
20
|
+
ifeq ifneq ifdef ifndef else endif include -include define endef :
|
21
|
+
)
|
22
|
+
|
23
|
+
line = /(?:\\.|\\\n|[^\\\n])*/m
|
24
|
+
|
25
|
+
def initialize(opts = {})
|
26
|
+
super
|
27
|
+
@shell = Shell.new(opts)
|
28
|
+
end
|
29
|
+
|
30
|
+
start { @shell.reset! }
|
31
|
+
|
32
|
+
state :root do
|
33
|
+
rule /\s+/, Text
|
34
|
+
|
35
|
+
rule /#.*?\n/, Comment
|
36
|
+
|
37
|
+
rule /(export)(\s+)(?=[a-zA-Z0-9_\${}\t -]+\n)/ do
|
38
|
+
groups Keyword, Text
|
39
|
+
push :export
|
40
|
+
end
|
41
|
+
|
42
|
+
rule /export\s+/, Keyword
|
43
|
+
|
44
|
+
# assignment
|
45
|
+
rule /([a-zA-Z0-9_${}.-]+)(\s*)([!?:+]?=)/m do |m|
|
46
|
+
token Name::Variable, m[1]
|
47
|
+
token Text, m[2]
|
48
|
+
token Operator, m[3]
|
49
|
+
push :shell_line
|
50
|
+
end
|
51
|
+
|
52
|
+
rule /"(\\\\|\\.|[^"\\])*"/, Str::Double
|
53
|
+
rule /'(\\\\|\\.|[^'\\])*'/, Str::Single
|
54
|
+
rule /([^\n:]+)(:+)([ \t]*)/ do
|
55
|
+
groups Name::Label, Operator, Text
|
56
|
+
push :block_header
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
state :export do
|
61
|
+
rule /[\w\${}-]/, Name::Variable
|
62
|
+
rule /\n/, Text, :pop!
|
63
|
+
rule /\s+/, Text
|
64
|
+
end
|
65
|
+
|
66
|
+
state :block_header do
|
67
|
+
rule /[^,\\\n#]+/, Name::Function
|
68
|
+
rule /,/, Punctuation
|
69
|
+
rule /#.*?/, Comment
|
70
|
+
rule /\\\n/, Text
|
71
|
+
rule /\\./, Text
|
72
|
+
rule /\n/ do
|
73
|
+
token Text
|
74
|
+
goto :block_body
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
state :block_body do
|
79
|
+
rule /(\t[\t ]*)([@-]?)/ do |_m|
|
80
|
+
groups Text, Punctuation
|
81
|
+
push :shell_line
|
82
|
+
end
|
83
|
+
|
84
|
+
rule(//) { @shell.reset!; pop! }
|
85
|
+
end
|
86
|
+
|
87
|
+
state :shell do
|
88
|
+
# macro interpolation
|
89
|
+
rule /\$\(\s*[a-z_]\w*\s*\)/i, Name::Variable
|
90
|
+
# $(shell ...)
|
91
|
+
rule /(\$\()(\s*)(shell)(\s+)/m do
|
92
|
+
groups Name::Function, Text, Name::Builtin, Text
|
93
|
+
push :shell_expr
|
94
|
+
end
|
95
|
+
|
96
|
+
rule(/\\./m) { delegate @shell }
|
97
|
+
stop = /\$\(|\(|\)|\n|\\/
|
98
|
+
rule(/.+?(?=#{stop})/m) { delegate @shell }
|
99
|
+
rule(stop) { delegate @shell }
|
100
|
+
end
|
101
|
+
|
102
|
+
state :shell_expr do
|
103
|
+
rule(/\(/) { delegate @shell; push }
|
104
|
+
rule /\)/, Name::Variable, :pop!
|
105
|
+
mixin :shell
|
106
|
+
end
|
107
|
+
|
108
|
+
state :shell_line do
|
109
|
+
rule /\n/, Text, :pop!
|
110
|
+
mixin :shell
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|