rouge 5.0.0 → 5.1.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 (40) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rouge/demos/addmusick +12 -0
  3. data/lib/rouge/demos/java +3 -0
  4. data/lib/rouge/lexer.rb +35 -0
  5. data/lib/rouge/lexers/addmusick.rb +251 -0
  6. data/lib/rouge/lexers/apiblueprint.rb +1 -1
  7. data/lib/rouge/lexers/apple_script.rb +2 -2
  8. data/lib/rouge/lexers/cypher.rb +0 -1
  9. data/lib/rouge/lexers/elixir.rb +1 -1
  10. data/lib/rouge/lexers/gdscript.rb +1 -1
  11. data/lib/rouge/lexers/go.rb +1 -1
  12. data/lib/rouge/lexers/hack.rb +1 -1
  13. data/lib/rouge/lexers/haxe.rb +1 -1
  14. data/lib/rouge/lexers/java.rb +7 -4
  15. data/lib/rouge/lexers/jsx.rb +1 -1
  16. data/lib/rouge/lexers/lean.rb +0 -1
  17. data/lib/rouge/lexers/make.rb +2 -0
  18. data/lib/rouge/lexers/markdown.rb +7 -6
  19. data/lib/rouge/lexers/mojo.rb +0 -1
  20. data/lib/rouge/lexers/perl.rb +140 -43
  21. data/lib/rouge/lexers/php.rb +1 -1
  22. data/lib/rouge/lexers/plist.rb +0 -1
  23. data/lib/rouge/lexers/postscript.rb +1 -1
  24. data/lib/rouge/lexers/prolog.rb +0 -1
  25. data/lib/rouge/lexers/prometheus.rb +0 -1
  26. data/lib/rouge/lexers/properties.rb +2 -2
  27. data/lib/rouge/lexers/qml.rb +0 -1
  28. data/lib/rouge/lexers/r.rb +1 -1
  29. data/lib/rouge/lexers/scala.rb +0 -1
  30. data/lib/rouge/lexers/shell.rb +18 -2
  31. data/lib/rouge/lexers/smarty.rb +0 -1
  32. data/lib/rouge/lexers/tap.rb +0 -1
  33. data/lib/rouge/lexers/tulip.rb +0 -1
  34. data/lib/rouge/lexers/vhdl.rb +3 -1
  35. data/lib/rouge/lexers/vue.rb +18 -2
  36. data/lib/rouge/regex_lexer.rb +12 -0
  37. data/lib/rouge/themes/thankful_eyes.rb +2 -1
  38. data/lib/rouge/version.rb +1 -1
  39. metadata +4 -2
  40. /data/lib/rouge/demos/{applescript → apple_script} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9123349dc8d157c07642dd422b2ce6589c42728fcc9a204255b55c2cdac11a41
4
- data.tar.gz: b077e0041bb215f3e3c33799e333c4983df1d98d35ecf0606e82563de05c2c0b
3
+ metadata.gz: 4fc775e033107ca0ecb870139f9a3863aea5eb90e26fc2314672757b3f745ca1
4
+ data.tar.gz: 26cae2d0593b1bf5ccd27d64e89a5dbdd2bb82fffba4e5019209e6a4c07a16ed
5
5
  SHA512:
