rouge 3.8.0 → 3.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rouge/demos/apex +9 -0
  3. data/lib/rouge/demos/clean +6 -0
  4. data/lib/rouge/demos/csvs +8 -0
  5. data/lib/rouge/demos/eex +1 -0
  6. data/lib/rouge/demos/haxe +5 -0
  7. data/lib/rouge/demos/hql +5 -0
  8. data/lib/rouge/demos/jsl +3 -0
  9. data/lib/rouge/demos/liquid +0 -1
  10. data/lib/rouge/demos/lustre +6 -0
  11. data/lib/rouge/demos/lutin +18 -0
  12. data/lib/rouge/demos/minizinc +23 -0
  13. data/lib/rouge/demos/robot_framework +27 -0
  14. data/lib/rouge/demos/sparql +6 -0
  15. data/lib/rouge/demos/terraform +0 -15
  16. data/lib/rouge/guessers/disambiguation.rb +5 -0
  17. data/lib/rouge/lexer.rb +3 -0
  18. data/lib/rouge/lexers/apex.rb +126 -0
  19. data/lib/rouge/lexers/clean.rb +156 -0
  20. data/lib/rouge/lexers/common_lisp.rb +1 -1
  21. data/lib/rouge/lexers/coq.rb +12 -9
  22. data/lib/rouge/lexers/csvs.rb +44 -0
  23. data/lib/rouge/lexers/eex.rb +52 -0
  24. data/lib/rouge/lexers/elixir.rb +20 -9
  25. data/lib/rouge/lexers/haxe.rb +246 -0
  26. data/lib/rouge/lexers/hql.rb +139 -0
  27. data/lib/rouge/lexers/http.rb +5 -5
  28. data/lib/rouge/lexers/javascript.rb +1 -1
  29. data/lib/rouge/lexers/jsl.rb +55 -0
  30. data/lib/rouge/lexers/json.rb +1 -1
  31. data/lib/rouge/lexers/kotlin.rb +21 -28
  32. data/lib/rouge/lexers/liquid.rb +82 -108
  33. data/lib/rouge/lexers/lustre.rb +79 -0
  34. data/lib/rouge/lexers/lutin.rb +33 -0
  35. data/lib/rouge/lexers/markdown.rb +7 -1
  36. data/lib/rouge/lexers/mason.rb +0 -5
  37. data/lib/rouge/lexers/matlab.rb +4 -2
  38. data/lib/rouge/lexers/matlab/builtins.yml +3515 -0
  39. data/lib/rouge/lexers/minizinc.rb +87 -0
  40. data/lib/rouge/lexers/perl.rb +1 -1
  41. data/lib/rouge/lexers/q.rb +1 -1
  42. data/lib/rouge/lexers/robot_framework.rb +249 -0
  43. data/lib/rouge/lexers/shell.rb +5 -3
  44. data/lib/rouge/lexers/sparql.rb +129 -0
  45. data/lib/rouge/lexers/sql.rb +26 -6
  46. data/lib/rouge/lexers/swift.rb +1 -1
  47. data/lib/rouge/lexers/terraform.rb +8 -0
  48. data/lib/rouge/plugins/redcarpet.rb +7 -1
  49. data/lib/rouge/version.rb +1 -1
  50. metadata +27 -3
  51. data/lib/rouge/lexers/matlab/builtins.rb +0 -13
@@ -7,7 +7,7 @@ module Rouge
7
7
  title "Common Lisp"
8
8
  desc "The Common Lisp variant of Lisp (common-lisp.net)"
9
9
  tag 'common_lisp'
10
- aliases 'cl', 'common-lisp', 'elisp', 'emacs-lisp'
10
+ aliases 'cl', 'common-lisp', 'elisp', 'emacs-lisp', 'lisp'
11
11
 
12
12
  filenames '*.cl', '*.lisp', '*.asd', '*.el' # used for Elisp too
13
13
  mimetypes 'text/x-common-lisp'
