rouge 3.7.0 → 3.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/lib/rouge/demos/apex +9 -0
  4. data/lib/rouge/demos/armasm +12 -0
  5. data/lib/rouge/demos/batchfile +3 -0
  6. data/lib/rouge/demos/bbcbasic +6 -0
  7. data/lib/rouge/demos/clean +6 -0
  8. data/lib/rouge/demos/cmhg +8 -0
  9. data/lib/rouge/demos/csvs +8 -0
  10. data/lib/rouge/demos/cython +6 -0
  11. data/lib/rouge/demos/eex +1 -0
  12. data/lib/rouge/demos/epp +4 -0
  13. data/lib/rouge/demos/haxe +5 -0
  14. data/lib/rouge/demos/hql +5 -0
  15. data/lib/rouge/demos/jsl +3 -0
  16. data/lib/rouge/demos/liquid +0 -1
  17. data/lib/rouge/demos/lustre +6 -0
  18. data/lib/rouge/demos/lutin +18 -0
  19. data/lib/rouge/demos/msgtrans +4 -0
  20. data/lib/rouge/demos/plist +1 -132
  21. data/lib/rouge/demos/robot_framework +27 -0
  22. data/lib/rouge/demos/sparql +6 -0
  23. data/lib/rouge/demos/terraform +0 -15
  24. data/lib/rouge/formatters/html_line_table.rb +3 -1
  25. data/lib/rouge/formatters/tex.rb +11 -12
  26. data/lib/rouge/guessers/disambiguation.rb +13 -0
  27. data/lib/rouge/lexers/apex.rb +126 -0
  28. data/lib/rouge/lexers/armasm.rb +145 -0
  29. data/lib/rouge/lexers/batchfile.rb +164 -0
  30. data/lib/rouge/lexers/bbcbasic.rb +112 -0
  31. data/lib/rouge/lexers/clean.rb +156 -0
  32. data/lib/rouge/lexers/cmhg.rb +34 -0
  33. data/lib/rouge/lexers/common_lisp.rb +1 -1
  34. data/lib/rouge/lexers/console.rb +1 -1
  35. data/lib/rouge/lexers/coq.rb +12 -9
  36. data/lib/rouge/lexers/cpp.rb +4 -1
  37. data/lib/rouge/lexers/csvs.rb +44 -0
  38. data/lib/rouge/lexers/cython.rb +151 -0
  39. data/lib/rouge/lexers/eex.rb +51 -0
  40. data/lib/rouge/lexers/elixir.rb +20 -9
  41. data/lib/rouge/lexers/epp.rb +51 -0
  42. data/lib/rouge/lexers/haxe.rb +246 -0
  43. data/lib/rouge/lexers/hql.rb +139 -0
  44. data/lib/rouge/lexers/http.rb +5 -5
  45. data/lib/rouge/lexers/javascript.rb +1 -1
  46. data/lib/rouge/lexers/jsl.rb +55 -0
  47. data/lib/rouge/lexers/json.rb +1 -1
  48. data/lib/rouge/lexers/julia.rb +1 -1
  49. data/lib/rouge/lexers/kotlin.rb +21 -28
  50. data/lib/rouge/lexers/liquid.rb +82 -108
  51. data/lib/rouge/lexers/lustre.rb +79 -0
  52. data/lib/rouge/lexers/lutin.rb +33 -0
  53. data/lib/rouge/lexers/make.rb +39 -12
  54. data/lib/rouge/lexers/matlab.rb +4 -2
  55. data/lib/rouge/lexers/matlab/builtins.yml +3515 -0
  56. data/lib/rouge/lexers/msgtrans.rb +26 -0
  57. data/lib/rouge/lexers/perl.rb +1 -1
  58. data/lib/rouge/lexers/plain_text.rb +1 -1
  59. data/lib/rouge/lexers/puppet.rb +2 -2
  60. data/lib/rouge/lexers/q.rb +1 -1
  61. data/lib/rouge/lexers/r.rb +2 -3
  62. data/lib/rouge/lexers/robot_framework.rb +249 -0
  63. data/lib/rouge/lexers/sed.rb +1 -1
  64. data/lib/rouge/lexers/shell.rb +5 -3
  65. data/lib/rouge/lexers/sparql.rb +129 -0
  66. data/lib/rouge/lexers/sql.rb +26 -6
  67. data/lib/rouge/lexers/swift.rb +1 -1
  68. data/lib/rouge/lexers/terraform.rb +8 -0
  69. data/lib/rouge/tex_theme_renderer.rb +2 -1
  70. data/lib/rouge/themes/magritte.rb +2 -2
  71. data/lib/rouge/version.rb +1 -1
  72. data/rouge.gemspec +4 -2
  73. metadata +44 -6
  74. data/lib/rouge/lexers/matlab/builtins.rb +0 -13
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class MsgTrans < RegexLexer
7
+ title "MessageTrans"
8
+ desc "RISC OS message translator messages file"
9
+ tag 'msgtrans'
10
+ filenames 'Messages', 'Message[0-9]', 'Message[1-9][0-9]', 'Message[1-9][0-9][0-9]'
11
+
12
+ state :root do
13
+ rule %r/^#[^\n]*/, Comment
14
+ rule %r/[^\t\n\r ,):?\/]+/, Name::Variable
15
+ rule %r/[\n\/?]/, Operator
16
+ rule %r/:/, Operator, :value
17
+ end
18
+
19
+ state :value do
20
+ rule %r/\n/, Text, :pop!
21
+ rule %r/%[0-3%]/, Operator
22
+ rule %r/[^\n%]/, Literal::String
23
+ end
24
+ end
25
+ end
26
+ end
@@ -127,7 +127,7 @@ module Rouge
127
127
  rule %r/(q|qq|qw|qr|qx)\(/, Str::Other, :rb_string
128
128
  rule %r/(q|qq|qw|qr|qx)\[/, Str::Other, :sb_string
129
129
  rule %r/(q|qq|qw|qr|qx)</, Str::Other, :lt_string
130
- rule %r/(q|qq|qw|qr|qx)([^a-zA-Z0-9])(.|\n)*?\2/, Str::Other
130
+ rule %r/(q|qq|qw|qr|qx)(\W)(.|\n)*?\2/, Str::Other
131
131
 
132
132
  rule %r/package\s+/, Keyword, :modulename
133
133
  rule %r/sub\s+/, Keyword, :funcname
@@ -9,7 +9,7 @@ module Rouge
9
9
 
10
10
  tag 'plaintext'
11
11
  aliases 'text'
12
- filenames '*.txt'
12
+ filenames '*.txt', 'Messages'
13
13
  mimetypes 'text/plain'
14
14
 
15
15
  attr_reader :token
@@ -59,7 +59,7 @@ module Rouge
59
59
  rule cap_id, Name::Class
60
60
 
61
61
  rule %r/[+=|~-]>|<[|~-]/, Punctuation
62
- rule %r/[:}();\[\]]/, Punctuation
62
+ rule %r/[|:}();\[\]]/, Punctuation
63
63
 
