rouge 3.8.0 → 3.12.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,87 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ # Based on Chroma's MiniZinc lexer:
5
+ # https://github.com/alecthomas/chroma/blob/5152194c717b394686d3d7a7e1946a360ec0728f/lexers/m/minizinc.go
6
+
7
+ module Rouge
8
+ module Lexers
9
+ class MiniZinc < RegexLexer
10
+ title "MiniZinc"
11
+ desc "MiniZinc is a free and open-source constraint modeling language (minizinc.org)"
12
+ tag 'minizinc'
13
+ filenames '*.mzn', '*.fzn', '*.dzn'
14
+ mimetypes 'text/minizinc'
15
+
16
+ def self.builtins
17
+ @builtins = Set.new %w[
18
+ abort abs acosh array_intersect array_union array1d array2d array3d
19
+ array4d array5d array6d asin assert atan bool2int card ceil concat
20
+ cos cosh dom dom_array dom_size fix exp floor index_set
21
+ index_set_1of2 index_set_2of2 index_set_1of3 index_set_2of3
22
+ index_set_3of3 int2float is_fixed join lb lb_array length ln log log2
23
+ log10 min max pow product round set2array show show_int show_float
24
+ sin sinh sqrt sum tan tanh trace ub ub_array
25
+ ]
26
+ end
27
+
28
+ def self.keywords
29
+ @keywords = Set.new %w[
30
+ ann annotation any constraint else endif function for forall if
31
+ include list of op output minimize maximize par predicate record
32
+ satisfy solve test then type var where
33
+ ]
34
+ end
35
+
36
+ def self.keywords_type
37
+ @keywords_type ||= Set.new %w(
38
+ array set bool enum float int string tuple
39
+ )
40
+ end
41
+
42
+ def self.operators
43
+ @operators ||= Set.new %w(
44
+ in subset superset union diff symdiff intersect
45
+ )
46
+ end
47
+
48
+ id = /[$a-zA-Z_]\w*/
49
+
50
+ state :root do
51
+ rule %r(\s+)m, Text::Whitespace
52
+ rule %r(\\\n)m, Text::Whitespace
53
+ rule %r(%.*), Comment::Single
54
+ rule %r(/(\\\n)?[*](.|\n)*?[*](\\\n)?/)m, Comment::Multiline
55
+ rule %r/"(\\\\|\\"|[^"])*"/, Literal::String
56
+
57
+ rule %r(not|<->|->|<-|\\/|xor|/\\), Operator
58
+ rule %r(<|>|<=|>=|==|=|!=), Operator
59
+ rule %r(\+|-|\*|/|div|mod), Operator
60
+ rule %r(\\|\.\.|\+\+), Operator
61
+ rule %r([|()\[\]{},:;]), Punctuation
62
+ rule %r((true|false)\b), Keyword::Constant
63
+ rule %r(([+-]?)\d+(\.(?!\.)\d*)?([eE][-+]?\d+)?), Literal::Number
64
+
65
+ rule id do |m|
66
+ if self.class.keywords.include? m[0]
67
+ token Keyword
68
+ elsif self.class.keywords_type.include? m[0]
69
+ token Keyword::Type
70
+ elsif self.class.builtins.include? m[0]
71
+ token Name::Builtin
72
+ elsif self.class.operators.include? m[0]
73
+ token Operator
74
+ else
75
+ token Name::Other
76
+ end
77
+ end
78
+
79
+ rule %r(::\s*([^\W\d]\w*)(\s*\([^\)]*\))?), Name::Decorator
80
+ rule %r(\b([^\W\d]\w*)\b(\()) do
81
+ groups Name::Function, Punctuation
82
+ end
83
+ rule %r([^\W\d]\w*), Name::Other
84
+ end
85
+ end
86
+ end
87
+ 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
@@ -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)
@@ -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
@@ -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