@@ -58,7 +58,7 @@ module Rouge
58
58
 
59
59
  def self.keyopts
60
60
  @keyopts ||= Set.new %w(
61
- := => -> /\\ \\/ _ ; :> :
61
+ := => -> /\\ \\/ _ ; :> : ⇒ → ↔ ⇔ ≔ ≡ ∀ ∃ ∧ ∨ ¬ ⊤ ⊥ ⊢ ⊨ ∈
62
62
  )
63
63
  end
64
64
 
@@ -115,14 +115,6 @@ module Rouge
115
115
  end
116
116
  rule %r(/\\), Operator
117
117
  rule %r/\\\//, Operator
118
- rule operator do |m|
119
- match = m[0]
120
- if self.class.keyopts.include? match
121
- token Punctuation
122
- else
123
- token Operator
124
- end
125
- end
126
118
 
127
119
  rule %r/-?\d[\d_]*(.[\d_]*)?(e[+-]?\d[\d_]*)/i, Num::Float
128
120
  rule %r/\d[\d_]*/, Num::Integer
@@ -131,6 +123,17 @@ module Rouge
131
123
  rule %r/'/, Keyword
132
124
  rule %r/"/, Str::Double, :string
133
125
  rule %r/[~?]#{id}/, Name::Variable
126
+
127
+ rule %r/./ do |m|
128
+ match = m[0]
129
+ if self.class.keyopts.include? match
130
+ token Punctuation
131
+ elsif match =~ operator
132
+ token Operator
133
+ else
134
+ token Error
135
+ end
136
+ end
134
137
  end
135
138
 
136
139
  state :comment do
