gitlab-rouge 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +23 -0
  3. data/LICENSE +186 -0
  4. data/bin/rougify +16 -0
  5. data/gitlab-rouge.gemspec +17 -0
  6. data/lib/rouge.rb +57 -0
  7. data/lib/rouge/cli.rb +363 -0
  8. data/lib/rouge/demos/apache +21 -0
  9. data/lib/rouge/demos/applescript +2 -0
  10. data/lib/rouge/demos/c +8 -0
  11. data/lib/rouge/demos/clojure +5 -0
  12. data/lib/rouge/demos/coffeescript +5 -0
  13. data/lib/rouge/demos/common_lisp +1 -0
  14. data/lib/rouge/demos/conf +4 -0
  15. data/lib/rouge/demos/cpp +8 -0
  16. data/lib/rouge/demos/csharp +5 -0
  17. data/lib/rouge/demos/css +4 -0
  18. data/lib/rouge/demos/dart +6 -0
  19. data/lib/rouge/demos/diff +7 -0
  20. data/lib/rouge/demos/elixir +1 -0
  21. data/lib/rouge/demos/erb +1 -0
  22. data/lib/rouge/demos/erlang +7 -0
  23. data/lib/rouge/demos/factor +5 -0
  24. data/lib/rouge/demos/gherkin +17 -0
  25. data/lib/rouge/demos/glsl +14 -0
  26. data/lib/rouge/demos/go +7 -0
  27. data/lib/rouge/demos/groovy +9 -0
  28. data/lib/rouge/demos/haml +5 -0
  29. data/lib/rouge/demos/handlebars +7 -0
  30. data/lib/rouge/demos/haskell +6 -0
  31. data/lib/rouge/demos/html +8 -0
  32. data/lib/rouge/demos/http +14 -0
  33. data/lib/rouge/demos/ini +4 -0
  34. data/lib/rouge/demos/io +11 -0
  35. data/lib/rouge/demos/java +5 -0
  36. data/lib/rouge/demos/javascript +1 -0
  37. data/lib/rouge/demos/json +1 -0
  38. data/lib/rouge/demos/json-doc +1 -0
  39. data/lib/rouge/demos/liquid +11 -0
  40. data/lib/rouge/demos/literate_coffeescript +3 -0
  41. data/lib/rouge/demos/literate_haskell +7 -0
  42. data/lib/rouge/demos/llvm +20 -0
  43. data/lib/rouge/demos/lua +12 -0
  44. data/lib/rouge/demos/make +6 -0
  45. data/lib/rouge/demos/markdown +4 -0
  46. data/lib/rouge/demos/matlab +6 -0
  47. data/lib/rouge/demos/moonscript +16 -0
  48. data/lib/rouge/demos/nginx +5 -0
  49. data/lib/rouge/demos/nim +27 -0
  50. data/lib/rouge/demos/objective_c +14 -0
  51. data/lib/rouge/demos/ocaml +12 -0
  52. data/lib/rouge/demos/perl +5 -0
  53. data/lib/rouge/demos/php +3 -0
  54. data/lib/rouge/demos/plaintext +1 -0
  55. data/lib/rouge/demos/powershell +49 -0
  56. data/lib/rouge/demos/prolog +9 -0
  57. data/lib/rouge/demos/properties +7 -0
  58. data/lib/rouge/demos/puppet +6 -0
  59. data/lib/rouge/demos/python +6 -0
  60. data/lib/rouge/demos/qml +9 -0
  61. data/lib/rouge/demos/r +8 -0
  62. data/lib/rouge/demos/racket +24 -0
  63. data/lib/rouge/demos/ruby +9 -0
  64. data/lib/rouge/demos/rust +12 -0
  65. data/lib/rouge/demos/sass +3 -0
  66. data/lib/rouge/demos/scala +3 -0
  67. data/lib/rouge/demos/scheme +4 -0
  68. data/lib/rouge/demos/scss +5 -0
  69. data/lib/rouge/demos/sed +4 -0
  70. data/lib/rouge/demos/shell +2 -0
  71. data/lib/rouge/demos/slim +17 -0
  72. data/lib/rouge/demos/smalltalk +6 -0
  73. data/lib/rouge/demos/sml +4 -0
  74. data/lib/rouge/demos/sql +1 -0
  75. data/lib/rouge/demos/swift +5 -0
  76. data/lib/rouge/demos/tcl +1 -0
  77. data/lib/rouge/demos/tex +1 -0
  78. data/lib/rouge/demos/toml +9 -0
  79. data/lib/rouge/demos/tulip +14 -0
  80. data/lib/rouge/demos/vb +4 -0
  81. data/lib/rouge/demos/viml +5 -0
  82. data/lib/rouge/demos/xml +2 -0
  83. data/lib/rouge/demos/yaml +4 -0
  84. data/lib/rouge/formatter.rb +50 -0
  85. data/lib/rouge/formatters/html.rb +117 -0
  86. data/lib/rouge/formatters/null.rb +19 -0
  87. data/lib/rouge/formatters/terminal256.rb +176 -0
  88. data/lib/rouge/lexer.rb +443 -0
  89. data/lib/rouge/lexers/apache.rb +68 -0
  90. data/lib/rouge/lexers/apache/keywords.yml +453 -0
  91. data/lib/rouge/lexers/apple_script.rb +367 -0
  92. data/lib/rouge/lexers/c.rb +212 -0
  93. data/lib/rouge/lexers/clojure.rb +112 -0
  94. data/lib/rouge/lexers/coffeescript.rb +174 -0
  95. data/lib/rouge/lexers/common_lisp.rb +345 -0
  96. data/lib/rouge/lexers/conf.rb +24 -0
  97. data/lib/rouge/lexers/cpp.rb +66 -0
  98. data/lib/rouge/lexers/csharp.rb +88 -0
  99. data/lib/rouge/lexers/css.rb +271 -0
  100. data/lib/rouge/lexers/dart.rb +104 -0
  101. data/lib/rouge/lexers/diff.rb +31 -0
  102. data/lib/rouge/lexers/elixir.rb +108 -0
  103. data/lib/rouge/lexers/erb.rb +56 -0
  104. data/lib/rouge/lexers/erlang.rb +118 -0
  105. data/lib/rouge/lexers/factor.rb +302 -0
  106. data/lib/rouge/lexers/gherkin.rb +137 -0
  107. data/lib/rouge/lexers/gherkin/keywords.rb +14 -0
  108. data/lib/rouge/lexers/glsl.rb +135 -0
  109. data/lib/rouge/lexers/go.rb +178 -0
  110. data/lib/rouge/lexers/groovy.rb +104 -0
  111. data/lib/rouge/lexers/haml.rb +228 -0
  112. data/lib/rouge/lexers/handlebars.rb +79 -0
  113. data/lib/rouge/lexers/haskell.rb +183 -0
  114. data/lib/rouge/lexers/html.rb +94 -0
  115. data/lib/rouge/lexers/http.rb +80 -0
  116. data/lib/rouge/lexers/ini.rb +57 -0
  117. data/lib/rouge/lexers/io.rb +68 -0
  118. data/lib/rouge/lexers/java.rb +76 -0
  119. data/lib/rouge/lexers/javascript.rb +297 -0
  120. data/lib/rouge/lexers/liquid.rb +287 -0
  121. data/lib/rouge/lexers/literate_coffeescript.rb +33 -0
  122. data/lib/rouge/lexers/literate_haskell.rb +36 -0
  123. data/lib/rouge/lexers/llvm.rb +84 -0
  124. data/lib/rouge/lexers/lua.rb +122 -0
  125. data/lib/rouge/lexers/lua/builtins.rb +22 -0
  126. data/lib/rouge/lexers/make.rb +116 -0
  127. data/lib/rouge/lexers/markdown.rb +154 -0
  128. data/lib/rouge/lexers/matlab.rb +74 -0
  129. data/lib/rouge/lexers/matlab/builtins.rb +11 -0
  130. data/lib/rouge/lexers/moonscript.rb +110 -0
  131. data/lib/rouge/lexers/nginx.rb +71 -0
  132. data/lib/rouge/lexers/nim.rb +152 -0
  133. data/lib/rouge/lexers/objective_c.rb +197 -0
  134. data/lib/rouge/lexers/ocaml.rb +111 -0
  135. data/lib/rouge/lexers/perl.rb +197 -0
  136. data/lib/rouge/lexers/php.rb +173 -0
  137. data/lib/rouge/lexers/php/builtins.rb +204 -0
  138. data/lib/rouge/lexers/plain_text.rb +25 -0
  139. data/lib/rouge/lexers/powershell.rb +96 -0
  140. data/lib/rouge/lexers/prolog.rb +64 -0
  141. data/lib/rouge/lexers/properties.rb +55 -0
  142. data/lib/rouge/lexers/puppet.rb +128 -0
  143. data/lib/rouge/lexers/python.rb +228 -0
  144. data/lib/rouge/lexers/qml.rb +72 -0
  145. data/lib/rouge/lexers/r.rb +56 -0
  146. data/lib/rouge/lexers/racket.rb +542 -0
  147. data/lib/rouge/lexers/ruby.rb +415 -0
  148. data/lib/rouge/lexers/rust.rb +191 -0
  149. data/lib/rouge/lexers/sass.rb +74 -0
  150. data/lib/rouge/lexers/sass/common.rb +180 -0
  151. data/lib/rouge/lexers/scala.rb +142 -0
  152. data/lib/rouge/lexers/scheme.rb +112 -0
  153. data/lib/rouge/lexers/scss.rb +34 -0
  154. data/lib/rouge/lexers/sed.rb +170 -0
  155. data/lib/rouge/lexers/shell.rb +152 -0
  156. data/lib/rouge/lexers/slim.rb +228 -0
  157. data/lib/rouge/lexers/smalltalk.rb +116 -0
  158. data/lib/rouge/lexers/sml.rb +347 -0
  159. data/lib/rouge/lexers/sql.rb +140 -0
  160. data/lib/rouge/lexers/swift.rb +144 -0
  161. data/lib/rouge/lexers/tcl.rb +192 -0
  162. data/lib/rouge/lexers/tex.rb +72 -0
  163. data/lib/rouge/lexers/toml.rb +71 -0
  164. data/lib/rouge/lexers/tulip.rb +75 -0
  165. data/lib/rouge/lexers/vb.rb +164 -0
  166. data/lib/rouge/lexers/viml.rb +101 -0
  167. data/lib/rouge/lexers/viml/keywords.rb +12 -0
  168. data/lib/rouge/lexers/xml.rb +59 -0
  169. data/lib/rouge/lexers/yaml.rb +364 -0
  170. data/lib/rouge/plugins/redcarpet.rb +30 -0
  171. data/lib/rouge/regex_lexer.rb +439 -0
  172. data/lib/rouge/template_lexer.rb +22 -0
  173. data/lib/rouge/text_analyzer.rb +48 -0
  174. data/lib/rouge/theme.rb +195 -0
  175. data/lib/rouge/themes/base16.rb +130 -0
  176. data/lib/rouge/themes/colorful.rb +67 -0
  177. data/lib/rouge/themes/github.rb +71 -0
  178. data/lib/rouge/themes/molokai.rb +82 -0
  179. data/lib/rouge/themes/monokai.rb +92 -0
  180. data/lib/rouge/themes/monokai_sublime.rb +90 -0
  181. data/lib/rouge/themes/thankful_eyes.rb +71 -0
  182. data/lib/rouge/token.rb +182 -0
  183. data/lib/rouge/util.rb +101 -0
  184. data/lib/rouge/version.rb +7 -0
  185. metadata +231 -0