6
- metadata.gz: 3b94cebfc00d70f126ae1ee7675c123d1d2f6bbbdaba02b659c1f864392f457f7e934117f43a1f17691eefa1c3b2b160f2c2e43f368bcf39737a766d98d87e7e
7
- data.tar.gz: d21221f27e9a98c1698a870fde934dc914e6cb7fea60ad782e2f3bcfa795ea7fc6eac2034193266e73ec8194f53f6c69d4a812467612536417bfb60bf39aec07
6
+ metadata.gz: 175d6d4949afdfa9366b5706c4dc47dc81379be9b5fb698d09d49a21a3b550213b716f3e8469297d442f52f3ff52d1eed6e825dc7fadea4ace10c3f426f9acb8
7
+ data.tar.gz: 99871aa091f369f89fc780430690752364d6060905d5facaf6e535cfc0693e5869df92360a1cb443de4279f2293e0343f82c27c962abb51cdff6b9e52f7e6ddd
@@ -0,0 +1,12 @@
1
+ #SPC {
2
+ #author "jneen"
3
+ #title "oh, you know"
4
+ #game "N/A"
5
+ }
6
+
7
+ #option TempoImmunity
8
+
9
+ "INST=@8o4"
10
+
11
+ #0
12
+ l8INSTq7Fdq7Eeq7Ffge4q78cq7Fd^4r4^4
data/lib/rouge/demos/java CHANGED
@@ -1,3 +1,6 @@
1
+ import java.util.List;
2
+ import static java.util.Collections.sort;
3
+
1
4
  public class java {
2
5
  public static void main(String[] args) {
3
6
  System.out.println("Hello World");
data/lib/rouge/lexer.rb CHANGED
@@ -225,6 +225,12 @@ module Rouge
225
225
  def register(name, lexer)
226
226
  # reset an existing list of lexers
227
227
  @all = nil if defined?(@all)
228
+ name = name.to_s
229
+
230
+ if registry.key?(name)
231
+ Kernel.warn("duplicate lexer tag/alias: #{name}")
232
+ end
233
+
228
234
  registry[name.to_s] = lexer
229
235
  end
230
236
 
@@ -351,6 +357,35 @@ module Rouge
351
357
  @debug = Lexer.debug_enabled? && bool_option('debug')
352
358
  end
353
359
 
360
+ def inspect
361
+ parts = []
362
+ inspect_parts do |*new_parts|
363
+ parts.concat(new_parts)
364
+ end
365
+
366
+ parts.join
367
+ end
368
+
369
+ def inspect_parts(&b)
370
+ yield "#<", self.class.name, " "
371
+
372
+ first = true
373
+ @options.each do |k, v|
374
+ yield (first ? '?' : '&')
375
+ first = false
376
+
377
+ yield k, "=", v
378
+ end
379
+
380
+ inspect_details(&b)
381
+
382
+ yield ">"
383
+ end
384
+
385
+ def inspect_details
386
+ # pass
387
+ end
388
+
354
389
  def eager_load!
355
390
  self.class.eager_load!
356
391
  end
@@ -0,0 +1,251 @@
1
+ # documentation:
2
+ # - https://bin.smwcentral.net/u/1743/syntax_reference.html
3
+ # - https://codeberg.org/jneen/ramekin
4
+ module Rouge
5
+ module Lexers
6
+ class AddmusicK < RegexLexer
7
+ title 'AddmusicK'
8
+ desc 'AddmusicK and Ramekin MML (https://smwc.me/s/37906, https://codeberg.org/jneen/ramekin)'
9
+ tag 'addmusick'
10
+ aliases 'ramekin', 'addmusickff', 'amk', 'rmk'
11
+
12
+ filenames '*.amk', '*.rmk', '*.mml'
13
+
14
+ KEYWORDS = Set.new %w(
15
+ samples instruments instrument path default optimized pack
16
+ )
17
+
18
+ def self.detect?(analyzer)
19
+ return true if analyzer.match?(/\A(\s+|;.*?$)*#spc\s*[{]/i)
20
+ return true if analyzer.match?(/\A(\s+|;.*?$)*#option smwvtable\b/i)
21
+ return true if analyzer.match?(/\A(\s+|;.*?$)*#amk \d/i)
22
+ end
23
+
24
+ def initialize(*)
25
+ super
26
+
27
+ @highlight_macros = bool_option(:macros) { true }
28
+ end
29
+
30
+ def note_token
31
+ return Str if @last == :rest
32
+ return Name::Function if @last == :fade || @last == :arp
33
+ Str::Symbol
34
+ end
35
+
36
+ # override
37
+ # [jneen] This override is required because AddmusicK has an extremely
38
+ # free-form macro system that doesn't "look like a function call" the same
39
+ # way that normal preproc macros do. They are quite literally arbitrary
40
+ # characters that pre-empt other tokens, in all states.
41
+ #
42
+ # AddmusicK is technically *even more* lenient than this about where macros
43
+ # can show up, e.g. "F=v123" will attempt to substitute into $FF twice.
44
+ # Neither Ramekin nor this lexer support that.
45
+ def step(state, stream)
46
+ if @highlight_macros
47
+ @macros.reverse_each do |macro|
48
+ if stream.skip(macro)
49
+ token Comment::Preproc
50
+ return true
51
+ end
52
+ end
53
+ end
54
+
55
+ super(state, stream)
56
+ end
57
+
58
+ start do
59
+ @macros = []
60
+ end
61
+
62
+ state :whitespace do
63
+ rule %r/\s+/, Text
64
+ rule %r/;.*/, Comment
65
+ end
66
+
67
+ state :ties do
68
+ rule %r/\^/ do
69
+ token(note_token)
70
+ push :post_note
71
+ end
72
+ end
73
+
74
+ state :root do
75
+ mixin :whitespace
76
+ rule %r/#spc/i, Keyword, :spc_pre
77
+ rule %r/(#amk)(\s+)(\d+)/ do
78
+ groups Keyword, Text, Num
79
+ end
80
+
81
+ rule %r/(#option)(\s+)(\w+)/ do
82
+ groups Keyword, Text, Name::Tag
83
+ end
84
+
85
+ rule %r/#path\b/, Keyword, :string_arg
86
+ rule %r/#tune:\S+/, Operator::Word
87
+ rule %r(#legato/toggle), Operator::Word
88
+ rule %r(#sustain/global-toggle), Operator::Word
89
+ rule %r(#echo/toggle), Operator::Word
90
+ rule %r(#amplify:\d+), Operator::Word
91
+ rule %r(#echo/\w+:\S+), Comment::Preproc
92
+ rule %r(#tuning:\h\h\h\h), Operator::Word
93
+ arg = %r(\d+|max(?:-\d+)?)
94
+ rule %r(#adsr:#{arg}(?:,#{arg}){3}), Operator::Word
95
+ rule %r(#adsr:(?:flat|reset)), Operator::Word
96
+ rule %r(#incompatible:\w+), Comment::Preproc
97
+ rule %r(#bpm:\d+), Operator::Word
98
+ rule %r(#arp/off), Operator::Word
99
+ rule %r/#(?:arp|gliss)\[/ do
100
+ token Operator::Word
101
+ @last = :arp
102
+ push :arp
103
+ push :post_note
104
+ end
105
+
106
+ rule %r(#ifn?def\s*\w+), Comment::Preproc
107
+
108
+ rule %r/[$]\h\h/, Name::Tag
109
+ rule %r/@\d+/, Name::Tag
110
+ rule %r/@\w+/, Name::Tag
111
+
112
+ # vcmds
113
+ rule %r/[tw]\d+/, Name::Function
114
+ rule %r/[v_][+-]?\d+/, Name::Function
115
+ rule %r/y[LR]?\d+/, Name::Function
116
+ rule %r/y[C]/, Name::Function
117
+
118
+ # note intrinsics
119
+ rule %r/[il]\d+/, Name::Builtin
120
+ rule %r/[uh][+-]?\d+/, Name::Builtin
121
+ rule %r/o\d/, Name::Builtin
122
+ rule %r/q\d\h/, Name::Builtin
123
+
124
+ # notes
125
+ rule %r/[a-g][+-]?/ do
126
+ @last = :note
127
+ token Str::Symbol
128
+ push :post_note
129
+ end
130
+
131
+ mixin :ties
132
+
133
+ rule %r/#[.][\w-]*/, Name::Label
134
+
135
+ rule %r/\\/ do
136
+ @last = :fade
137
+ token Name::Function
138
+ push :post_note
139
+ end
140
+
141
+ rule %r/r/ do
142
+ @last = :rest
143
+ token Str
144
+ push :post_note
145
+ end
146
+
147
+ rule %r/p\d+,\d+(?:,\d+)?/, Name::Function
148
+
149
+ rule %r/#\d/ do
150
+ token Name::Namespace
151
+ @last = nil
152
+ end
153
+
154
+ rule %r/#(\w+)/ do |m|
155
+ if KEYWORDS.include?(m[1])
156
+ token Keyword
157
+ else
158
+ token Name::Class
159
+ end
160
+ end
161
+
162
+ rule %r/(")([^"=]+)(=)/ do |m|
163
+ @macros << m[2].strip
164
+ @macros.sort_by!(&:size)
165
+ groups Comment::Preproc, Name::Class, Comment::Preproc
166
+ push :macro
167
+ end
168
+
169
+ rule %r/".*?"/m, Str::Double
170
+ rule %r([{},/<>~&'`]), Punctuation
171
+ rule %r([|]) do
172
+ token Punctuation
173
+ @last = nil
174
+ end
175
+
176
+ rule %r/[(][!]/, Name::Namespace, :remote
177
+
178
+ rule %r/[(]\s*[\w-]+\s*[)]\d*/ do
179
+ token Name::Namespace
180
+ @last = nil
181
+ end
182
+
183
+ rule %r/[*]\d*/ do
184
+ token Name::Namespace
185
+ @last = nil
186
+ end
187
+
188
+ rule %r/\[\[?/, Name::Namespace
189
+ rule %r/\]\]?\d*/ do
190
+ token Name::Namespace
191
+ @last = nil
192
+ end
193
+
194
+ rule %r/./ do
195
+ if @highlight_macros
196
+ fallthrough!
197
+ else
198
+ token Text
199
+ end
200
+ end
201
+ end
202
+
203
+ state :post_note do
204
+ rule(/=\d+/) { token(note_token); pop! }
205
+ rule(/\d+[.]*/) { token(note_token); pop! }
206
+ rule(//) { pop! }
207
+ end
208
+
209
+ state :string_arg do
210
+ mixin :whitespace
211
+ rule %r/".*?"/, Str::Double, :pop!
212
+ rule(//) { pop! }
213
+ end
214
+
215
+ state :spc_pre do
216
+ mixin :whitespace
217
+ rule %r/[{]/, Punctuation, :spc
218
+ rule(//) { pop! }
219
+ end
220
+
221
+ state :spc do
222
+ mixin :whitespace
223
+ rule %r/#(?:title|author|game|comment)/, Name::Attribute
224
+ rule %r/".*?"/, Str::Double
225
+ rule(/[}]/) { token Punctuation; pop! 2 }
226
+ end
227
+
228
+ state :macro do
229
+ rule %r/"/, Comment::Preproc, :pop!
230
+ mixin :root
231
+ end
232
+
233
+ state :arp do
234
+ mixin :whitespace
235
+ mixin :ties
236
+ rule %r([:/]), Punctuation
237
+ rule %r/[+-]?\d+/, Num
238
+ rule %r/\]/, Operator::Word, :pop!
239
+ end
240
+
241
+ state :remote do
242
+ mixin :whitespace
243
+ rule %r/,/, Punctuation
244
+ rule %r/\d+/, Name::Namespace
245
+ rule %r/#\w+/, Keyword
246
+ rule %r/\w+/, Name::Namespace
247
+ rule %r/[)]/, Name::Namespace, :pop!
248
+ end
249
+ end
250
+ end
251
+ end
@@ -9,7 +9,7 @@ module Rouge
9
9
  desc 'Markdown based API description language.'
10
10
 
11
11
  tag 'apiblueprint'
12
- aliases 'apiblueprint', 'apib'
12
+ aliases 'apib'
13
13
  filenames '*.apib'
14
14
  mimetypes 'text/vnd.apiblueprint'
15
15
 
@@ -7,8 +7,8 @@ module Rouge
7
7
  title "AppleScript"
8
8
  desc "The AppleScript scripting language by Apple Inc. (https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html)"
9
9
 
10
- tag 'applescript'
11
- aliases 'applescript'
10
+ tag 'apple_script'
11
+ aliases 'applescript', 'osa'
12
12
 
13
13
  filenames '*.applescript', '*.scpt'
14
14
 
@@ -5,7 +5,6 @@ module Rouge
5
5
  module Lexers
6
6
  class Cypher < RegexLexer
7
7
  tag 'cypher'
8
- aliases 'cypher'
9
8
  filenames '*.cypher'
10
9
  mimetypes 'application/x-cypher-query'
11
10
 
@@ -10,7 +10,7 @@ module Rouge
10
10
  desc "Elixir language (elixir-lang.org)"
11
11
 
12
12
  tag 'elixir'
13
- aliases 'elixir', 'exs'
13
+ aliases 'exs'
14
14
 
15
15
  filenames '*.ex', '*.exs'
16
16
 
@@ -7,7 +7,7 @@ module Rouge
7
7
  title "GDScript"
8
8
  desc "The Godot Engine programming language (https://godotengine.org/)"
9
9
  tag 'gdscript'
10
- aliases 'gd', 'gdscript'
10
+ aliases 'gd', 'godot'
11
11
  filenames '*.gd'
12
12
  mimetypes 'text/x-gdscript', 'application/x-gdscript'
13
13
 
@@ -7,7 +7,7 @@ module Rouge
7
7
  title "Go"
8
8
  desc 'The Go programming language (http://golang.org)'
9
9
  tag 'go'
10
- aliases 'go', 'golang'
10
+ aliases 'golang'
11
11
  filenames '*.go'
12
12
 
13
13
  mimetypes 'text/x-go', 'application/x-go'
@@ -9,7 +9,7 @@ module Rouge
9
9
  title 'Hack'
10
10
  desc 'The Hack programming language (hacklang.org)'
11
11
  tag 'hack'
12
- aliases 'hack', 'hh'
12
+ aliases 'hh'
13
13
  filenames '*.php', '*.hh'
14
14
 
15
15
  def self.detect?(text)
@@ -7,7 +7,7 @@ module Rouge
7
7
  desc "Haxe Cross-platform Toolkit (http://haxe.org)"
8
8
 
9
9
  tag 'haxe'
10
- aliases 'hx', 'haxe'
10
+ aliases 'hx'
11
11
  filenames '*.hx'
12
12
  mimetypes 'text/haxe', 'text/x-haxe', 'text/x-hx'
13
13
 
@@ -14,11 +14,12 @@ module Rouge
14
14
  keywords = %w(
15
15
  assert break case catch continue default do else finally for
16
16
  if goto instanceof new return switch this throw try while
17
+ yield when
17
18
  )
18
19
 
19
20
  declarations = %w(
20
- abstract const enum extends final implements native private protected
21
- public static strictfp super synchronized throws transient volatile
21
+ abstract const extends final implements native permits private protected
22
+ public sealed static strictfp super synchronized throws transient volatile
22
23
  )
23
24
 
24
25
  types = %w(boolean byte char double float int long short var void)
@@ -47,12 +48,14 @@ module Rouge
47
48
  token Operator, m[4]
48
49
  end
49
50
 
51
+ rule %r/non-sealed\b/, Keyword::Declaration
52
+ rule %r/@interface\b/, Keyword::Declaration, :class
50
53
  rule %r/@#{id}/, Name::Decorator
51
54
  rule %r/(?:#{declarations.join('|')})\b/, Keyword::Declaration
52
55
  rule %r/(?:#{types.join('|')})\b/, Keyword::Type
53
56
  rule %r/(?:true|false|null)\b/, Keyword::Constant
54
- rule %r/(?:class|interface|record)\b/, Keyword::Declaration, :class
55
- rule %r/(?:import|package)\b/, Keyword::Namespace, :import
57
+ rule %r/(?:class|enum|interface|record)\b/, Keyword::Declaration, :class
58
+ rule %r/(?:import(?:\s+(?:static|module))?|package)\b/, Keyword::Namespace, :import
56
59
  rule %r/"""\s*\n.*?(?<!\\)"""/m, Str::Heredoc
57
60
  rule %r/"(\\\\|\\"|[^"])*"/, Str
58
61
  rule %r/'(?:\\.|[^\\]|\\u[0-9a-f]{4})'/, Str::Char
@@ -8,7 +8,7 @@ module Rouge
8
8
  title 'JSX'
9
9
  desc 'An XML-like syntax extension to JavaScript (facebook.github.io/jsx/)'
10
10
  tag 'jsx'
11
- aliases 'jsx', 'react'
11
+ aliases 'react'
12
12
  filenames '*.jsx'
13
13
 
14
14
  mimetypes 'text/x-jsx', 'application/x-jsx'
@@ -8,7 +8,6 @@ module Rouge
8
8
  title 'Lean'
9
9
  desc 'The Lean programming language (leanprover.github.io)'
10
10
  tag 'lean'
11
- aliases 'lean'
12
11
  filenames '*.lean'
13
12
 
14
13
  def self.keywords
@@ -103,6 +103,8 @@ module Rouge
103
103
  groups Keyword, Text, Comment, Text
104
104
  end
105
105
 
106
+ rule %r/#.*\n?/, Comment
107
+
106
108
  rule %r/(\t[\t ]*)([@-]?)/ do
107
109
  groups Text, Punctuation
108
110
  push :shell_line
@@ -26,12 +26,6 @@ module Rouge
26
26
 
27
27
  rule %r/\\./, Str::Escape
28
28
 
29
- rule %r/^[\S ]+\n(?:---*)\n/, Generic::Heading
30
- rule %r/^[\S ]+\n(?:===*)\n/, Generic::Subheading
31
-
32
- rule %r/^#(?=[^#]).*?$/, Generic::Heading
33
- rule %r/^##*.*?$/, Generic::Subheading
34
-
35
29
  rule %r/^([ \t]*)(`{3,}|~{3,})([^\n]*\n)((.*?)(\n\1)(\2))?/m do |m|
36
30
  name = m[3].strip
37
31
  sublexer =
@@ -73,6 +67,12 @@ module Rouge
73
67
 
74
68
  rule %r/(`+)(?:#{edot}|\n)+?\1/, Str::Backtick
75
69
 
70
+ rule %r/^[\S ]+\n(?:---*)\n/, Generic::Heading
71
+ rule %r/^[\S ]+\n(?:===*)\n/, Generic::Subheading
72
+
73
+ rule %r/^#(?=[^#]).*?$/, Generic::Heading
74
+ rule %r/^##*.*?$/, Generic::Subheading
75
+
76
76
  # various uses of * are in order of precedence
77
77
 
78
78
  # line breaks
@@ -139,6 +139,7 @@ module Rouge
139
139
 
140
140
  rule %r/[(]/ do
141
141
  token Punctuation
142
+ pop!
142
143
  push :inline_title
143
144
  push :inline_url
144
145
  end
@@ -9,7 +9,6 @@ module Rouge
9
9
  title "Mojo"
10
10
  desc "The Mojo programming language (modular.com)"
11
11
  tag 'mojo'
12
- aliases 'mojo'
13
12
  filenames '*.mojo', '*.🔥'
14
13
  mimetypes 'text/x-mojo', 'application/x-mojo'
15
14
 
@@ -17,13 +17,13 @@ module Rouge
17
17
  return true if text.shebang? 'perl'
18
18
  end
19
19
 
20
- keywords = %w(
20
+ KEYWORDS = Set.new %w(
21
21
  case continue do else elsif for foreach if last my next our
22
22
  redo reset then unless until while use print new BEGIN CHECK
23
23
  INIT END return
24
24
  )
25
25
 
26
- builtins = %w(
26
+ BUILTINS = Set.new %w(
27
27
  abs accept alarm atan2 bind binmode bless caller chdir chmod
28
28
  chomp chop chown chr chroot close closedir connect continue cos
29
29
  crypt dbmclose dbmopen defined delete die dump each endgrent
@@ -49,25 +49,108 @@ module Rouge
49
49
  utime values vec wait waitpid wantarray warn write
50
50
  )
51
51
 
52
+ OPERATOR_WORDS = Set.new %w(eq lt gt le ge ne not and or cmp)
53
+
52
54
  re_tok = Str::Regex
53
55
 
54
56
  state :balanced_regex do
55
- rule %r(/(\\[\\/]|[^/])*/[egimosx]*)m, re_tok, :pop!
56
- rule %r(!(\\[\\!]|[^!])*![egimosx]*)m, re_tok, :pop!
57
- rule %r(\\(\\\\|[^\\])*\\[egimosx]*)m, re_tok, :pop!
58
- rule %r({(\\[\\}]|[^}])*}[egimosx]*), re_tok, :pop!
59
- rule %r(<(\\[\\>]|[^>])*>[egimosx]*), re_tok, :pop!
60
- rule %r(\[(\\[\\\]]|[^\]])*\][egimosx]*), re_tok, :pop!
61
- rule %r[\((\\[\\\)]|[^\)])*\)[egimosx]*], re_tok, :pop!
62
- rule %r(@(\\[\\@]|[^@])*@[egimosx]*), re_tok, :pop!
63
- rule %r(%(\\[\\%]|[^%])*%[egimosx]*), re_tok, :pop!
64
- rule %r(\$(\\[\\\$]|[^\$])*\$[egimosx]*), re_tok, :pop!
57
+ rule %r/\s+/, Text
58
+ rule %r/./ do |m|
59
+ pop!
60
+ open_regex!(m[0])
61
+ token Str::Delimiter
62
+ end
65
63
  end
66
64
 
67
- state :root do
65
+ state :continued_regex do
66
+ mixin :regex
67
+ end
68
+
69
+ state :regex_flags do
70
+ rule %r/[msixpodualngcr]+/, Str::Affix
71
+ rule(//) { pop! }
72
+ end
73
+
74
+ state :regex_escapes do
75
+ rule %r/\\[0-7][0-7][0-7]/, Str::Escape
76
+ rule %r/\\x\h\h/, Str::Escape
77
+ rule %r/\\.(?:[{]\w+[}])?/, Str::Escape
78
+ end
79
+
80
+ state :regex do
81
+ rule %r/./ do |m|
82
+ if m[0] == @regex_end
83
+ token Str::Delimiter
84
+ goto :regex_flags
85
+ else
86
+ fallthrough!
87
+ end
88
+ end
89
+
90
+ mixin :regex_escapes
91
+ rule %r/[{]\d+(?:,\d+)?[}]/, Operator
92
+ rule %r/\[\^?/, Punctuation, :regex_char_class
93
+ rule %r/[?]|[.]|[|]|[*+][?]?/, Operator
94
+ rule %r/[(](?:[?][=!<:]?)?/, Punctuation
95
+ rule %r/[(][?]<!/, Punctuation
96
+ rule %r/[{})]/, Punctuation
97
+ rule %r/./, Str::Regex
98
+ end
99
+
100
+ state :regex_char_class do
101
+ rule(/\^/) { token Punctuation; goto :regex_char_class_inner }
102
+ rule(/-/) { token Str::Regex; goto :regex_char_class_inner }
103
+ rule(//) { goto :regex_char_class_inner }
104
+ end
105
+
106
+ state :regex_char_class_inner do
107
+ mixin :regex_escapes
108
+ rule %r/-(?!\])/, Punctuation
109
+ rule %r/\\./, Str::Escape
110
+ rule %r/[^-\]\\]+/, Str::Regex
111
+ rule %r/\]/, Punctuation, :pop!
112
+ end
113
+
114
+ BALANCED_DELIMITERS = {
115
+ '{' => '}',
116
+ '(' => ')',
117
+ '[' => ']',
118
+ '<' => '>',
119
+ }
120
+
121
+ def open_regex!(delimiter)
122
+ @regex_end = BALANCED_DELIMITERS.fetch(delimiter, delimiter)
123
+ push :regex
124
+ end
125
+
126
+ def open_regex_operator!(delimiter)
127
+ if BALANCED_DELIMITERS.key?(delimiter)
128
+ push :balanced_regex
129
+ else
130
+ push :continued_regex
131
+ end
132
+
133
+ open_regex!(delimiter)
134
+ end
135
+
136
+ state :expr_start do
137
+ mixin :whitespace
138
+ rule %r(/) do
139
+ open_regex!('/')
140
+ token Str::Delimiter
141
+ end
142
+
143
+ rule(//) { pop! }
144
+ end
145
+
146
+ state :whitespace do
68
147
  rule %r/#.*/, Comment::Single
148
+ rule %r/\s+/, Text
69
149
  rule %r/^=[a-zA-Z0-9]+\s+.*?\n=cut/m, Comment::Multiline
70
- rule %r/(?:#{keywords.join('|')})\b/, Keyword
150
+ end
151
+
152
+ state :root do
153
+ mixin :whitespace
71
154
 
72
155
  rule %r/(format)(\s+)([a-zA-Z0-9_]+)(\s*)(=)(\s*\n)/ do
73
156
  groups Keyword, Text, Name, Text, Punctuation, Text
@@ -75,34 +158,37 @@ module Rouge
75
158
  push :format
76
159
  end
77
160
 
78
- rule %r/(?:eq|lt|gt|le|ge|ne|not|and|or|cmp)\b/, Operator::Word
79
-
80
- # substitution/transliteration: balanced delimiters
81
- rule %r((?:s|tr|y){(\\\\|\\}|[^}])*}\s*), re_tok, :balanced_regex
82
- rule %r((?:s|tr|y)<(\\\\|\\>|[^>])*>\s*), re_tok, :balanced_regex
83
- rule %r((?:s|tr|y)\[(\\\\|\\\]|[^\]])*\]\s*), re_tok, :balanced_regex
84
- rule %r[(?:s|tr|y)\((\\\\|\\\)|[^\)])*\)\s*], re_tok, :balanced_regex
85
-
86
- # substitution/transliteration: arbitrary non-whitespace delimiters
87
- rule %r((?:s|tr|y)\s*([^\w\s])((\\\\|\\\1)|[^\1])*?\1((\\\\|\\\1)|[^\1])*?\1[msixpodualngcr]*)m, re_tok
88
- rule %r((?:s|tr|y)\s+(\w)((\\\\|\\\1)|[^\1])*?\1((\\\\|\\\1)|[^\1])*?\1[msixpodualngcr]*)m, re_tok
89
-
90
- # matches: common case, m-optional
91
- rule %r(m?/(\\\\|\\/|[^/\n])*/[msixpodualngc]*), re_tok
92
- rule %r(m(?=[/!\\{<\[\(@%\$])), re_tok, :balanced_regex
161
+ rule %r/\w+/ do |m|
162
+ w = m[0]
163
+ if KEYWORDS.include?(w)
164
+ token Keyword
165
+ elsif OPERATOR_WORDS.include?(w)
166
+ token Operator::Word
167
+ else
168
+ fallthrough!
169
+ end
170
+ end
93
171
 
94
- # arbitrary non-whitespace delimiters
95
- rule %r(m\s*([^\w\s])((\\\\|\\\1)|[^\1])*?\1[msixpodualngc]*)m, re_tok
96
- rule %r(m\s+(\w)((\\\\|\\\1)|[^\1])*?\1[msixpodualngc]*)m, re_tok
172
+ rule %r{(?=[a-z_]\w*(\s*#.*\n)*\s*=>)}i do
173
+ push :fat_comma
174
+ end
97
175
 
98
- rule %r(((?<==~)|(?<=\())\s*/(\\\\|\\/|[^/])*/[msixpodualngc]*),
99
- re_tok, :balanced_regex
176
+ # non-whitespace delimiters that match \w are allowed only
177
+ # if there is whitespace between the operator and the delimiter.
178
+ # here we use a \b to detect that case in a way that shouldn't
179
+ # cause backtracking explosion.
180
+ regex_delim = /[^\w\s]|\b\w/
100
181
 
101
- rule %r/\s+/, Text
182
+ rule %r/(s|tr|y)(\s*)(#{regex_delim})/ do |m|
183
+ open_regex_operator!(m[3])
184
+ groups Str::Affix, Text, Str::Delimiter
185
+ end
102
186
 
103
- rule(/(?=[a-z_]\w*(\s*#.*\n)*\s*=>)/i) { push :fat_comma }
187
+ rule %r/(m)(\s*)(#{regex_delim})/ do |m|
188
+ open_regex!(m[3])
189
+ groups Str::Affix, Text, Str::Delimiter
190
+ end
104
191
 
105
- rule %r/(?:#{builtins.join('|')})\b/, Name::Builtin
106
192
  rule %r/((__(DIE|WARN)__)|(DATA|STD(IN|OUT|ERR)))\b/,
107
193
  Name::Builtin::Pseudo
108
194
 
@@ -113,7 +199,9 @@ module Rouge
113
199
  rule %r/\$[\\"'\[\]&`+*.,;=%~?@$!<>(^\|\/_-](?!\w)/, Name::Variable::Global
114
200
  rule %r/[$@%&*][$@%&*#_]*(?=[a-z{\[;])/i, Name::Variable, :varname
115
201
 
116
- rule %r/[-+\/*%=<>&^\|!\\~]=?/, Operator
202
+ rule %r/\[\]|\*\*|::|<<|>>|>=|<=|<=>|={3}|!=|=~|!~|&&?|\|\||\.{1,3}/,
203
+ Operator, :expr_start
204
+ rule %r/[-+\/*%=<>&^\|!\\~]=?/, Operator, :expr_start
117
205
 
118
206
  rule %r/0_?[0-7]+(_[0-7]+)*/, Num::Oct
119
207
  rule %r/0x[0-9A-Fa-f]+(_[0-9A-Fa-f]+)*/, Num::Hex
@@ -133,11 +221,20 @@ module Rouge
133
221
  rule %r/(q|qq|qw|qr|qx)</, Str::Other, :lt_string
134
222
  rule %r/(q|qq|qw|qr|qx)(\W)(.|\n)*?\2/, Str::Other
135
223
 
136
- rule %r/package\s+/, Keyword, :modulename
137
- rule %r/sub\s+/, Keyword, :funcname
138
- rule %r/\[\]|\*\*|::|<<|>>|>=|<=|<=>|={3}|!=|=~|!~|&&?|\|\||\.{1,3}/,
139
- Operator
140
- rule %r/[()\[\]:;,<>\/?{}]/, Punctuation
224
+ rule %r/package\b/, Keyword, :modulename
225
+ rule %r/sub\b/, Keyword, :funcname
226
+ rule %r/[(]/, Punctuation, :expr_start
227
+ rule %r/[)\[\]:;,<>\/?{}]/, Punctuation
228
+
229
+ rule %r/[a-z]\w*/ do |m|
230
+ w = m[0]
231
+ if BUILTINS.include?(w)
232
+ token Name::Builtin
233
+ else
234
+ fallthrough!
235
+ end
236
+ end
237
+
141
238
  rule(/(?=\w)/) { push :name }
142
239
  end
143
240
 
@@ -7,7 +7,7 @@ module Rouge
7
7
  title "PHP"
8
8
  desc "The PHP scripting language (php.net)"
9
9
  tag 'php'
10
- aliases 'php', 'php3', 'php4', 'php5'
10
+ aliases 'php3', 'php4', 'php5'
11
11
  filenames '*.php', '*.php[345t]','*.phtml',
12
12
  # Support Drupal file extensions, see:
13
13
  # https://github.com/gitlabhq/gitlabhq/issues/8900
@@ -5,7 +5,6 @@ module Rouge
5
5
  class Plist < RegexLexer
6
6
  desc 'plist'
7
7
  tag 'plist'
8
- aliases 'plist'
9
8
  filenames '*.plist', '*.pbxproj'
10
9
 
11
10
  mimetypes 'text/x-plist', 'application/x-plist'
@@ -8,7 +8,7 @@ module Rouge
8
8
  title "PostScript"
9
9
  desc "The PostScript language (adobe.com/devnet/postscript.html)"
10
10
  tag "postscript"
11
- aliases "postscr", "postscript", "ps", "eps"
11
+ aliases "postscr", "ps", "eps"
12
12
  filenames "*.ps", "*.eps"
13
13
  mimetypes "application/postscript"
14
14
 
@@ -7,7 +7,6 @@ module Rouge
7
7
  title "Prolog"
8
8
  desc "The Prolog programming language (http://en.wikipedia.org/wiki/Prolog)"
9
9
  tag 'prolog'
10
- aliases 'prolog'
11
10
  filenames '*.pro', '*.P', '*.prolog', '*.pl'
12
11
  mimetypes 'text/x-prolog'
13
12
 
@@ -5,7 +5,6 @@ module Rouge
5
5
  class Prometheus < RegexLexer
6
6
  desc 'prometheus'
7
7
  tag 'prometheus'
8
- aliases 'prometheus'
9
8
  filenames '*.prometheus'
10
9
 
11
10
  mimetypes 'text/x-prometheus', 'application/x-prometheus'
@@ -11,10 +11,10 @@ module Rouge
11
11
  filenames '*.properties'
12
12
  mimetypes 'text/x-java-properties'
13
13
 
14
- identifier = /[\w.-]+/
14
+ identifier = /(?:[\w.-]|\\u\h{4}|\\.)+/
15
15
 
16
16
  state :basic do
17
- rule %r/[!#].*?\n/, Comment
17
+ rule %r/[!#].*/, Comment
18
18
  rule %r/\s+/, Text
19
19
  rule %r/\\\n/, Str::Escape
20
20
  end
@@ -9,7 +9,6 @@ module Rouge
9
9
  title "QML"
10
10
  desc 'QML, a UI markup language'
11
11
  tag 'qml'
12
- aliases 'qml'
13
12
  filenames '*.qml'
14
13
 
15
14
  mimetypes 'application/x-qml', 'text/x-qml'
@@ -7,7 +7,7 @@ module Rouge
7
7
  title "R"
8
8
  desc 'The R statistics language (r-project.org)'
9
9
  tag 'r'
10
- aliases 'r', 'R', 's', 'S'
10
+ aliases 'R', 's', 'S'
11
11
  filenames '*.R', '*.r', '.Rhistory', '.Rprofile'
12
12
  mimetypes 'text/x-r-source', 'text/x-r', 'text/x-R'
13
13
 
@@ -7,7 +7,6 @@ module Rouge
7
7
  title "Scala"
8
8
  desc "The Scala programming language (scala-lang.org)"
9
9
  tag 'scala'
10
- aliases 'scala'
11
10
  filenames '*.scala', '*.sbt'
12
11
 
13
12
  mimetypes 'text/x-scala', 'application/x-scala'
@@ -161,9 +161,21 @@ module Rouge
161
161
  mixin :root
162
162
  end
163
163
 
164
+ state :curly_interp do
165
+ rule %r/[}]/, Str::Interpol, :pop!
166
+ rule %r/[{]/, Operator, :curly_inner
167
+ mixin :root
168
+ end
169
+
170
+ state :curly_inner do
171
+ rule %r/[{]/, Operator, :push
172
+ rule %r/[}]/, Operator, :pop!
173
+ mixin :root
174
+ end
175
+
164
176
  state :math do
165
177
  rule %r/\)\)/, Keyword, :pop!
166
- rule %r([-+*/%^|&!]|\*\*|\|\|), Operator
178
+ rule %r([-+*/%^|&!]|\*\*|\|\||<<|>>), Operator
167
179
  rule %r/\d+(#\w+)?/, Num
168
180
  mixin :root
169
181
  end
@@ -189,7 +201,11 @@ module Rouge
189
201
  rule %r/\\$/, Str::Escape # line continuation
190
202
  rule %r/\\./, Str::Escape
191
203
  rule %r/\$\(\(/, Keyword, :math
192
- rule %r/\$\(/, Str::Interpol, :paren_interp
204
+ rule %r/\$[(]/, Str::Interpol, :paren_interp
205
+
206
+ # see https://www.gnu.org/software/bash/manual/bash.html#Command-Substitution-1
207
+ rule %r/\$[{][\s|]/, Str::Interpol, :curly_interp
208
+
193
209
  rule %r/\${#?/, Keyword, :curly
194
210
  rule %r/`/, Str::Backtick, :backticks
195
211
  rule %r/\$#?(\w+|.)/, Name::Variable
@@ -7,7 +7,6 @@ module Rouge
7
7
  title "Smarty"
8
8
  desc 'Smarty Template Engine'
9
9
  tag 'smarty'
10
- aliases 'smarty'
11
10
  filenames '*.tpl', '*.smarty'
12
11
  mimetypes 'application/x-smarty', 'text/x-smarty'
13
12
 
@@ -6,7 +6,6 @@ module Rouge
6
6
  title 'TAP'
7
7
  desc 'Test Anything Protocol'
8
8
  tag 'tap'
9
- aliases 'tap'
10
9
  filenames '*.tap'
11
10
 
12
11
  mimetypes 'text/x-tap', 'application/x-tap'
@@ -5,7 +5,6 @@ module Rouge
5
5
  class Tulip < RegexLexer
6
6
  desc 'the tulip programming language (twitter.com/tuliplang)'
7
7
  tag 'tulip'
8
- aliases 'tulip'
9
8
 
10
9
  filenames '*.tlp'
11
10
 
@@ -43,8 +43,10 @@ module Rouge
43
43
  state :whitespace do
44
44
  rule %r/\s+/, Text
45
45
  rule %r/\n/, Text
46
- # Find Comments (VHDL doesn't support multiline comments)
46
+ # Find single-line comments "-- ..."
47
47
  rule %r/--.*$/, Comment::Single
48
+ # Find delimited comments "/* ... */"
49
+ rule %r{/\*.*?\*/}m, Comment::Multiline
48
50
  end
49
51
 
50
52
  state :statements do
@@ -5,6 +5,19 @@ require_relative 'html'
5
5
  module Rouge
6
6
  module Lexers
7
7
  class Vue < HTML
8
+ # HTML extended with Vue template attribute shorthands.
9
+ # Used as the delegate lexer for <template> content so that directives
10
+ # like @click and @click.disabled are recognised without polluting the plain
11
+ # HTML lexer with framework-specific syntax.
12
+ class TemplateHTML < HTML
13
+ prepend :tag do
14
+ rule %r/([@a-zA-Z0-9_:#\[\]()*.-]+\s*)(=)(\s*)/m do
15
+ groups Name::Attribute, Operator, Text
16
+ push :attr
17
+ end
18
+ end
19
+ end
20
+
8
21
  desc 'Vue.js single-file components'
9
22
  tag 'vue'
10
23
  aliases 'vuejs'
@@ -38,7 +51,7 @@ module Rouge
38
51
  prepend :root do
39
52
  rule %r/(<)(\s*)(template)/ do
40
53
  groups Name::Tag, Text, Keyword
41
- @lang = HTML
54
+ @lang = TemplateHTML
42
55
  push :template
43
56
  push :lang_tag
44
57
  end
@@ -59,7 +72,10 @@ module Rouge
59
72
  end
60
73
 
61
74
  prepend :tag do
62
- rule %r/[a-zA-Z0-9_:#\[\]()*.-]+\s*=\s*/m, Name::Attribute, :attr
75
+ rule %r/([a-zA-Z0-9_:#\[\]()*.-]+\s*)(=)(\s*)/m do
76
+ groups Name::Attribute, Operator, Text
77
+ push :attr
78
+ end
63
79
  end
64
80
 
65
81
  state :style do
@@ -281,6 +281,18 @@ module Rouge
281
281
  end
282
282
  end
283
283
 
284
+ def inspect_details
285
+ yield ' stack:['
286
+ first = true
287
+ stack.each do |state|
288
+ yield ',' unless first
289
+ first = false
290
+ yield state.name
291
+ end
292
+
293
+ yield ']'
294
+ end
295
+
284
296
  # @private
285
297
  def get_state(state_name)
286
298
  self.class.get_state(state_name)
@@ -60,7 +60,8 @@ module Rouge
60
60
  Literal::Date,
61
61
  Literal::String::Symbol, :fg => :pink_merengue, :bold => true
62
62
  style Literal::String, :fg => :dune, :bold => true
63
- style Literal::String::Affix, :fg => :sandy, :bold => true
63
+ style Literal::String::Affix,
64
+ Literal::String::Delimiter, :fg => :sandy, :bold => true
64
65
  style Literal::String::Escape,
65
66
  Literal::String::Char,
66
67
  Literal::String::Interpol, :fg => :backlit, :bold => true
data/lib/rouge/version.rb CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  module Rouge
5
5
  def self.version
6
- "5.0.0"
6
+ "5.1.0"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rouge
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeanine Adkisson
@@ -39,10 +39,11 @@ files:
39
39
  - lib/rouge/demos/abap
40
40
  - lib/rouge/demos/actionscript
41
41
  - lib/rouge/demos/ada
42
+ - lib/rouge/demos/addmusick
42
43
  - lib/rouge/demos/apache
43
44
  - lib/rouge/demos/apex
44
45
  - lib/rouge/demos/apiblueprint
45
- - lib/rouge/demos/applescript
46
+ - lib/rouge/demos/apple_script
46
47
  - lib/rouge/demos/armasm
47
48
  - lib/rouge/demos/augeas
48
49
  - lib/rouge/demos/awk
@@ -298,6 +299,7 @@ files:
298
299
  - lib/rouge/lexers/abap/builtins.rb
299
300
  - lib/rouge/lexers/actionscript.rb
300
301
  - lib/rouge/lexers/ada.rb
302
+ - lib/rouge/lexers/addmusick.rb
301
303
  - lib/rouge/lexers/apache.rb
302
304
  - lib/rouge/lexers/apache/keywords.rb
303
305
  - lib/rouge/lexers/apex.rb
File without changes