rouge 3.5.1 → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rouge.rb +1 -0
  3. data/lib/rouge/cli.rb +19 -11
  4. data/lib/rouge/demos/openedge +4 -0
  5. data/lib/rouge/demos/powershell +12 -48
  6. data/lib/rouge/demos/xojo +2 -1
  7. data/lib/rouge/demos/xpath +2 -0
  8. data/lib/rouge/demos/xquery +22 -0
  9. data/lib/rouge/formatters/html.rb +18 -2
  10. data/lib/rouge/formatters/html_line_table.rb +51 -0
  11. data/lib/rouge/guessers/modeline.rb +1 -1
  12. data/lib/rouge/lexers/apache.rb +1 -1
  13. data/lib/rouge/lexers/bpf.rb +12 -12
  14. data/lib/rouge/lexers/ceylon.rb +5 -5
  15. data/lib/rouge/lexers/docker.rb +2 -2
  16. data/lib/rouge/lexers/elixir.rb +5 -2
  17. data/lib/rouge/lexers/elm.rb +1 -1
  18. data/lib/rouge/lexers/fsharp.rb +4 -4
  19. data/lib/rouge/lexers/glsl.rb +1 -1
  20. data/lib/rouge/lexers/http.rb +1 -1
  21. data/lib/rouge/lexers/idlang.rb +1 -1
  22. data/lib/rouge/lexers/json.rb +1 -1
  23. data/lib/rouge/lexers/jsp.rb +3 -3
  24. data/lib/rouge/lexers/liquid.rb +23 -0
  25. data/lib/rouge/lexers/magik.rb +2 -1
  26. data/lib/rouge/lexers/make.rb +5 -4
  27. data/lib/rouge/lexers/mosel.rb +43 -43
  28. data/lib/rouge/lexers/nim.rb +2 -1
  29. data/lib/rouge/lexers/nix.rb +1 -1
  30. data/lib/rouge/lexers/openedge.rb +429 -0
  31. data/lib/rouge/lexers/perl.rb +12 -14
  32. data/lib/rouge/lexers/powershell.rb +181 -635
  33. data/lib/rouge/lexers/ruby.rb +2 -2
  34. data/lib/rouge/lexers/scala.rb +1 -1
  35. data/lib/rouge/lexers/shell.rb +1 -1
  36. data/lib/rouge/lexers/swift.rb +4 -4
  37. data/lib/rouge/lexers/tex.rb +1 -1
  38. data/lib/rouge/lexers/toml.rb +1 -1
  39. data/lib/rouge/lexers/vala.rb +1 -1
  40. data/lib/rouge/lexers/vhdl.rb +1 -1
  41. data/lib/rouge/lexers/wollok.rb +1 -1
  42. data/lib/rouge/lexers/xml.rb +1 -1
  43. data/lib/rouge/lexers/xojo.rb +4 -4
  44. data/lib/rouge/lexers/xpath.rb +332 -0
  45. data/lib/rouge/lexers/xquery.rb +145 -0
  46. data/lib/rouge/lexers/yaml.rb +5 -3
  47. data/lib/rouge/regex_lexer.rb +14 -13
  48. data/lib/rouge/tex_theme_renderer.rb +2 -2
  49. data/lib/rouge/themes/monokai_sublime.rb +2 -1
  50. data/lib/rouge/themes/pastie.rb +1 -1
  51. data/lib/rouge/util.rb +2 -2
  52. data/lib/rouge/version.rb +1 -1
  53. metadata +10 -3
@@ -11,7 +11,7 @@ module Rouge
11
11
  filenames '*.rb', '*.ruby', '*.rbw', '*.rake', '*.gemspec', '*.podspec',
12
12
  'Rakefile', 'Guardfile', 'Gemfile', 'Capfile', 'Podfile',
13
13
  'Vagrantfile', '*.ru', '*.prawn', 'Berksfile', '*.arb',
14
- 'Dangerfile'
14
+ 'Dangerfile', 'Fastfile', 'Deliverfile', 'Appfile'
15
15
 
16
16
  mimetypes 'text/x-ruby', 'application/x-ruby'
17
17
 
@@ -183,7 +183,7 @@ module Rouge
183
183
 
184
184
  mixin :strings
185
185
 