@@ -0,0 +1,44 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class CSVS < RegexLexer
7
+ tag 'csvs'
8
+ title "csvs"
9
+ desc 'The CSV Schema Language (digital-preservation.github.io)'
10
+ filenames '*.csvs'
11
+
12
+ state :root do
13
+ rule %r/\s+/m, Text
14
+
15
+ rule %r(//[\S\t ]*), Comment::Single
16
+ rule %r(/\*[^*]*\*/)m, Comment::Multiline
17
+
18
+ rule %r/(version)( )(\d+\.\d+)/ do
19
+ groups Keyword, Text::Whitespace, Num::Float
20
+ end
21
+
22
+ rule %r/T?\d{2}:\d{2}:\d{2}(\.\d{5})?(Z|(?:[-+]\d{2}:\d{2}))?/, Literal::Date
23
+ rule %r/\d{4}-\d{2}-\d{2}/, Literal::Date
24
+ rule %r/\d{2}\/\d{2}\/\d{4}/, Literal::Date
25
+
26
+ rule %r((\d+[.]?\d*|\d*[.]\d+)(e[+-]?[0-9]+)?)i, Num::Float
27
+ rule %r/\d+/, Num::Integer
28
+
29
+ rule %r/@\w+/, Keyword::Pseudo
30
+
31
+ rule %r/[-.\w]+:/, Name::Variable
32
+ rule %r/^"[^"]+"/, Name::Variable
33
+ rule %r/\$([-.\w]+|("[^"]+"))\/?/, Name::Variable
34
+
35
+ rule %r/[A-Z]+/i, Keyword
36
+
37
+ rule %r/"[^"]*"/, Str::Double
38
+ rule %r/'[^\r\n\f']'/, Str::Char
39
+
40
+ rule %r/[,()*]/, Punctuation
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,52 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class EEX < TemplateLexer
6
+ title "EEX"
7
+ desc "Embedded Elixir"
8
+
9
+ tag 'eex'
10
+ aliases 'leex'
11
+
12
+ filenames '*.eex', '*.leex'
13
+
14
+ def initialize(opts={})
15
+ @elixir_lexer = Elixir.new(opts)
16
+
17
+ super(opts)
18
+ end
19
+
20
+ start do
21
+ parent.reset!
22
+ @elixir_lexer.reset!
23
+ end
24
+
25
+ open = /<%%|<%=|<%#|<%/
26
+ close = /%%>|%>/
27
+
28
+ state :root do
29
+ rule %r/<%#/, Comment, :comment
30
+
31
+ rule open, Comment::Preproc, :elixir
32
+
33
+ rule %r/.+?(?=#{open})|.+/mo do
34
+ delegate parent
35
+ end
36
+ end
37
+
38
+ state :comment do
39
+ rule close, Comment, :pop!
40
+ rule %r/.+?(?=#{close})|.+/mo, Comment
41
+ end
42
+
43
+ state :elixir do
44
+ rule close, Comment::Preproc, :pop!
45
+
46
+ rule %r/.+?(?=#{close})|.+/mo do
47
+ delegate @elixir_lexer
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -51,15 +51,25 @@ module Rouge
51
51
  state :strings do
52
52
  rule %r/(%[A-Ba-z])?"""(?:.|\n)*?"""/, Str::Doc
53
53
  rule %r/'''(?:.|\n)*?'''/, Str::Doc
54
- rule %r/"/, Str::Doc, :dqs
55
- rule %r/'.*?'/, Str::Single
54
+ rule %r/"/, Str::Double, :dqs
55
+ rule %r/'/, Str::Single, :sqs
56
56
  rule %r{(?<!\w)\?(\\(x\d{1,2}|\h{1,2}(?!\h)\b|0[0-7]{0,2}(?![0-7])\b[^x0MC])|(\\[MC]-)+\w|[^\s\\])}, Str::Other
57
-
58
57
  end
59
58
 
60
59
  state :dqs do
60
+ mixin :escapes
61
+ mixin :interpoling
62
+ rule %r/[^#"\\]+/, Str::Double
61
63
  rule %r/"/, Str::Double, :pop!
62
- mixin :enddoublestr
64
+ rule %r/[#\\]/, Str::Double
65
+ end
66
+
67
+ state :sqs do
68
+ mixin :escapes
69
+ mixin :interpoling
70
+ rule %r/[^#'\\]+/, Str::Single
71
+ rule %r/'/, Str::Single, :pop!
72
+ rule %r/[#\\]/, Str::Single
63
73
  end
64
74
 
65
75
  state :interpoling do
@@ -71,17 +81,18 @@ module Rouge
71
81
  mixin :root
72
82
  end
73
83
 
84
+ state :escapes do
85
+ rule %r/\\x\h{2}/, Str::Escape
86
+ rule %r/\\u\{?\d+\}?/, Str::Escape
87
+ rule %r/\\[\\abdefnrstv0"']/, Str::Escape
88
+ end
89
+
74
90
  state :interpoling_symbol do
75
91
  rule %r/"/, Str::Symbol, :pop!
76
92
  mixin :interpoling
77
93
  rule %r/[^#"]+/, Str::Symbol
78
94
  end
79
95
 
80
- state :enddoublestr do
81
- mixin :interpoling
82
- rule %r/[^#"]+/, Str::Double
83
- end
84
-
85
96
  state :sigil_strings do
86
97
  # ~-sigiled strings
87
98
  # ~(abc), ~[abc], ~<abc>, ~|abc|, ~r/abc/, etc
@@ -0,0 +1,246 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Haxe < RegexLexer
6
+ title "Haxe"
7
+ desc "Haxe Cross-platform Toolkit (http://haxe.org)"
8
+
9
+ tag 'haxe'
10
+ aliases 'hx', 'haxe'
11
+ filenames '*.hx'
12
+ mimetypes 'text/haxe', 'text/x-haxe', 'text/x-hx'
13
+
14
+ def self.detect?(text)
15
+ return true if text.shebang? "haxe"
16
+ end
17
+
18
+ def self.keywords
19
+ @keywords ||= Set.new %w(
20
+ break case cast catch class continue default do else enum false for
21
+ function if import interface macro new null override package private
22
+ public return switch this throw true try untyped while
23
+ )
24
+ end
25
+
26
+ def self.imports
27
+ @imports ||= Set.new %w(
28
+ import using
29
+ )
30
+ end
31
+
32
+ def self.declarations
33
+ @declarations ||= Set.new %w(
34
+ abstract dynamic extern extends from implements inline static to
35
+ typedef var
36
+ )
37
+ end
38
+
39
+ def self.reserved
40
+ @reserved ||= Set.new %w(
41
+ super trace inline build autoBuild enum
42
+ )
43
+ end
44
+
45
+ def self.constants
46
+ @constants ||= Set.new %w(true false null)
47
+ end
48
+
49
+ def self.builtins
50
+ @builtins ||= %w(
51
+ Void Dynamic Math Class Any Float Int UInt String StringTools Sys
52
+ EReg isNaN parseFloat parseInt this Array Map Date DateTools Bool
53
+ Lambda Reflect Std File FileSystem
54
+ )
55
+ end
56
+
57
+ id = /[$a-zA-Z_][a-zA-Z0-9_]*/
58
+
59
+ state :comments_and_whitespace do
60
+ rule %r/\s+/, Text
61
+ rule %r(//.*?$), Comment::Single
62
+ rule %r(/\*.*?\*/)m, Comment::Multiline
63
+ end
64
+
65
+ state :expr_start do
66
+ mixin :comments_and_whitespace
67
+
68
+ rule %r/#(?:if|elseif|else|end).*/, Comment::Preproc
69
+
70
+ rule %r(~) do
71
+ token Str::Regex
72
+ goto :regex
73
+ end
74
+
75
+ rule %r/[{]/, Punctuation, :object
76
+
77
+ rule %r//, Text, :pop!
78
+ end
79
+
80
+ state :regex do
81
+ rule %r(/) do
82
+ token Str::Regex
83
+ goto :regex_end
84
+ end
85
+
86
+ rule %r([^/]\n), Error, :pop!
87
+
88
+ rule %r/\n/, Error, :pop!
89
+ rule %r/\[\^/, Str::Escape, :regex_group
90
+ rule %r/\[/, Str::Escape, :regex_group
91
+ rule %r/\\./, Str::Escape
92
+ rule %r{[(][?][:=<!]}, Str::Escape
93
+ rule %r/[{][\d,]+[}]/, Str::Escape
94
+ rule %r/[()?]/, Str::Escape
95
+ rule %r/./, Str::Regex
96
+ end
97
+
98
+ state :regex_end do
99
+ rule %r/[gim]+/, Str::Regex, :pop!
100
+ rule(//) { pop! }
101
+ end
102
+
103
+ state :regex_group do
104
+ # specially highlight / in a group to indicate that it doesn't
105
+ # close the regex
106
+ rule %r/\//, Str::Escape
107
+
108
+ rule %r([^/]\n) do
109
+ token Error
110
+ pop! 2
111
+ end
112
+
113
+ rule %r/\]/, Str::Escape, :pop!
114
+ rule %r/\\./, Str::Escape
115
+ rule %r/./, Str::Regex
116
+ end
117
+
118
+ state :bad_regex do
119
+ rule %r/[^\n]+/, Error, :pop!
120
+ end
121
+
122
+ state :root do
123
+ rule %r/\n/, Text, :statement
124
+ rule %r(\{), Punctuation, :expr_start
125
+
126
+ mixin :comments_and_whitespace
127
+
128
+ rule %r/@/, Name::Decorator, :metadata
129
+ rule %r(\+\+ | -- | ~ | && | \|\| | \\(?=\n) | << | >> | ==
130
+ | != )x,
131
+ Operator, :expr_start
132
+ rule %r([-:<>+*%&|\^/!=]=?), Operator, :expr_start
133
+ rule %r/[(\[,]/, Punctuation, :expr_start
134
+ rule %r/;/, Punctuation, :statement
135
+ rule %r/[)\]}.]/, Punctuation
136
+
137
+ rule %r/[?]/ do
138
+ token Punctuation
139
+ push :ternary
140
+ push :expr_start
141
+ end
142
+
143
+ rule id do |m|
144
+ if self.class.keywords.include? m[0]
145
+ token Keyword
146
+ push :expr_start
147
+ elsif self.class.imports.include? m[0]
148
+ token Keyword
149
+ push :namespace
150
+ elsif self.class.declarations.include? m[0]
151
+ token Keyword::Declaration
152
+ push :expr_start
153
+ elsif self.class.reserved.include? m[0]
154
+ token Keyword::Reserved
155
+ elsif self.class.constants.include? m[0]
156
+ token Keyword::Constant
157
+ elsif self.class.builtins.include? m[0]
158
+ token Name::Builtin
159
+ else
160
+ token Name::Other
161
+ end
162
+ end
163
+
164
+ rule %r/\-?\d+\.\d+(?:[eE]\d+)?[fd]?/, Num::Float
165
+ rule %r/0x\h+/, Num::Hex
166
+ rule %r/\-?[0-9]+/, Num::Integer
167
+ rule %r/"/, Str::Double, :str_double
168
+ rule %r/'/, Str::Single, :str_single
169
+ end
170
+
171
+ # braced parts that aren't object literals
172
+ state :statement do
173
+ rule %r/(#{id})(\s*)(:)/ do
174
+ groups Name::Label, Text, Punctuation
175
+ end
176
+
177
+ mixin :expr_start
178
+ end
179
+
180
+ # object literals
181
+ state :object do
182
+ mixin :comments_and_whitespace
183
+ rule %r/[}]/ do
184
+ token Punctuation
185
+ goto :statement
186
+ end
187
+
188
+ rule %r/(#{id})(\s*)(:)/ do
189
+ groups Name::Attribute, Text, Punctuation
190
+ push :expr_start
191
+ end
192
+
193
+ rule %r/:/, Punctuation
194
+ mixin :root
195
+ end
196
+
197
+ state :metadata do
198
+ rule %r/(#{id})(\()?/ do |m|
199
+ groups Name::Decorator, Punctuation
200
+ pop! unless m[2]
201
+ end
202
+ rule %r/:#{id}(?:\.#{id})*/, Name::Decorator, :pop!
203
+ rule %r/\)/, Name::Decorator, :pop!
204
+ mixin :root
205
+ end
206
+
207
+ # ternary expressions, where <id>: is not a label!
208
+ state :ternary do
209
+ rule %r/:/ do
210
+ token Punctuation
211
+ goto :expr_start
212
+ end
213
+
214
+ mixin :root
215
+ end
216
+
217
+ state :str_double do
218
+ mixin :str_escape
219
+ rule %r/"/, Str::Double, :pop!
220
+ rule %r/[^\\"]+/, Str::Double
221
+ end
222
+
223
+ state :str_single do
224
+ mixin :str_escape
225
+ rule %r/'/, Str::Single, :pop!
226
+ rule %r/\$\$/, Str::Single
227
+ rule %r/\$#{id}/, Str::Interpol
228
+ rule %r/\$\{/, Str::Interpol, :str_interpol
229
+ rule %r/[^\\$']+/, Str::Single
230
+ end
231
+
232
+ state :str_escape do
233
+ rule %r/\\[\\tnr'"]/, Str::Escape
234
+ rule %r/\\[0-7]{3}/, Str::Escape
235
+ rule %r/\\x\h{2}/, Str::Escape
236
+ rule %r/\\u\h{4}/, Str::Escape
237
+ rule %r/\\u\{\h{1,6}\}/, Str::Escape
238
+ end
239
+
240
+ state :str_interpol do
241
+ rule %r/\}/, Str::Interpol, :pop!
242
+ mixin :root
243
+ end
244
+ end
245
+ end
246
+ end