rouge 3.10.0 → 3.14.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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rouge/demos/apex +9 -0
  3. data/lib/rouge/demos/csvs +8 -0
  4. data/lib/rouge/demos/liquid +0 -1
  5. data/lib/rouge/demos/minizinc +23 -0
  6. data/lib/rouge/demos/nesasm +11 -0
  7. data/lib/rouge/demos/q +6 -0
  8. data/lib/rouge/demos/robot_framework +27 -0
  9. data/lib/rouge/demos/slice +10 -0
  10. data/lib/rouge/demos/ttcn3 +6 -0
  11. data/lib/rouge/guessers/disambiguation.rb +5 -0
  12. data/lib/rouge/lexer.rb +3 -0
  13. data/lib/rouge/lexers/apex.rb +126 -0
  14. data/lib/rouge/lexers/bpf.rb +20 -6
  15. data/lib/rouge/lexers/coq.rb +12 -9
  16. data/lib/rouge/lexers/csvs.rb +44 -0
  17. data/lib/rouge/lexers/d.rb +1 -1
  18. data/lib/rouge/lexers/dot.rb +2 -2
  19. data/lib/rouge/lexers/eex.rb +2 -1
  20. data/lib/rouge/lexers/io.rb +2 -2
  21. data/lib/rouge/lexers/json.rb +1 -1
  22. data/lib/rouge/lexers/json_doc.rb +4 -3
  23. data/lib/rouge/lexers/kotlin.rb +21 -28
  24. data/lib/rouge/lexers/liquid.rb +82 -108
  25. data/lib/rouge/lexers/m68k.rb +2 -2
  26. data/lib/rouge/lexers/magik.rb +1 -1
  27. data/lib/rouge/lexers/markdown.rb +7 -1
  28. data/lib/rouge/lexers/mason.rb +0 -5
  29. data/lib/rouge/lexers/minizinc.rb +87 -0
  30. data/lib/rouge/lexers/nesasm.rb +78 -0
  31. data/lib/rouge/lexers/nginx.rb +1 -1
  32. data/lib/rouge/lexers/perl.rb +1 -1
  33. data/lib/rouge/lexers/pony.rb +1 -1
  34. data/lib/rouge/lexers/protobuf.rb +1 -1
  35. data/lib/rouge/lexers/q.rb +2 -1
  36. data/lib/rouge/lexers/robot_framework.rb +249 -0
  37. data/lib/rouge/lexers/scala.rb +3 -3
  38. data/lib/rouge/lexers/shell.rb +5 -3
  39. data/lib/rouge/lexers/sieve.rb +1 -1
  40. data/lib/rouge/lexers/slice.rb +32 -0
  41. data/lib/rouge/lexers/sqf.rb +1 -1
  42. data/lib/rouge/lexers/swift.rb +1 -1
  43. data/lib/rouge/lexers/toml.rb +16 -1
  44. data/lib/rouge/lexers/ttcn3.rb +119 -0
  45. data/lib/rouge/lexers/verilog.rb +1 -1
  46. data/lib/rouge/plugins/redcarpet.rb +7 -1
  47. data/lib/rouge/version.rb +1 -1
  48. metadata +16 -2
@@ -87,8 +87,8 @@ module Rouge
87
87
 
88
88
  state :whitespace do
89
89
  rule %r/\n+/m, Text, :expr_bol
90
- rule %r(^\*(\\.|.)*?\n), Comment::Single, :expr_bol
91
- rule %r(;(\\.|.)*?\n), Comment::Single, :expr_bol
90
+ rule %r(^\*(\\.|.)*?$), Comment::Single, :expr_bol
91
+ rule %r(;(\\.|.)*?$), Comment::Single, :expr_bol
92
92
  mixin :inline_whitespace
93
93
  end
94
94
 
@@ -22,7 +22,7 @@ module Rouge
22
22
  _throw
23
23
  _lock _endlock
24
24
  _if _then _elif _else _endif
25
- _for _over _while _loop _endloop _loopbody _continue _leave
25
+ _for _over _while _loop _finally _endloop _loopbody _continue _leave
26
26
  _return
27
27
  _class
28
28
  _local _constant _recursive _global _dynamic _import
@@ -34,7 +34,13 @@ module Rouge
34
34
 