186
- rule %r/(?:#{keywords.join('|')})\b/, Keyword, :expr_start
186
+ rule %r/(?:#{keywords.join('|')})(?=\W|$)/, Keyword, :expr_start
187
187
  rule %r/(?:#{keywords_pseudo.join('|')})\b/, Keyword::Pseudo, :expr_start
188
188
 
189
189
  rule %r(
@@ -78,7 +78,7 @@ module Rouge
78
78
  (#{keywords.join("|")})\b|
79
79
  (<[%:-]|=>|>:|[#=@_\u21D2\u2190])(\b|(?=\s)|$)
80
80
  )x, Keyword
81
- rule %r/:(?!#{op})/, Keyword, :type
81
+ rule %r/:(?!#{op})/, Keyword, :type
82
82
  rule %r/(true|false|null)\b/, Keyword::Constant
83
83
  rule %r/(import|package)(\s+)/ do
84
84
  groups Keyword, Text
@@ -52,7 +52,7 @@ module Rouge
52
52
  rule %r/\b(#{BUILTINS})\s*\b(?!(\.|-))/, Name::Builtin
53
53
  rule %r/[.](?=\s)/, Name::Builtin
54
54
 
55
- rule %r/(\b\w+)(=)/ do |m|
55
+ rule %r/(\b\w+)(=)/ do
56
56
  groups Name::Variable, Operator
57
57
  end
58
58
 
@@ -97,13 +97,13 @@ module Rouge
97
97
  groups Keyword::Declaration, Error, Keyword::Declaration
98
98
  end
99
99
  end
100
-
100
+
101
101
  rule %r/#available\([^)]+\)/, Keyword::Declaration
102
-
102
+
103
103
  rule %r/(#(?:selector|keyPath)\()([^)]+?(?:[(].*?[)])?)(\))/ do
104
104
  groups Keyword::Declaration, Name::Function, Keyword::Declaration
105
105
  end
106
-
106
+
107
107
  rule %r/#(line|file|column|function|dsohandle)/, Keyword::Declaration
108
108
 
109
109
  rule %r/(let|var)\b(\s*)(#{id})/ do
@@ -122,7 +122,7 @@ module Rouge
122
122
  token Name::Function
123
123
  end
124
124
  end
125
-
125
+
126
126
  rule %r/as[?!]?(?=\s)/, Keyword
127
127
  rule %r/try[!]?(?=\s)/, Keyword
128
128
 
@@ -30,7 +30,7 @@ module Rouge
30
30
  rule %r/\$/, Punctuation, :inlinemath
31
31
  rule %r/\\(begin|end)\{.*?\}/, Name::Tag
32
32
 
33
- rule %r/(\\verb)\b(\S)(.*?)(\2)/ do |m|
33
+ rule %r/(\\verb)\b(\S)(.*?)(\2)/ do
34
34
  groups Name::Builtin, Keyword::Pseudo, Str::Other, Keyword::Pseudo
35
35
  end
36
36
 
@@ -8,7 +8,7 @@ module Rouge
8
8
  desc 'the TOML configuration format (https://github.com/mojombo/toml)'
9
9
  tag 'toml'
10
10
 
11
- filenames '*.toml'
11
+ filenames '*.toml', 'Pipfile'
12
12
  mimetypes 'text/x-toml'
13
13
 
14
14
  identifier = /\S+/
@@ -24,7 +24,7 @@ module Rouge
24
24
  )
25
25
 
26
26
  keywords_type = %w(
27
- bool char double float int int8 int16 int32 int64 long short size_t
27
+ bool char double float int int8 int16 int32 int64 long short size_t
28
28
  ssize_t string unichar uint uint8 uint16 uint32 uint64 ulong ushort
29
29
  )
30
30
 
@@ -59,7 +59,7 @@ module Rouge
59
59
 
60
60
  # Find Attributes
61
61
  rule %r/'#{id}/i, Name::Attribute
62
-
62
+
63
63
  # Punctuations
64
64
  rule %r/[(),:;]/, Punctuation
65
65
 
@@ -1,4 +1,4 @@
1
- # -*- coding: utf-8 -*- #
1
+ # -*- coding: utf-8 -*- #
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Rouge
@@ -9,7 +9,7 @@ module Rouge
9
9
  tag 'xml'
10
10
  filenames '*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd', '*.wsdl', '*.svg',
11
11
  '*.plist'
12
- mimetypes 'text/xml', 'application/xml', 'image/svg+xml',
12
+ mimetypes 'text/xml', 'application/xml', 'image/svg+xml',
13
13
  'application/rss+xml', 'application/atom+xml'
14
14
 
15
15
  def self.detect?(text)
@@ -8,7 +8,7 @@ module Rouge
8
8
  desc "Xojo"
9
9
  tag 'xojo'
10
10
  aliases 'realbasic'
11
- filenames '*.xojo_code', '*.xojo_window', '*.xojo_toolbar', '*.xojo_menu'
11
+ filenames '*.xojo_code', '*.xojo_window', '*.xojo_toolbar', '*.xojo_menu', '*.xojo_image', '*.rbbas', '*.rbfrm', '*.rbmnu', '*.rbres', '*.rbtbar'
12
12
 
13
13
  keywords = %w(
14
14
  addhandler aggregates array asc assigns attributes begin break
@@ -30,15 +30,15 @@ module Rouge
30
30
  )
31
31
 
32
32
  operator_words = %w(
33
- addressof and as in is isa mod not or xor
33
+ addressof weakaddressof and as in is isa mod not or xor
34
34
  )
35
35
 
36
36
  state :root do
37
37
  rule %r/\s+/, Text::Whitespace
38
38
 
39
39
  rule %r/rem\b.*?$/i, Comment::Single
40
- rule %r(//.*$), Comment::Single
41
- rule %r/\#tag Note.*\#tag EndNote/m, Comment::Preproc
40
+ rule %r([//'].*$), Comment::Single
41
+ rule %r/\#tag Note.*?\#tag EndNote/mi, Comment::Preproc
42
42
  rule %r/\s*[#].*$/x, Comment::Preproc
43
43
 
44
44
  rule %r/".*?"/, Literal::String::Double
@@ -0,0 +1,332 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class XPath < RegexLexer
7
+ title 'XPath'
8
+ desc 'XML Path Language (XPath) 3.1'
9
+ tag 'xpath'
10
+ filenames '*.xpath'
11
+
12
+ # Terminal literals:
13
+ # https://www.w3.org/TR/xpath-31/#terminal-symbols
14
+ def self.digits
15
+ @digits ||= %r/[0-9]+/
16
+ end
17
+
18
+ def self.decimalLiteral
19
+ @decimalLiteral ||= %r/\.#{digits}|#{digits}\.[0-9]*/
20
+ end
21
+
22
+ def self.doubleLiteral
23
+ @doubleLiteral ||= %r/(\.#{digits})|#{digits}(\.[0-9]*)?[eE][+-]?#{digits}/
24
+ end
25
+
26
+ def self.stringLiteral
27
+ @stringLiteral ||= %r/("(("")|[^"])*")|('(('')|[^'])*')/
28
+ end
29
+
30
+ def self.ncName
31
+ @ncName ||= %r/[a-z_][a-z_\-.0-9]*/i
32
+ end
33
+
34
+ def self.qName
35
+ @qName ||= %r/(?:#{ncName})(?::#{ncName})?/
36
+ end
37
+
38
+ def self.uriQName
39
+ @uriQName ||= %r/Q\{[^{}]*\}#{ncName}/
40
+ end
41
+
42
+ def self.eqName
43
+ @eqName ||= %r/(?:#{uriQName}|#{qName})/
44
+ end
45
+
46
+ def self.commentStart
47
+ @commentStart ||= %r/\(:/
48
+ end
49
+
50
+ def self.openParen
51
+ @openParen ||= %r/\((?!:)/
52
+ end
53
+
54
+ # Terminal symbols:
55
+ # https://www.w3.org/TR/xpath-30/#id-terminal-delimitation
56
+ def self.kindTest
57
+ @kindTest ||= Regexp.union %w(
58
+ element attribute schema-element schema-attribute
59
+ comment text node document-node namespace-node
60
+ )
61
+ end
62
+
63
+ def self.kindTestForPI
64
+ @kindTestForPI ||= Regexp.union %w(processing-instruction)
65
+ end
66
+
67
+ def self.axes
68
+ @axes ||= Regexp.union %w(
69
+ child descendant attribute self descendant-or-self
70
+ following-sibling following namespace
71
+ parent ancestor preceding-sibling preceding ancestor-or-self
72
+ )
73
+ end
74
+
75
+ def self.operators
76
+ @operators ||= Regexp.union %w(, => = := : >= >> > <= << < - * != + // / || |)
77
+ end
78
+
79
+ def self.keywords
80
+ @keywords ||= Regexp.union %w(let for some every if then else return in satisfies)
81
+ end
82
+
83
+ def self.word_operators
84
+ @word_operators ||= Regexp.union %w(
85
+ and or eq ge gt le lt ne is
86
+ div mod idiv
87
+ intersect except union
88
+ to
89
+ )
90
+ end
91
+
92
+ def self.constructorTypes
93
+ @constructorTypes ||= Regexp.union %w(function array map empty-sequence)
94
+ end
95
+
96
+ # Mixin states:
97
+
98
+ state :commentsAndWhitespace do
99
+ rule XPath.commentStart, Comment, :comment
100
+ rule %r/\s+/m, Text::Whitespace
101
+ end
102
+
103
+ # Lexical states:
104
+ # https://www.w3.org/TR/xquery-xpath-parsing/#XPath-lexical-states
105
+ # https://lists.w3.org/Archives/Public/public-qt-comments/2004Aug/0127.html
106
+ # https://www.w3.org/TR/xpath-30/#id-revision-log
107
+ # https://www.w3.org/TR/xpath-31/#id-revision-log
108
+
109
+ state :root do
110
+ mixin :commentsAndWhitespace
111
+
112
+ # Literals
113
+ rule XPath.doubleLiteral, Num::Float
114
+ rule XPath.decimalLiteral, Num::Float
115
+ rule XPath.digits, Num
116
+ rule XPath.stringLiteral, Literal::String
117
+
118
+ # Variables
119
+ rule %r/\$/, Name::Variable, :varname
120
+
121
+ # Operators
122
+ rule XPath.operators, Operator
123
+ rule %r/#{XPath.word_operators}\b/, Operator::Word
124
+ rule %r/#{XPath.keywords}\b/, Keyword
125
+ rule %r/[?,{}()\[\]]/, Punctuation
126
+
127
+ # Functions
128
+ rule %r/(function)(\s*)(#{XPath.openParen})/ do # function declaration
129
+ groups Keyword, Text::Whitespace, Punctuation
130
+ end
131
+ rule %r/(map|array|empty-sequence)/, Keyword # constructors
132
+ rule %r/(#{XPath.kindTest})(\s*)(#{XPath.openParen})/ do # kindtest
133
+ groups Keyword, Text::Whitespace, Punctuation
134
+ push :kindtest
135
+ end
136
+ rule %r/(#{XPath.kindTestForPI})(\s*)(#{XPath.openParen})/ do # processing instruction kindtest
137
+ groups Keyword, Text::Whitespace, Punctuation
138
+ push :kindtestforpi
139
+ end
140
+ rule %r/(#{XPath.eqName})(\s*)(#{XPath.openParen})/ do # function call
141
+ groups Name::Function, Text::Whitespace, Punctuation
142
+ end
143
+ rule %r/(#{XPath.eqName})(\s*)(#)(\s*)(\d+)/ do # namedFunctionRef
144
+ groups Name::Function, Text::Whitespace, Name::Function, Text::Whitespace, Name::Function
145
+ end
146
+
147
+ # Type commands
148
+ rule %r/(cast|castable)(\s+)(as)/ do
149
+ groups Keyword, Text::Whitespace, Keyword
150
+ push :singletype
151
+ end
152
+ rule %r/(treat)(\s+)(as)/ do
153
+ groups Keyword, Text::Whitespace, Keyword
154
+ push :itemtype
155
+ end
156
+ rule %r/(instance)(\s+)(of)/ do
157
+ groups Keyword, Text::Whitespace, Keyword
158
+ push :itemtype
159
+ end
160
+ rule %r/(as)\b/ do
161
+ token Keyword
162
+ push :itemtype
163
+ end
164
+
165
+ # Paths
166
+ rule %r/(#{XPath.ncName})(\s*)(:)(\s*)(\*)/ do
167
+ groups Name::Tag, Text::Whitespace, Punctuation, Text::Whitespace, Operator
168
+ end
169
+ rule %r/(\*)(\s*)(:)(\s*)(#{XPath.ncName})/ do
170
+ groups Operator, Text::Whitespace, Punctuation, Text::Whitespace, Name::Tag
171
+ end
172
+ rule %r/(#{XPath.axes})(\s*)(::)/ do
173
+ groups Keyword, Text::Whitespace, Operator
174
+ end
175
+ rule %r/\.\.|\.|\*/, Operator
176
+ rule %r/@/, Name::Attribute, :attrname
177
+ rule XPath.eqName, Name::Tag
178
+ end
179
+
180
+ state :singletype do
181
+ mixin :commentsAndWhitespace
182
+
183
+ # Type name
184
+ rule XPath.eqName do
185
+ token Keyword::Type
186
+ pop!
187
+ end
188
+ end
189
+
190
+ state :itemtype do
191
+ mixin :commentsAndWhitespace
192
+
193
+ # Type tests
194
+ rule %r/(#{XPath.kindTest})(\s*)(#{XPath.openParen})/ do
195
+ groups Keyword::Type, Text::Whitespace, Punctuation
196
+ # go to kindtest then occurrenceindicator
197
+ goto :occurrenceindicator
198
+ push :kindtest
199
+ end
200
+ rule %r/(#{XPath.kindTestForPI})(\s*)(#{XPath.openParen})/ do
201
+ groups Keyword::Type, Text::Whitespace, Punctuation
202
+ # go to kindtestforpi then occurrenceindicator
203
+ goto :occurrenceindicator
204
+ push :kindtestforpi
205
+ end
206
+ rule %r/(item)(\s*)(#{XPath.openParen})(\s*)(\))/ do
207
+ groups Keyword::Type, Text::Whitespace, Punctuation, Text::Whitespace, Punctuation
208
+ goto :occurrenceindicator
209
+ end
210
+ rule %r/(#{XPath.constructorTypes})(\s*)(#{XPath.openParen})/ do
211
+ groups Keyword::Type, Text::Whitespace, Punctuation
212
+ end
213
+
214
+ # Type commands
215
+ rule %r/(cast|castable)(\s+)(as)/ do
216
+ groups Keyword, Text::Whitespace, Keyword
217
+ goto :singletype
218
+ end
219
+ rule %r/(treat)(\s+)(as)/ do
220
+ groups Keyword, Text::Whitespace, Keyword
221
+ goto :itemtype
222
+ end
223
+ rule %r/(instance)(\s+)(of)/ do
224
+ groups Keyword, Text::Whitespace, Keyword
225
+ goto :itemtype
226
+ end
227
+ rule %r/(as)\b/, Keyword
228
+
229
+ # Operators
230
+ rule XPath.operators do
231
+ token Operator
232
+ pop!
233
+ end
234
+ rule %r/#{XPath.word_operators}\b/ do
235
+ token Operator::Word
236
+ pop!
237
+ end
238
+ rule %r/#{XPath.keywords}\b/ do
239
+ token Keyword
240
+ pop!
241
+ end
242
+ rule %r/[\[),]/ do
243
+ token Punctuation
244
+ pop!
245
+ end
246
+
247
+ # Other types (e.g. xs:double)
248
+ rule XPath.eqName do
249
+ token Keyword::Type
250
+ goto :occurrenceindicator
251
+ end
252
+ end
253
+
254
+ # For pseudo-parameters for the KindTest productions
255
+ state :kindtest do
256
+ mixin :commentsAndWhitespace
257
+
258
+ # Pseudo-parameters:
259
+ rule %r/[?*]/, Operator
260
+ rule %r/,/, Punctuation
261
+ rule %r/(element|schema-element)(\s*)(#{XPath.openParen})/ do
262
+ groups Keyword::Type, Text::Whitespace, Punctuation
263
+ push :kindtest
264
+ end
265
+ rule XPath.eqName, Name::Tag
266
+
267
+ # End of pseudo-parameters
268
+ rule %r/\)/, Punctuation, :pop!
269
+ end
270
+
271
+ # Similar to :kindtest, but recognizes NCNames instead of EQNames
272
+ state :kindtestforpi do
273
+ mixin :commentsAndWhitespace
274
+
275
+ # Pseudo-parameters
276
+ rule XPath.ncName, Name
277
+ rule XPath.stringLiteral, Literal::String
278
+
279
+ # End of pseudo-parameters
280
+ rule %r/\)/, Punctuation, :pop!
281
+ end
282
+
283
+ state :occurrenceindicator do
284
+ mixin :commentsAndWhitespace
285
+
286
+ # Occurrence indicator
287
+ rule %r/[?*+]/ do
288
+ token Operator
289
+ pop!
290
+ end
291
+
292
+ # Otherwise, lex it in root state:
293
+ rule %r/(?![?*+])/ do
294
+ pop!
295
+ end
296
+ end
297
+
298
+ state :varname do
299
+ mixin :commentsAndWhitespace
300
+
301
+ # Function call
302
+ rule %r/(#{XPath.eqName})(\s*)(#{XPath.openParen})/ do
303
+ groups Name::Variable, Text::Whitespace, Punctuation
304
+ pop!
305
+ end
306
+
307
+ # Variable name
308
+ rule XPath.eqName, Name::Variable, :pop!
309
+ end
310
+
311
+ state :attrname do
312
+ mixin :commentsAndWhitespace
313
+
314
+ # Attribute name
315
+ rule XPath.eqName, Name::Attribute, :pop!
316
+ rule %r/\*/, Operator, :pop!
317
+ end
318
+
319
+ state :comment do
320
+ # Comment end
321
+ rule %r/:\)/, Comment, :pop!
322
+
323
+ # Nested comment
324
+ rule XPath.commentStart, Comment, :comment
325
+
326
+ # Comment contents
327
+ rule %r/[^:(]+/m, Comment
328
+ rule %r/[:(]/, Comment
329
+ end
330
+ end
331
+ end
332
+ end