64
64
  # HACK for case statements and selectors
65
65
  rule %r/{/, Punctuation, :regex_allowed
@@ -68,7 +68,7 @@ module Rouge
68
68
  rule %r/(in|and|or)\b/, Operator::Word
69
69
  rule %r/[=!<>]=/, Operator
70
70
  rule %r/[=!]~/, Operator, :regex_allowed
71
- rule %r([=<>!+*/-]), Operator
71
+ rule %r([.=<>!+*/-]), Operator
72
72
 
73
73
  rule %r/(class|include)(\s*)(#{qualname})/ do
74
74
  groups Keyword, Text, Name::Class
@@ -67,7 +67,7 @@ module Rouge
67
67
  end
68
68
 
69
69
  # White space and comments
70
- rule(%r{[ \t\r]\/.*$}, Comment::Single)
70
+ rule(%r{\s+/.*}, Comment::Single)
71
71
  rule(/[ \t\r]+/, Text::Whitespace)
72
72
  rule(%r{^/$.*?^\\$}m, Comment::Multiline)
73
73
  rule(%r{^\/[^\n]*$(\n[^\S\n]+.*$)*}, Comment::Multiline)
@@ -60,8 +60,7 @@ module Rouge
60
60
  rule %r/%[^%]*?%/, Operator
61
61
 
62
62
  rule %r/0[xX][a-fA-F0-9]+([pP][0-9]+)?[Li]?/, Num::Hex
63
- rule %r/[+-]?(\d+([.]\d+)?|[.]\d+)([eE][+-]?\d+)?[Li]?/,
64
- Num
63
+ rule %r/[+-]?(\d+([.]\d+)?|[.]\d+)([eE][+-]?\d+)?[Li]?/, Num
65
64
 
66
65
  # Only recognize built-in functions when they are actually used as a
67
66
  # function call, i.e. followed by an opening parenthesis.
@@ -69,7 +68,7 @@ module Rouge
69
68
  # highlighted specifically; thus use `Name::Function`.
70
69
  rule %r/\b(?<!.)(#{PRIMITIVE_FUNCTIONS.join('|')})(?=\()/, Name::Function
71
70
 
72
- rule %r/[a-zA-Z.]([a-zA-Z_][\w.]*)?/ do |m|
71
+ rule %r/(?:(?:[[:alpha:]]|[.][._[:alpha:]])[._[:alnum:]]*)|[.]/ do |m|
73
72
  if KEYWORDS.include? m[0]
74
73
  token Keyword
75
74
  elsif KEYWORD_CONSTANTS.include? m[0]
@@ -0,0 +1,249 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class RobotFramework < RegexLexer
7
+ tag 'robot_framework'
8
+ aliases 'robot', 'robot-framework'
9
+
10
+ title "Robot Framework"
11
+ desc 'Robot Framework is a generic open source automation testing framework (robotframework.org)'
12
+
13
+ filenames '*.robot'
14
+ mimetypes 'text/x-robot'
15
+
16
+ def initialize(opts = {})
17
+ super(opts)
18
+ @col = 0
19
+ @next = nil
20
+ @is_template = false
21
+ end
22
+
23
+ def self.settings_with_keywords
24
+ @settings_with_keywords ||= Set.new [
25
+ "library", "resource", "setup", "teardown", "template", "suite setup",
26
+ "suite teardown", "task setup", "task teardown", "task template",
27
+ "test setup", "test teardown", "test template", "variables"
28
+ ]
29
+ end
30
+
31
+ def self.settings_with_args
32
+ @settings_with_args ||= Set.new [
33
+ "arguments", "default tags", "documentation", "force tags",
34
+ "metadata", "return", "tags", "timeout", "task timeout",
35
+ "test timeout"
36
+ ]
37
+ end
38
+
39
+ id = %r/(?:\\|[^|$@&% \t\n])+(?: (?:\\.|[^|$@&% \t\n])+)*/
40
+ bdd = %r/(?:Given|When|Then|And|But) /i
41
+ sep = %r/ +\| +|[ ]{2,}|\t+/
42
+
43
+ start do
44
+ push :prior_text
45
+ end
46
+
47
+ state :prior_text do
48
+ rule %r/^[^*].*/, Text
49
+ rule(//) { pop! }
50
+ end
51
+
52
+ # Mixins
53
+
54
+ state :whitespace do
55
+ rule %r/\s+/, Text::Whitespace
56
+ end
57
+
58
+ state :section_include do
59
+ mixin :end_section
60
+ mixin :sep
61
+ mixin :newline
62
+ end
63
+
64
+ state :end_section do
65
+ rule(/(?=^(?:\| )?\*)/) { pop! }
66
+ end
67
+
68
+ state :return do
69
+ rule(//) { pop! }
70
+ end
71
+
72
+ state :sep do
73
+ rule %r/\| /, Text::Whitespace
74
+
75
+ rule sep do
76
+ token Text::Whitespace
77
+ @col = @col + 1
78
+ if @next
79
+ push @next
80
+ elsif @is_template
81
+ push :args
82
+ elsif @col == 1
83
+ @next = :keyword
84
+ push :keyword
85
+ else
86
+ push :args
87
+ end
88
+ push :cell_start
89
+ end
90
+
91
+ rule %r/\.\.\. */ do
92
+ token Text::Whitespace
93
+ @col = @col + 1
94
+ push :args
95
+ end
96
+
97
+ rule %r/ ?\|/, Text::Whitespace
98
+ end
99
+
100
+ state :newline do
101
+ rule %r/\n/ do
102
+ token Text::Whitespace
103
+ @col = 0
104
+ @next = nil
105
+ push :cell_start
106
+ end
107
+ end
108
+
109
+ # States
110
+
111
+ state :root do
112
+ mixin :whitespace
113
+
114
+ rule %r/^(?:\| )?\*[* ]*([A-Z]+(?: [A-Z]+)?).*/i do |m|
115
+ token Generic::Heading, m[0]
116
+ case m[1].chomp("s").downcase
117
+ when "setting" then push :section_settings
118
+ when "test case" then push :section_tests
119
+ when "task" then push :section_tasks
120
+ when "keyword" then push :section_keywords
121
+ when "variable" then push :section_variables
122
+ end
123
+ end
124
+ end
125
+
126
+ state :section_settings do
127
+ mixin :section_include
128
+
129
+ rule %r/([A-Z]+(?: [A-Z]+)?)(:?)/i do |m|
130
+ match = m[1].downcase
131
+ @next = if self.class.settings_with_keywords.include? match
132
+ :keyword
133
+ elsif self.class.settings_with_args.include? match
134
+ :args
135
+ end
136
+ groups Name::Builtin::Pseudo, Punctuation
137
+ end
138
+ end
139
+
140
+ state :section_tests do
141
+ mixin :section_include
142
+
143
+ rule %r/[$@&%{}]+/, Name::Label
144
+ rule %r/( )(?![ |])/, Name::Label
145
+
146
+ rule id do
147
+ @is_template = false
148
+ token Name::Label
149
+ end
150
+ end
151
+
152
+ state :section_tasks do
153
+ mixin :section_tests
154
+ end
155
+
156
+ state :section_keywords do
157
+ mixin :section_include
158
+
159
+ rule %r/[$@&%]\{/ do
160
+ token Name::Variable
161
+ push :var
162
+ end
163
+
164
+ rule %r/[$@&%{}]+/, Name::Label
165
+ rule %r/( )(?![ |])/, Name::Label
166
+
167
+ rule id, Name::Label
168
+ end
169
+
170
+ state :section_variables do
171
+ mixin :section_include
172
+
173
+ rule %r/[$@&%]\{/ do
174
+ token Name::Variable
175
+ @next = :args
176
+ push :var
177
+ end
178
+ end
179
+
180
+ state :cell_start do
181
+ rule %r/#.*/, Comment
182
+ mixin :return
183
+ end
184
+
185
+ state :keyword do
186
+ rule %r/(\[)([A-Z]+(?: [A-Z]+)?)(\])/i do |m|
187
+ groups Punctuation, Name::Builtin::Pseudo, Punctuation
188
+
189
+ match = m[2].downcase
190
+ @is_template = true if match == "template"
191
+ if self.class.settings_with_keywords.include? match
192
+ @next = :keyword
193
+ elsif self.class.settings_with_args.include? match
194
+ @next = :args
195
+ end
196
+
197
+ pop!
198
+ end
199
+
200
+ rule %r/[$@&%]\{/ do
201
+ token Name::Variable
202
+ @next = :keyword unless @next.nil?
203
+ push :var
204
+ end
205
+
206
+ rule %r/FOR/i do
207
+ token Name::Function
208
+ @next = :keyword unless @next.nil?
209
+ end
210
+
211
+ rule %r/( )(?![ |])/, Name::Function
212
+
213
+ rule bdd, Name::Builtin
214
+ rule id do
215
+ token Name::Function
216
+ @next = nil
217
+ end
218
+
219
+ mixin :return
220
+ end
221
+
222
+ state :args do
223
+ rule %r/[$@&%]\{/ do
224
+ token Name::Variable
225
+ @next = :keyword unless @next.nil?
226
+ push :var
227
+ end
228
+
229
+ rule %r/[$@&%]+/, Str
230
+ rule %r/( )(?![ |])/, Str
231
+ rule id, Str
232
+
233
+ mixin :return
234
+ end
235
+
236
+ state :var do
237
+ rule %r/(\})( )(=)/ do
238
+ groups Name::Variable, Text::Whitespace, Punctuation
239
+ pop!
240
+ end
241
+ rule %r/[$@&%]\{/, Name::Variable, :var
242
+ rule %r/[{\[]/, Name::Variable, :var
243
+ rule %r/[}\]]/, Name::Variable, :pop!
244
+ rule %r/[^$@&%{}\[\]]+/, Name::Variable
245
+ rule %r/\}\[/, Name::Variable
246
+ end
247
+ end
248
+ end
249
+ end
@@ -141,7 +141,7 @@ module Rouge
141
141
  end
142
142
 
143
143
  # alternate regex rage delimiters
144
- rule %r((\\)(.)(\\.|.)*?(\2)) do |m|
144
+ rule %r((\\)(.)((?:\\.|.)*?)(\2)) do |m|
145
145
  token addr_tok, m[1] + m[2]
146
146
  delegate regex, m[3]
147
147
  token addr_tok, m[4]
@@ -9,10 +9,12 @@ module Rouge
9
9
 
10
10
  tag 'shell'
11
11
  aliases 'bash', 'zsh', 'ksh', 'sh'
12
- filenames '*.sh', '*.bash', '*.zsh', '*.ksh',
13
- '.bashrc', '.zshrc', '.kshrc', '.profile', 'APKBUILD', 'PKGBUILD'
12
+ filenames '*.sh', '*.bash', '*.zsh', '*.ksh', '.bashrc', '.zshrc',
13
+ '.kshrc', '.profile', 'APKBUILD', 'PKGBUILD', '*.ebuild',
14
+ '*.eclass', '*.exheres-0', '*.exlib'
14
15
 
15
- mimetypes 'application/x-sh', 'application/x-shellscript'
16
+ mimetypes 'application/x-sh', 'application/x-shellscript', 'text/x-sh',
17
+ 'text/x-shellscript'
16
18
 
17
19
  def self.detect?(text)
18
20
  return true if text.shebang?(/(ba|z|k)?sh/)
@@ -0,0 +1,129 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class SPARQL < RegexLexer
7
+ title "SPARQL"
8
+ desc "Semantic Query Language, for RDF data"
9
+ tag 'sparql'
10
+ filenames '*.rq'
11
+ mimetypes 'application/sparql-query'
12
+
13
+ def self.builtins
14
+ @builtins = Set.new %w[
15
+ ABS AVG BNODE BOUND CEIL COALESCE CONCAT CONTAINS COUNT DATATYPE DAY
16
+ ENCODE_FOR_URI FLOOR GROUP_CONCAT HOURS IF IRI isBLANK isIRI
17
+ isLITERAL isNUMERIC isURI LANG LANGMATCHES LCASE MAX MD5 MIN MINUTES
18
+ MONTH NOW RAND REGEX REPLACE ROUND SAMETERM SAMPLE SECONDS SEPARATOR
19
+ SHA1 SHA256 SHA384 SHA512 STR STRAFTER STRBEFORE STRDT STRENDS
20
+ STRLANG STRLEN STRSTARTS STRUUID SUBSTR SUM TIMEZONE TZ UCASE URI
21
+ UUID YEAR
22
+ ]
23
+ end
24
+
25
+ def self.keywords
26
+ @keywords = Set.new %w[
27
+ ADD ALL AS ASC ASK BASE BIND BINDINGS BY CLEAR CONSTRUCT COPY CREATE
28
+ DATA DEFAULT DELETE DESC DESCRIBE DISTINCT DROP EXISTS FILTER FROM
29
+ GRAPH GROUP BY HAVING IN INSERT LIMIT LOAD MINUS MOVE NAMED NOT
30
+ OFFSET OPTIONAL ORDER PREFIX SELECT REDUCED SERVICE SILENT TO UNDEF
31
+ UNION USING VALUES WHERE WITH
32
+ ]
33
+ end
34
+
35
+ state :root do
36
+ rule %r(\s+)m, Text::Whitespace
37
+ rule %r(#.*), Comment::Single
38
+
39
+ rule %r("""), Str::Double, :string_double_literal
40
+ rule %r("), Str::Double, :string_double
41
+ rule %r('''), Str::Single, :string_single_literal
42
+ rule %r('), Str::Single, :string_single
43
+
44
+ rule %r([$?]\w+), Name::Variable
45
+ rule %r((\w*:)(\w+)?) do |m|
46
+ token Name::Namespace, m[1]
47
+ token Str::Symbol, m[2]
48
+ end
49
+ rule %r(<[^>]*>), Name::Namespace
50
+ rule %r(true|false)i, Keyword::Constant
51
+
52
+ rule %r([A-Z]\w+\b)i do |m|
53
+ if self.class.builtins.include? m[0].upcase
54
+ token Name::Builtin
55
+ elsif self.class.keywords.include? m[0].upcase
56
+ token Keyword
57
+ else
58
+ token Error
59
+ end
60
+ end
61
+
62
+ rule %r([+\-]?(?:\d+\.\d*|\.\d+)(?:[e][+\-]?[0-9]+)?)i, Num::Float
63
+ rule %r([+\-]?\d+), Num::Integer
64
+ rule %r([\]\[(){}.,;=]), Punctuation
65
+ rule %r([/?*+=!<>]|&&|\|\||\^\^), Operator
66
+ end
67
+
68
+ state :string_double_common do
69
+ mixin :string_escapes
70
+ rule %r(\\), Str::Double
71
+ rule %r([^"\\]+), Str::Double
72
+ end
73
+
74
+ state :string_double do
75
+ rule %r(") do
76
+ token Str::Double
77
+ goto :string_end
78
+ end
79
+ mixin :string_double_common
80
+ end
81
+
82
+ state :string_double_literal do
83
+ rule %r(""") do
84
+ token Str::Double
85
+ goto :string_end
86
+ end
87
+ rule %r("), Str::Double
88
+ mixin :string_double_common
89
+ end
90
+
91
+ state :string_single_common do
92
+ mixin :string_escapes
93
+ rule %r(\\), Str::Single
94
+ rule %r([^'\\]+), Str::Single
95
+ end
96
+
97
+ state :string_single do
98
+ rule %r(') do
99
+ token Str::Single
100
+ goto :string_end
101
+ end
102
+ mixin :string_single_common
103
+ end
104
+
105
+ state :string_single_literal do
106
+ rule %r(''') do
107
+ token Str::Single
108
+ goto :string_end
109
+ end
110
+ rule %r('), Str::Single
111
+ mixin :string_single_common
112
+ end
113
+
114
+ state :string_escapes do
115
+ rule %r(\\[tbnrf"'\\]), Str::Escape
116
+ rule %r(\\u\h{4}), Str::Escape
117
+ rule %r(\\U\h{8}), Str::Escape
118
+ end
119
+
120
+ state :string_end do
121
+ rule %r((@)([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)) do
122
+ groups Operator, Name::Property
123
+ end
124
+ rule %r(\^\^), Operator
125
+ rule(//) { pop! }
126
+ end
127
+ end
128
+ end
129
+ end