35
35
  rule %r/^([ \t]*)(```|~~~)([^\n]*\n)((.*?)(\2))?/m do |m|
36
36
  name = m[3].strip
37
- sublexer = Lexer.find_fancy(name.empty? ? "guess" : name, m[5], @options)
37
+ sublexer =
38
+ begin
39
+ Lexer.find_fancy(name.empty? ? "guess" : name, m[5], @options)
40
+ rescue Guesser::Ambiguous => e
41
+ e.alternatives.first.new(@options)
42
+ end
43
+
38
44
  sublexer ||= PlainText.new(@options.merge(:token => Str::Backtick))
39
45
  sublexer.reset!
40
46
 
@@ -15,11 +15,6 @@ module Rouge
15
15
  @perl = Perl.new
16
16
  end
17
17
 
18
- def self.detect?(text)
19
- return false if text.doctype?(/((?:ht|x)ml)/)
20
- return true if text.doctype?
21
- end
22
-
23
18
  # Note: If you add a tag in the lines below, you also need to modify "disambiguate '*.m'" in file disambiguation.rb
24
19
  TEXT_BLOCKS = %w(text doc)
25
20
  PERL_BLOCKS = %w(args flags attr init once shared perl cleanup filter)
@@ -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
@@ -0,0 +1,78 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class NesAsm < RegexLexer
7
+ title "NesAsm"
8
+ desc "Nesasm3 assembly (6502 asm)"
9
+ tag 'nesasm'
10
+ aliases 'nes'
11
+ filenames '*.nesasm'
12
+
13
+ def self.keywords
14
+ @keywords ||= %w(
15
+ ADC AND ASL BIT BRK CMP CPX CPY DEC EOR INC JMP JSR LDA LDX LDY LSR
16
+ NOP ORA ROL ROR RTI RTS SBC STA STX STY TAX TXA DEX INX TAY TYA DEY
17
+ INY BPL BMI BVC BVS BCC BCS BNE BEQ CLC SEC CLI SEI CLV CLD SED TXS
18
+ TSX PHA PLA PHP PLP
19
+ )
20
+ end
21
+
22
+ def self.keywords_type
23
+ @keywords_type ||= %w(
24
+ DB DW BYTE WORD
25
+ )
26
+ end
27
+
28
+ def self.keywords_reserved
29
+ @keywords_reserved ||= %w(
30
+ INCBIN INCLUDE ORG BANK RSSET RS MACRO ENDM DS PROC ENDP PROCGROUP
31
+ ENDPROCGROUP INCCHR DEFCHR ZP BSS CODE DATA IF IFDEF IFNDEF ELSE
32
+ ENDIF FAIL INESPRG INESCHR INESMAP INESMIR FUNC
33
+ )
34
+ end
35
+
36
+ state :root do
37
+ rule %r/\s+/m, Text
38
+ rule %r(;.*), Comment::Single
39
+
40
+ rule %r/[\(\)\,\.\[\]]/, Punctuation
41
+ rule %r/\#?\%[0-1]+/, Num::Bin # #%00110011 %00110011
42
+ rule %r/\#?\$\h+/, Num::Hex # $1f #$1f
43
+ rule %r/\#?\d+/, Num # 10 #10
44
+ rule %r([~&*+=\|?:<>/-]), Operator
45
+
46
+ rule %r/\#?\w+:?/i do |m|
47
+ name = m[0].upcase
48
+
49
+ if self.class.keywords.include? name
50
+ token Keyword
51
+ elsif self.class.keywords_type.include? name
52
+ token Keyword::Type
53
+ elsif self.class.keywords_reserved.include? name
54
+ token Keyword::Reserved
55
+ else
56
+ token Name::Function
57
+ end
58
+ end
59
+
60
+ rule %r/\#?(?:LOW|HIGH)\(.*\)/i, Keyword::Reserved # LOW() #HIGH()
61
+
62
+ rule %r/\#\(/, Punctuation # #()
63
+
64
+ rule %r/"/, Str, :string
65
+
66
+ rule %r/'\w'/, Str::Char # 'A' for example
67
+
68
+ rule %r/\\\??[\d@#]/, Name::Builtin # builtin parameters for use inside macros and functions: \1-\9 , \?1-\?9 , \# , \@
69
+ end
70
+
71
+ state :string do
72
+ rule %r/"/, Str, :pop!
73
+ rule %r/\\"?/, Str::Escape
74
+ rule %r/[^"\\]+/m, Str
75
+ end
76
+ end
77
+ end
78
+ end
@@ -41,7 +41,7 @@ module Rouge
41
41
  state :base do
42
42
  rule %r/\s+/, Text
43
43
 
44
- rule %r/#.*?\n/, Comment::Single
44
+ rule %r/#.*/, Comment::Single
45
45
  rule %r/(?:on|off)\b/, Name::Constant
46
46
  rule %r/[$][\w-]+/, Name::Variable
47
47
 
@@ -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
@@ -46,7 +46,7 @@ module Rouge
46
46
  state :root do
47
47
  mixin :whitespace
48
48
  rule %r/"""/, Str::Doc, :docstring
49
- rule %r{//(.*?)\n}, Comment::Single
49
+ rule %r{//.*}, Comment::Single
50
50
  rule %r{/(\\\n)?[*](.|\n)*?[*](\\\n)?/}, Comment::Multiline
51
51
  rule %r/"/, Str, :string
52
52
  rule %r([~!%^&*+=\|?:<>/-]), Operator
@@ -17,7 +17,7 @@ module Rouge
17
17
  state :root do
18
18
  rule %r/[\s]+/, Text
19
19
  rule %r/[,;{}\[\]()]/, Punctuation
20
- rule %r/\/(\\\n)?\/(\n|(.|\n)*?[^\\]\n)/, Comment::Single
20
+ rule %r/\/(\\\n)?\/($|(.|\n)*?[^\\]$)/, Comment::Single
21
21
  rule %r/\/(\\\n)?\*(.|\n)*?\*(\\\n)?\//, Comment::Multiline
22
22
  rule kw, Keyword
23
23
  rule datatype, Keyword::Type
@@ -110,7 +110,8 @@ module Rouge
110
110
  end
111
111
 
112
112
  state :string do
113
- rule(/"/, Str, :pop!)
113
+ rule %r/\\"/, Str
114
+ rule %r/"/, Str, :pop!
114
115
  rule %r/\\([\\nr]|[01][0-7]{2})/, Str::Escape
115
116
  rule %r/[^\\"\n]+/, Str
116
117
  rule %r/\\/, Str # stray backslash
@@ -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