@@ -0,0 +1,287 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Liquid < RegexLexer
6
+ title "Liquid"
7
+ desc 'Liquid is a templating engine for Ruby (liquidmarkup.org)'
8
+ tag 'liquid'
9
+ filenames '*.liquid'
10
+
11
+ state :root do
12
+ rule /[^\{]+/, Text
13
+
14
+ rule /(\{%)(\s*)/ do
15
+ groups Punctuation, Text::Whitespace
16
+ push :tag_or_block
17
+ end
18
+
19
+ rule /(\{\{)(\s*)/ do
20
+ groups Punctuation, Text::Whitespace
21
+ push :output
22
+ end
23
+
24
+ rule /\{/, Text
25
+ end
26
+
27
+ state :tag_or_block do
28
+ # builtin logic blocks
29
+ rule /(if|unless|elsif|case)(?=\s+)/, Keyword::Reserved, :condition
30
+
31
+ rule /(when)(\s+)/ do
32
+ groups Keyword::Reserved, Text::Whitespace
33
+ push :when
34
+ end
35
+
36
+ rule /(else)(\s*)(%\})/ do
37
+ groups Keyword::Reserved, Text::Whitespace, Punctuation
38
+ pop!
39
+ end
40
+
41
+ # other builtin blocks
42
+ rule /(capture)(\s+)([^\s%]+)(\s*)(%\})/ do
43
+ groups Name::Tag, Text::Whitespace, Name::Attribute, Text::Whitespace, Punctuation
44
+ pop!
45
+ end
46
+
47
+ rule /(comment)(\s*)(%\})/ do
48
+ groups Name::Tag, Text::Whitespace, Punctuation
49
+ push :comment
50
+ end
51
+
52
+ rule /(raw)(\s*)(%\})/ do
53
+ groups Name::Tag, Text::Whitespace, Punctuation
54
+ push :raw
55
+ end
56
+
57
+ rule /assign/, Name::Tag, :assign
58
+ rule /include/, Name::Tag, :include
59
+
60
+ # end of block
61
+ rule /(end(case|unless|if))(\s*)(%\})/ do
62
+ groups Keyword::Reserved, nil, Text::Whitespace, Punctuation
63
+ pop!
64
+ end
65
+
66
+ rule /(end([^\s%]+))(\s*)(%\})/ do
67
+ groups Name::Tag, nil, Text::Whitespace, Punctuation
68
+ pop!
69
+ end
70
+
71
+ # builtin tags
72
+ rule /(cycle)(\s+)(([^\s:]*)(:))?(\s*)/ do |m|
73
+ token Name::Tag, m[1]
74
+ token Text::Whitespace, m[2]
75
+
76
+ if m[4] =~ /'[^']*'/
77
+ token Str::Single, m[4]
78
+ elsif m[4] =~ /"[^"]*"/
79
+ token Str::Double, m[4]
80
+ else
81
+ token Name::Attribute, m[4]
82
+ end
83
+
84
+ token Punctuation, m[5]
85
+ token Text::Whitespace, m[6]
86
+
87
+ push :variable_tag_markup
88
+ end
89
+
90
+ # other tags or blocks
91
+ rule /([^\s%]+)(\s*)/ do
92
+ groups Name::Tag, Text::Whitespace
93
+ push :tag_markup
94
+ end
95
+ end
96
+
97
+ state :output do
98
+ mixin :whitespace
99
+ mixin :generic
100
+
101
+ rule /\}\}/, Punctuation, :pop!
102
+ rule /\|/, Punctuation, :filters
103
+ end
104
+
105
+ state :filters do
106
+ mixin :whitespace
107
+
108
+ rule (/\}\}/) { token Punctuation; reset_stack }
109
+
110
+ rule /([^\s\|:]+)(:?)(\s*)/ do
111
+ groups Name::Function, Punctuation, Text::Whitespace
112
+ push :filter_markup
113
+ end
114
+ end
115
+
116
+ state :filter_markup do
117
+ rule /\|/, Punctuation, :pop!
118
+
119
+ mixin :end_of_tag
120
+ mixin :end_of_block
121
+ mixin :default_param_markup
122
+ end
123
+
124
+ state :condition do
125
+ mixin :end_of_block
126
+ mixin :whitespace
127
+
128
+ rule /([=!><]=?)/, Operator
129
+
130
+ rule /\b((!)|(not\b))/ do
131
+ groups nil, Operator, Operator::Word
132
+ end
133
+
134
+ rule /(contains)/, Operator::Word
135
+
136
+ mixin :generic
137
+ mixin :whitespace
138
+ end
139
+
140
+ state :when do
141
+ mixin :end_of_block
142
+ mixin :whitespace
143
+ mixin :generic
144
+ end
145
+
146
+ state :operator do
147
+ rule /(\s*)((=|!|>|<)=?)(\s*)/ do
148
+ groups Text::Whitespace, Operator, nil, Text::Whitespace
149
+ pop!
150
+ end
151
+
152
+ rule /(\s*)(\bcontains\b)(\s*)/ do
153
+ groups Text::Whitespace, Operator::Word, Text::Whitespace
154
+ pop!
155
+ end
156
+ end
157
+
158
+ state :end_of_tag do
159
+ rule (/\}\}/) { token Punctuation; reset_stack }
160
+ end
161
+
162
+ state :end_of_block do
163
+ rule (/%\}/) { token Punctuation; reset_stack }
164
+ end
165
+
166
+ # states for unknown markup
167
+ state :param_markup do
168
+ mixin :whitespace
169
+ mixin :string
170
+
171
+ rule /([^\s=:]+)(\s*)(=|:)/ do
172
+ groups Name::Attribute, Text::Whitespace, Operator
173
+ end
174
+
175
+ rule /(\{\{)(\s*)([^\s\}])(\s*)(\}\})/ do
176
+ groups Punctuation, Text::Whitespace, nil, Text::Whitespace, Punctuation
177
+ end
178
+
179
+ mixin :number
180
+ mixin :keyword
181
+
182
+ rule /,/, Punctuation
183
+ end
184
+
185
+ state :default_param_markup do
186
+ mixin :param_markup
187
+ rule /./, Text
188
+ end
189
+
190
+ state :variable_param_markup do
191
+ mixin :param_markup
192
+ mixin :variable
193
+ rule /./, Text
194
+ end
195
+
196
+ state :tag_markup do
197
+ mixin :end_of_block
198
+ mixin :default_param_markup
199
+ end
200
+
201
+ state :variable_tag_markup do
202
+ mixin :end_of_block
203
+ mixin :variable_param_markup
204
+ end
205
+
206
+ # states for different values types
207
+ state :keyword do
208
+ rule /\b(false|true)\b/, Keyword::Constant
209
+ end
210
+
211
+ state :variable do
212
+ rule /\.(?=\w)/, Punctuation
213
+ rule /[a-zA-Z_]\w*/, Name::Variable
214
+ end
215
+
216
+ state :string do
217
+ rule /'[^']*'/, Str::Single
218
+ rule /"[^"]*"/, Str::Double
219
+ end
220
+
221
+ state :number do
222
+ rule /\d+\.\d+/, Num::Float
223
+ rule /\d+/, Num::Integer
224
+ end
225
+
226
+ state :array_index do
227
+ rule /\[/, Punctuation
228
+ rule /\]/, Punctuation
229
+ end
230
+
231
+ state :generic do
232
+ mixin :array_index
233
+ mixin :keyword
234
+ mixin :string
235
+ mixin :variable
236
+ mixin :number
237
+ end
238
+
239
+ state :whitespace do
240
+ rule /[ \t]+/, Text::Whitespace
241
+ end
242
+
243
+ state :comment do
244
+ rule /(\{%)(\s*)(endcomment)(\s*)(%\})/ do
245
+ groups Punctuation, Text::Whitespace, Name::Tag, Text::Whitespace, Punctuation
246
+ reset_stack
247
+ end
248
+
249
+ rule /./, Comment
250
+ end
251
+
252
+ state :raw do
253
+ rule /[^\{]+/, Text
254
+
255
+ rule /(\{%)(\s*)(endraw)(\s*)(%\})/ do
256
+ groups Punctuation, Text::Whitespace, Name::Tag, Text::Whitespace, Punctuation
257
+ reset_stack
258
+ end
259
+
260
+ rule /\{/, Text
261
+ end
262
+
263
+ state :assign do
264
+ mixin :whitespace
265
+ mixin :end_of_block
266
+
267
+ rule /(\s*)(=)(\s*)/ do
268
+ groups Text::Whitespace, Operator, Text::Whitespace
269
+ end
270
+
271
+ rule /\|/, Punctuation, :filters
272
+
273
+ mixin :generic
274
+ end
275
+
276
+ state :include do
277
+ mixin :whitespace
278
+
279
+ rule /([^\.]+)(\.)(html|liquid)/ do
280
+ groups Name::Attribute, Punctuation, Name::Attribute
281
+ end
282
+
283
+ mixin :variable_tag_markup
284
+ end
285
+ end
286
+ end
287
+ end
@@ -0,0 +1,33 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class LiterateCoffeescript < RegexLexer
6
+ tag 'literate_coffeescript'
7
+ title "Literate CoffeeScript"
8
+ desc 'Literate coffeescript'
9
+ aliases 'litcoffee'
10
+ filenames '*.litcoffee'
11
+
12
+ def markdown
13
+ @markdown ||= Markdown.new(options)
14
+ end
15
+
16
+ def coffee
17
+ @coffee ||= Coffeescript.new(options)
18
+ end
19
+
20
+ start { markdown.reset!; coffee.reset! }
21
+
22
+ state :root do
23
+ rule /^( .*?\n)+/m do
24
+ delegate coffee
25
+ end
26
+
27
+ rule /^([ ]{0,3}(\S.*?|)\n)*/m do
28
+ delegate markdown
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,36 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class LiterateHaskell < RegexLexer
6
+ title "Literate Haskell"
7
+ desc 'Literate haskell'
8
+ tag 'literate_haskell'
9
+ aliases 'lithaskell', 'lhaskell', 'lhs'
10
+ filenames '*.lhs'
11
+ mimetypes 'text/x-literate-haskell'
12
+
13
+ def haskell
14
+ @haskell ||= Haskell.new(options)
15
+ end
16
+
17
+ start { haskell.reset! }
18
+
19
+ # TODO: support TeX versions as well.
20
+ state :root do
21
+ rule /\s*?\n(?=>)/, Text, :code
22
+ rule /.*?\n/, Text
23
+ rule /.+\z/, Text
24
+ end
25
+
26
+ state :code do
27
+ rule /(>)( .*?(\n|\z))/ do |m|
28
+ token Name::Label, m[1]
29
+ delegate haskell, m[2]
30
+ end
31
+
32
+ rule /\s*\n(?=\s*[^>])/, Text, :pop!
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,84 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class LLVM < RegexLexer
6
+ title "LLVM"
7
+ desc 'The LLVM Compiler Infrastructure (http://llvm.org/)'
8
+ tag 'llvm'
9
+
10
+ filenames '*.ll'
11
+ mimetypes 'text/x-llvm'
12
+
13
+ def self.analyze_text(text)
14
+ return 0.1 if text =~ /\A%\w+\s=\s/
15
+ end
16
+
17
+ string = /"[^"]*?"/
18
+ identifier = /([-a-zA-Z$._][-a-zA-Z$._0-9]*|#{string})/
19
+
20
+ state :basic do
21
+ rule /;.*?$/, Comment::Single
22
+ rule /\s+/, Text
23
+
24
+ rule /#{identifier}\s*:/, Name::Label
25
+
26
+ rule /@(#{identifier}|\d+)/, Name::Variable::Global
27
+ rule /(%|!)#{identifier}/, Name::Variable
28
+ rule /(%|!)\d+/, Name::Variable
29
+
30
+ rule /c?#{string}/, Str
31
+
32
+ rule /0[xX][a-fA-F0-9]+/, Num
33
+ rule /-?\d+(?:[.]\d+)?(?:[eE][-+]?\d+(?:[.]\d+)?)?/, Num
34
+
35
+ rule /[=<>{}\[\]()*.,!]|x/, Punctuation
36
+ end
37
+
38
+ builtin_types = %w(
39
+ void float double half x86_fp80 x86mmx fp128 ppc_fp128 label metadata
40
+ )
41
+
42
+ state :types do
43
+ rule /i[1-9]\d*/, Keyword::Type
44
+ rule /#{builtin_types.join('|')}/, Keyword::Type
45
+ end
46
+
47
+ builtin_keywords = %w(
48
+ begin end true false declare define global constant personality private
49
+ landingpad linker_private internal available_externally linkonce_odr
50
+ linkonce weak weak_odr appending dllimport dllexport common default
51
+ hidden protected extern_weak external thread_local zeroinitializer
52
+ undef null to tail target triple datalayout volatile nuw nsw nnan ninf
53
+ nsz arcp fast exact inbounds align addrspace section alias module asm
54
+ sideeffect gc dbg ccc fastcc coldcc x86_stdcallcc x86_fastcallcc
55
+ arm_apcscc arm_aapcscc arm_aapcs_vfpcc ptx_device ptx_kernel cc
56
+ c signext zeroext inreg sret nounwind noreturn noalias nocapture byval
57
+ nest readnone readonly inlinehint noinline alwaysinline optsize ssp
58
+ sspreq noredzone noimplicitfloat naked type opaque eq ne slt sgt sle
59
+ sge ult ugt ule uge oeq one olt ogt ole oge ord uno unnamed_addr ueq
60
+ une uwtable x
61
+ )
62
+
63
+ builtin_instructions = %w(
64
+ add fadd sub fsub mul fmul udiv sdiv fdiv urem srem frem shl lshr ashr
65
+ and or xor icmp fcmp phi call catch trunc zext sext fptrunc fpext
66
+ uitofp sitofp fptoui fptosi inttoptr ptrtoint bitcast select va_arg ret
67
+ br switch invoke unwind unreachable malloc alloca free load store
68
+ getelementptr extractelement insertelement shufflevector getresult
69
+ extractvalue insertvalue cleanup resume
70
+ )
71
+
72
+ state :keywords do
73
+ rule /#{builtin_instructions.join('|')}/, Keyword
74
+ rule /#{builtin_keywords.join('|')}/, Keyword
75
+ end
76
+
77
+ state :root do
78
+ mixin :basic
79
+ mixin :keywords
80
+ mixin :types
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,122 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Lua < RegexLexer
6
+ title "Lua"
7
+ desc "Lua (http://www.lua.org)"
8
+ tag 'lua'
9
+ filenames '*.lua', '*.wlua'
10
+
11
+ mimetypes 'text/x-lua', 'application/x-lua'
12
+
13
+ def initialize(opts={})
14
+ @function_highlighting = opts.delete(:function_highlighting) { true }
15
+ @disabled_modules = opts.delete(:disabled_modules) { [] }
16
+ super(opts)
17
+ end
18
+
19
+ def self.analyze_text(text)
20
+ return 1 if text.shebang? 'lua'
21
+ end
22
+
23
+ def self.builtins
24
+ load Pathname.new(__FILE__).dirname.join('lua/builtins.rb')
25
+ self.builtins
26
+ end
27
+
28
+ def builtins
29
+ return [] unless @function_highlighting
30
+
31
+ @builtins ||= Set.new.tap do |builtins|
32
+ self.class.builtins.each do |mod, fns|
33
+ next if @disabled_modules.include? mod
34
+ builtins.merge(fns)
35
+ end
36
+ end
37
+ end
38
+
39
+ state :root do
40
+ # lua allows a file to start with a shebang
41
+ rule %r(#!(.*?)$), Comment::Preproc
42
+ rule //, Text, :base
43
+ end
44
+
45
+ state :base do
46
+ rule %r(--\[(=*)\[.*?\]\1\])m, Comment::Multiline
47
+ rule %r(--.*$), Comment::Single
48
+
49
+ rule %r((?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?'), Num::Float
50
+ rule %r((?i)\d+e[+-]?\d+), Num::Float
51
+ rule %r((?i)0x[0-9a-f]*), Num::Hex
52
+ rule %r(\d+), Num::Integer
53
+
54
+ rule %r(\n), Text
55
+ rule %r([^\S\n]), Text
56
+ # multiline strings
57
+ rule %r(\[(=*)\[.*?\]\1\])m, Str
58
+
59
+ rule %r((==|~=|<=|>=|\.\.\.|\.\.|[=+\-*/%^<>#])), Operator
60
+ rule %r([\[\]\{\}\(\)\.,:;]), Punctuation
61
+ rule %r((and|or|not)\b), Operator::Word
62
+
63
+ rule %r((break|do|else|elseif|end|for|if|in|repeat|return|then|until|while)\b), Keyword
64
+ rule %r((local)\b), Keyword::Declaration
65
+ rule %r((true|false|nil)\b), Keyword::Constant
66
+
67
+ rule %r((function)\b), Keyword, :function_name
68
+
69
+ rule %r([A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?) do |m|
70
+ name = m[0]
71
+ if self.builtins.include?(name)
72
+ token Name::Builtin
73
+ elsif name =~ /\./
74
+ a, b = name.split('.', 2)
75
+ token Name, a
76
+ token Punctuation, '.'
77
+ token Name, b
78
+ else
79
+ token Name
80
+ end
81
+ end
82
+
83
+ rule %r('), Str::Single, :escape_sqs
84
+ rule %r("), Str::Double, :escape_dqs
85
+ end
86
+
87
+ state :function_name do
88
+ rule /\s+/, Text
89
+ rule %r((?:([A-Za-z_][A-Za-z0-9_]*)(\.))?([A-Za-z_][A-Za-z0-9_]*)) do
90
+ groups Name::Class, Punctuation, Name::Function
91
+ pop!
92
+ end
93
+ # inline function
94
+ rule %r(\(), Punctuation, :pop!
95
+ end
96
+
97
+ state :escape_sqs do
98
+ mixin :string_escape
99
+ mixin :sqs
100
+ end
101
+
102
+ state :escape_dqs do
103
+ mixin :string_escape
104
+ mixin :dqs
105
+ end
106
+
107
+ state :string_escape do
108
+ rule %r(\\([abfnrtv\\"']|\d{1,3})), Str::Escape
109
+ end
110
+
111
+ state :sqs do
112
+ rule %r('), Str::Single, :pop!
113
+ rule %r([^']+), Str::Single
114
+ end
115
+
116
+ state :dqs do
117
+ rule %r("), Str::Double, :pop!
118
+ rule %r([^"]+), Str::Double
119
+ end
120
+ end
121
+ end
122
+ end