rouge 4.1.3 → 4.7.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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -7
  3. data/LICENSE +2 -1
  4. data/lib/rouge/cli.rb +4 -5
  5. data/lib/rouge/demos/bicep +10 -0
  6. data/lib/rouge/demos/cobol +103 -0
  7. data/lib/rouge/demos/codeowners +6 -0
  8. data/lib/rouge/demos/gjs +23 -0
  9. data/lib/rouge/demos/gts +36 -0
  10. data/lib/rouge/demos/iecst +21 -0
  11. data/lib/rouge/demos/json5 +12 -0
  12. data/lib/rouge/demos/mojo +10 -0
  13. data/lib/rouge/demos/p4 +99 -0
  14. data/lib/rouge/demos/svelte +29 -0
  15. data/lib/rouge/formatters/html_legacy.rb +0 -3
  16. data/lib/rouge/guessers/disambiguation.rb +24 -3
  17. data/lib/rouge/lexer.rb +8 -6
  18. data/lib/rouge/lexers/ada.rb +5 -5
  19. data/lib/rouge/lexers/bicep.rb +111 -0
  20. data/lib/rouge/lexers/bpf.rb +10 -10
  21. data/lib/rouge/lexers/brainfuck.rb +1 -0
  22. data/lib/rouge/lexers/clean.rb +4 -4
  23. data/lib/rouge/lexers/cobol.rb +137 -0
  24. data/lib/rouge/lexers/codeowners.rb +30 -0
  25. data/lib/rouge/lexers/cpp.rb +5 -4
  26. data/lib/rouge/lexers/crystal.rb +17 -17
  27. data/lib/rouge/lexers/csharp.rb +37 -34
  28. data/lib/rouge/lexers/css.rb +192 -150
  29. data/lib/rouge/lexers/dart.rb +1 -1
  30. data/lib/rouge/lexers/docker.rb +2 -2
  31. data/lib/rouge/lexers/ecl.rb +2 -2
  32. data/lib/rouge/lexers/eiffel.rb +1 -1
  33. data/lib/rouge/lexers/elixir.rb +5 -1
  34. data/lib/rouge/lexers/gdscript.rb +4 -4
  35. data/lib/rouge/lexers/ghc_cmm.rb +3 -3
  36. data/lib/rouge/lexers/gjs.rb +39 -0
  37. data/lib/rouge/lexers/go.rb +7 -5
  38. data/lib/rouge/lexers/groovy.rb +6 -4
  39. data/lib/rouge/lexers/gts.rb +39 -0
  40. data/lib/rouge/lexers/hcl.rb +1 -0
  41. data/lib/rouge/lexers/html.rb +1 -1
  42. data/lib/rouge/lexers/iecst.rb +92 -0
  43. data/lib/rouge/lexers/ini.rb +7 -5
  44. data/lib/rouge/lexers/java.rb +1 -1
  45. data/lib/rouge/lexers/javascript.rb +4 -4
  46. data/lib/rouge/lexers/json5.rb +74 -0
  47. data/lib/rouge/lexers/julia.rb +3 -2
  48. data/lib/rouge/lexers/kotlin.rb +1 -1
  49. data/lib/rouge/lexers/lua.rb +24 -3
  50. data/lib/rouge/lexers/make.rb +5 -1
  51. data/lib/rouge/lexers/markdown.rb +2 -1
  52. data/lib/rouge/lexers/mathematica.rb +1 -1
  53. data/lib/rouge/lexers/meson.rb +0 -1
  54. data/lib/rouge/lexers/mojo.rb +35 -0
  55. data/lib/rouge/lexers/nasm.rb +5 -4
  56. data/lib/rouge/lexers/nginx.rb +1 -0
  57. data/lib/rouge/lexers/objective_c/common.rb +0 -2
  58. data/lib/rouge/lexers/objective_c.rb +1 -1
  59. data/lib/rouge/lexers/ocl.rb +2 -2
  60. data/lib/rouge/lexers/openedge.rb +0 -2
  61. data/lib/rouge/lexers/p4.rb +81 -0
  62. data/lib/rouge/lexers/php/keywords.rb +86 -136
  63. data/lib/rouge/lexers/php.rb +42 -2
  64. data/lib/rouge/lexers/plsql.rb +5 -5
  65. data/lib/rouge/lexers/python.rb +59 -32
  66. data/lib/rouge/lexers/robot_framework.rb +1 -1
  67. data/lib/rouge/lexers/ruby.rb +21 -21
  68. data/lib/rouge/lexers/sass/common.rb +1 -1
  69. data/lib/rouge/lexers/scala.rb +5 -2
  70. data/lib/rouge/lexers/sql.rb +1 -1
  71. data/lib/rouge/lexers/svelte.rb +91 -0
  72. data/lib/rouge/lexers/syzlang.rb +0 -1
  73. data/lib/rouge/lexers/tcl.rb +7 -2
  74. data/lib/rouge/lexers/terraform.rb +4 -3
  75. data/lib/rouge/lexers/toml.rb +56 -45
  76. data/lib/rouge/lexers/ttcn3.rb +0 -2
  77. data/lib/rouge/lexers/typescript/common.rb +9 -0
  78. data/lib/rouge/lexers/xojo.rb +6 -6
  79. data/lib/rouge/lexers/yang.rb +1 -1
  80. data/lib/rouge/regex_lexer.rb +13 -0
  81. data/lib/rouge/tex_theme_renderer.rb +1 -1
  82. data/lib/rouge/themes/base16.rb +23 -18
  83. data/lib/rouge/themes/bw.rb +1 -0
  84. data/lib/rouge/themes/colorful.rb +1 -0
  85. data/lib/rouge/themes/github.rb +1 -0
  86. data/lib/rouge/themes/gruvbox.rb +4 -1
  87. data/lib/rouge/themes/igor_pro.rb +3 -0
  88. data/lib/rouge/themes/magritte.rb +1 -0
  89. data/lib/rouge/themes/molokai.rb +2 -1
  90. data/lib/rouge/themes/monokai.rb +2 -1
  91. data/lib/rouge/themes/monokai_sublime.rb +4 -3
  92. data/lib/rouge/themes/pastie.rb +1 -0
  93. data/lib/rouge/themes/thankful_eyes.rb +1 -0
  94. data/lib/rouge/themes/tulip.rb +1 -0
  95. data/lib/rouge/token.rb +2 -1
  96. data/lib/rouge/version.rb +1 -1
  97. metadata +23 -6
@@ -100,6 +100,11 @@ module Rouge
100
100
  end
101
101
 
102
102
  state :names do
103
+ rule %r/(?:public|protected|private)\(set\)/i do
104
+ push :in_visibility
105
+ token Keyword
106
+ end
107
+
103
108
  rule %r/#{id_with_ns}(?=\s*\()/ do |m|
104
109
  name = m[0].downcase
105
110
  if self.class.keywords.include? name
@@ -179,7 +184,7 @@ module Rouge
179
184
 
180
185
  # numbers
181
186
  rule %r/(\d[_\d]*)?\.(\d[_\d]*)?(e[+-]?\d[_\d]*)?/i, Num::Float
182
- rule %r/0[0-7][0-7_]*/, Num::Oct
187
+ rule %r/0o?[0-7][0-7_]*/i, Num::Oct
183
188
  rule %r/0b[01][01_]*/i, Num::Bin
184
189
  rule %r/0x[a-f0-9][a-f0-9_]*/i, Num::Hex
185
190
  rule %r/\d[_\d]*/, Num::Integer
@@ -243,6 +248,13 @@ module Rouge
243
248
  groups Keyword::Declaration, Text, Name::Class
244
249
  end
245
250
 
251
+ rule %r/(enum)
252
+ (\s+)
253
+ (#{id_with_ns})/ix do |m|
254
+ groups Keyword::Declaration, Text, Name::Class
255
+ push :in_enum
256
+ end
257
+
246
258
  mixin :names
247
259
 
248
260
  rule %r/[;,\(\)\{\}\[\]]/, Punctuation
@@ -280,6 +292,9 @@ module Rouge
280
292
  end
281
293
 
282
294
  state :in_const do
295
+ rule %r/(\??#{id})(\s+)(#{id})/i do
296
+ groups Keyword::Type, Text, Name::Constant
297
+ end
283
298
  rule id, Name::Constant
284
299
  rule %r/=/, Operator, :in_assign
285
300
  mixin :escape
@@ -307,7 +322,8 @@ module Rouge
307
322
  rule %r/,/, Punctuation
308
323
  rule %r/[.]{3}/, Punctuation
309
324
  rule %r/=/, Operator, :in_assign
310
- rule %r/\b(?:public|protected|private|readonly)\b/i, Keyword
325
+ rule %r/\b(?:public|protected|private|readonly)(?:\(set\)|\b)/i, Keyword
326
+ rule %r/\breadonly\b/i, Keyword
311
327
  rule %r/\??#{id}/, Keyword::Type, :in_assign
312
328
  mixin :escape
313
329
  mixin :whitespace
@@ -369,6 +385,7 @@ module Rouge
369
385
  end
370
386
 
371
387
  state :in_visibility do
388
+ rule %r/\b(?:public|protected|private)(?:\(set\)|\b)/i, Keyword
372
389
  rule %r/\b(?:readonly|static)\b/i, Keyword
373
390
  rule %r/(?=(abstract|const|function)\b)/i, Keyword, :pop!
374
391
  rule %r/\??#{id}/, Keyword::Type, :pop!
@@ -376,6 +393,29 @@ module Rouge
376
393
  mixin :whitespace
377
394
  mixin :return
378
395
  end
396
+
397
+ state :in_enum do
398
+ rule %r/:/, Punctuation, :in_enum_base_type
399
+ rule %r/\{/, Punctuation, :in_enum_body
400
+ mixin :escape
401
+ mixin :whitespace
402
+ mixin :return
403
+ end
404
+
405
+ state :in_enum_base_type do
406
+ rule id, Keyword::Type, :pop!
407
+ mixin :escape
408
+ mixin :whitespace
409
+ mixin :return
410
+ end
411
+
412
+ state :in_enum_body do
413
+ rule %r/\}/, Punctuation, :pop!
414
+ rule %r/(case)(\s+)(#{id})/i do
415
+ groups Keyword, Text, Name::Constant
416
+ end
417
+ mixin :php
418
+ end
379
419
  end
380
420
  end
381
421
  end
@@ -472,7 +472,7 @@ module Rouge
472
472
  # A double-quoted string refers to a database object in our default SQL
473
473
  rule %r/"/, Operator, :double_string
474
474
  # preprocessor directive treated as special comment
475
- rule %r/(\$(?:IF|THEN|ELSE|ELSIF|ERROR|END|(?:\$\$?\w[\w\d]*)))(\s+)/im do
475
+ rule %r/(\$(?:IF|THEN|ELSE|ELSIF|ERROR|END|(?:\$\$?[a-z]\w*)))(\s+)/im do
476
476
  groups Comment::Preproc, Text
477
477
  end
478
478
 
@@ -503,7 +503,7 @@ module Rouge
503
503
  # Special processing for keywords with multiple contexts
504
504
  #
505
505
  # this madness is to keep the word "replace" from being treated as a builtin function in this context
506
- rule %r/(create)(\s+)(?:(or)(\s+)(replace)(\s+))?(package|function|procedure|type)(?:(\s+)(body))?(\s+)(\w[\w\d\$]*)/im do
506
+ rule %r/(create)(\s+)(?:(or)(\s+)(replace)(\s+))?(package|function|procedure|type)(?:(\s+)(body))?(\s+)([a-z][\w$]*)/im do
507
507
  groups Keyword::Reserved, Text, Keyword::Reserved, Text, Keyword::Reserved, Text, Keyword::Reserved, Text, Keyword::Reserved, Text, Name
508
508
  end
509
509
  # similar for MERGE keywords
@@ -515,7 +515,7 @@ module Rouge
515
515
  # General keyword classification with sepcial attention to names
516
516
  # in a chained "dot" notation.
517
517
  #
518
- rule %r/(\w[\w\d\$]*)(\.(?=\w))?/ do |m|
518
+ rule %r/([a-zA-Z][\w$]*)(\.(?=\w))?/ do |m|
519
519
  if self.class.keywords_type.include? m[1].upcase
520
520
  tok = Keyword::Type
521
521
  elsif self.class.keywords_func.include? m[1].upcase
@@ -556,11 +556,11 @@ module Rouge
556
556
 
557
557
  state :dotnames do
558
558
  # if we are followed by a dot and another name, we are an ordinary name
559
- rule %r/(\w[\w\d\$]*)(\.(?=\w))/ do
559
+ rule %r/([a-zA-Z][\w\$]*)(\.(?=\w))/ do
560
560
  groups Name, Punctuation
561
561
  end
562
562
  # this rule WILL be true if something pushed into our state. That is our state contract
563
- rule %r/\w[\w\d\$]*/ do |m|
563
+ rule %r/[a-zA-Z][\w\$]*/ do |m|
564
564
  if self.class.keywords_func.include? m[0].upcase
565
565
  # The Function lookup allows collection methods like COUNT, FIRST, LAST, etc.. to be
566
566
  # classified correctly. Occasionally misidentifies ordinary names as builtin functions,
@@ -8,8 +8,8 @@ module Rouge
8
8
  desc "The Python programming language (python.org)"
9
9
  tag 'python'
10
10
  aliases 'py'
11
- filenames '*.py', '*.pyw', '*.sc', 'SConstruct', 'SConscript', '*.tac',
12
- '*.bzl', 'BUCK', 'BUILD', 'BUILD.bazel', 'WORKSPACE'
11
+ filenames '*.py', '*.pyi', '*.pyw', '*.sc', 'SConstruct', 'SConscript',
12
+ '*.tac', '*.bzl', 'BUCK', 'BUILD', 'BUILD.bazel', 'WORKSPACE'
13
13
  mimetypes 'text/x-python', 'application/x-python'
14
14
 
15
15
  def self.detect?(text)
@@ -20,22 +20,24 @@ module Rouge
20
20
  @keywords ||= %w(
21
21
  assert break continue del elif else except exec
22
22
  finally for global if lambda pass print raise
23
- return try while yield as with from import yield
23
+ return try while yield as with from import
24
24
  async await nonlocal
25
25
  )
26
26
  end
27
27
 
28
28
  def self.builtins
29
29
  @builtins ||= %w(
30
- __import__ abs all any apply ascii basestring bin bool buffer
31
- bytearray bytes callable chr classmethod cmp coerce compile
32
- complex delattr dict dir divmod enumerate eval execfile exit
33
- file filter float format frozenset getattr globals hasattr hash hex id
34
- input int intern isinstance issubclass iter len list locals
35
- long map max memoryview min next object oct open ord pow property range
36
- raw_input reduce reload repr reversed round set setattr slice
37
- sorted staticmethod str sum super tuple type unichr unicode
38
- vars xrange zip
30
+ __import__ abs aiter all anext any apply ascii
31
+ basestring bin bool buffer breakpoint bytearray bytes
32
+ callable chr classmethod cmp coerce compile complex
33
+ delattr dict dir divmod enumerate eval exec execfile exit
34
+ file filter float format frozenset getattr globals
35
+ hasattr hash help hex
36
+ id input int intern isinstance issubclass iter len list locals long
37
+ map max memoryview min next object oct open ord pow print property
38
+ range raw_input reduce reload repr reversed round set setattr slice
39
+ sorted staticmethod str sum super tuple type unichr unicode vars
40
+ xrange zip
39
41
  )
40
42
  end
41
43
 
@@ -45,25 +47,26 @@ module Rouge
45
47
 
46
48
  def self.exceptions
47
49
  @exceptions ||= %w(
48
- ArithmeticError AssertionError AttributeError
49
- BaseException BlockingIOError BrokenPipeError BufferError
50
- BytesWarning ChildProcessError ConnectionAbortedError
51
- ConnectionError ConnectionRefusedError ConnectionResetError
52
- DeprecationWarning EOFError EnvironmentError
53
- Exception FileExistsError FileNotFoundError
54
- FloatingPointError FutureWarning GeneratorExit IOError
55
- ImportError ImportWarning IndentationError IndexError
56
- InterruptedError IsADirectoryError KeyError KeyboardInterrupt
57
- LookupError MemoryError ModuleNotFoundError NameError
58
- NotADirectoryError NotImplemented NotImplementedError OSError
59
- OverflowError OverflowWarning PendingDeprecationWarning
60
- ProcessLookupError RecursionError ReferenceError ResourceWarning
61
- RuntimeError RuntimeWarning StandardError StopAsyncIteration
62
- StopIteration SyntaxError SyntaxWarning SystemError SystemExit
63
- TabError TimeoutError TypeError UnboundLocalError UnicodeDecodeError
64
- UnicodeEncodeError UnicodeError UnicodeTranslateError
65
- UnicodeWarning UserWarning ValueError VMSError Warning
66
- WindowsError ZeroDivisionError
50
+ ArithmeticError AssertionError AttributeError BaseException
51
+ BaseExceptionGroup BlockingIOError BrokenPipeError BufferError
52
+ BytesWarning ChildProcessError ConnectionAbortedError ConnectionError
53
+ ConnectionRefusedError ConnectionResetError DeprecationWarning
54
+ EOFError EnvironmentError EncodingWarning Exception ExceptionGroup
55
+ FileExistsError FileNotFoundError FloatingPointError FutureWarning
56
+ GeneratorExit IOError ImportError ImportWarning IndentationError
57
+ IndexError InterruptedError IsADirectoryError
58
+ KeyError KeyboardInterrupt LookupError
59
+ MemoryError ModuleNotFoundError
60
+ NameError NotADirectoryError NotImplemented NotImplementedError
61
+ OSError OverflowError OverflowWarning PendingDeprecationWarning
62
+ PermissionError ProcessLookupError PythonFinalizationError
63
+ RecursionError ReferenceError ResourceWarning RuntimeError RuntimeWarning
64
+ StandardError StopAsyncIteration StopIteration SyntaxError SyntaxWarning
65
+ SystemError SystemExit TabError TimeoutError TypeError
66
+ UnboundLocalError UnicodeDecodeError UnicodeEncodeError UnicodeError
67
+ UnicodeTranslateError UnicodeWarning UserWarning ValueError VMSError
68
+ Warning WindowsError
69
+ ZeroDivisionError
67
70
  )
68
71
  end
69
72
 
@@ -121,12 +124,14 @@ module Rouge
121
124
 
122
125
  # TODO: not in python 3
123
126
  rule %r/`.*?`/, Str::Backtick
124
- rule %r/([rfbu]{0,2})('''|"""|['"])/i do |m|
127
+ rule %r/([rtfbu]{0,2})('''|"""|['"])/i do |m|
125
128
  groups Str::Affix, Str::Heredoc
126
129
  current_string.register type: m[1].downcase, delim: m[2]
127
130
  push :generic_string
128
131
  end
129
132
 
133
+ mixin :soft_keywords
134
+
130
135
  # using negative lookbehind so we don't match property names
131
136
  rule %r/(?<!\.)#{identifier}/ do |m|
132
137
  if self.class.keywords.include? m[0]
@@ -166,6 +171,28 @@ module Rouge
166
171
  rule identifier, Name::Class, :pop!
167
172
  end
168
173
 
174
+ state :soft_keywords do
175
+ rule %r/
176
+ (^[ \t]*)
177
+ (match|case)\b
178
+ (?![ \t]*
179
+ (?:[:,;=^&|@~)\]}] |
180
+ (?:#{Python.keywords.join('|')})\b))
181
+ /x do |m|
182
+ token Text::Whitespace, m[1]
183
+ token Keyword, m[2]
184
+ push :soft_keywords_inner
185
+ end
186
+ end
187
+
188
+ state :soft_keywords_inner do
189
+ rule %r((\s+)([^\n_]*)(_\b)) do |m|
190
+ groups Text::Whitespace, Text, Keyword
191
+ end
192
+
193
+ rule(//) { pop! }
194
+ end
195
+
169
196
  state :raise do
170
197
  rule %r/from\b/, Keyword
171
198
  rule %r/raise\b/, Keyword
@@ -10,7 +10,7 @@ module Rouge
10
10
  title "Robot Framework"
11
11
  desc 'Robot Framework is a generic open source automation testing framework (robotframework.org)'
12
12
 
13
- filenames '*.robot'
13
+ filenames '*.robot', '*.resource'
14
14
  mimetypes 'text/x-robot'
15
15
 
16
16
  def initialize(opts = {})
@@ -11,7 +11,7 @@ module Rouge
11
11
  filenames '*.rb', '*.ruby', '*.rbw', '*.rake', '*.gemspec', '*.podspec',
12
12
  'Rakefile', 'Guardfile', 'Gemfile', 'Capfile', 'Podfile',
13
13
  'Vagrantfile', '*.ru', '*.prawn', 'Berksfile', '*.arb',
14
- 'Dangerfile', 'Fastfile', 'Deliverfile', 'Appfile'
14
+ 'Dangerfile', 'Fastfile', 'Deliverfile', 'Appfile', '*.thor', 'Thorfile'
15
15
 
16
16
  mimetypes 'text/x-ruby', 'application/x-ruby'
17
17
 
@@ -24,7 +24,7 @@ module Rouge
24
24
  rule %r(
25
25
  : # initial :
26
26
  @{0,2} # optional ivar, for :@foo and :@@foo
27
- [a-z_]\w*[!?]? # the symbol
27
+ [\p{Ll}_]\p{Word}*[!?]? # the symbol
28
28
  )xi, Str::Symbol
29
29
 
30
30
  # special symbols
@@ -39,7 +39,7 @@ module Rouge
39
39
  # %-sigiled strings
40
40
  # %(abc), %[abc], %<abc>, %.abc., %r.abc., etc
41
41
  delimiter_map = { '{' => '}', '[' => ']', '(' => ')', '<' => '>' }
42
- rule %r/%([rqswQWxiI])?([^\w\s])/ do |m|
42
+ rule %r/%([rqswQWxiI])?([^\p{Word}\s])/ do |m|
43
43
  open = Regexp.escape(m[2])
44
44
  close = Regexp.escape(delimiter_map[m[2]] || m[2])
45
45
  interp = /[rQWxI]/ === m[1] || !m[1]
@@ -57,7 +57,7 @@ module Rouge
57
57
  token toktype
58
58
 
59
59
  push do
60
- uniq_chars = "#{open}#{close}".squeeze
60
+ uniq_chars = [open, close].uniq.join
61
61
  uniq_chars = '' if open == close && open == "\\#"
62
62
  rule %r/\\[##{uniq_chars}\\]/, Str::Escape
63
63
  # nesting rules only with asymmetric delimiters
@@ -83,7 +83,7 @@ module Rouge
83
83
 
84
84
  state :strings do
85
85
  mixin :symbols
86
- rule %r/\b[a-z_]\w*?[?!]?:\s+/, Str::Symbol, :expr_start
86
+ rule %r/\b[\p{Ll}_]\p{Word}*?[?!]?:\s+/, Str::Symbol, :expr_start
87
87
  rule %r/'(\\\\|\\'|[^'])*'/, Str::Single
88
88
  rule %r/"/, Str::Double, :simple_string
89
89
  rule %r/(?<!\.)`/, Str::Backtick, :simple_backtick
@@ -177,9 +177,9 @@ module Rouge
177
177
  rule decimal, Num::Integer
178
178
 
179
179
  # names
180
- rule %r/@@[a-z_]\w*/i, Name::Variable::Class
181
- rule %r/@[a-z_]\w*/i, Name::Variable::Instance
182
- rule %r/\$\w+/, Name::Variable::Global
180
+ rule %r/@@[\p{Ll}_]\p{Word}*/i, Name::Variable::Class
181
+ rule %r/@[\p{Ll}_]\p{Word}*/i, Name::Variable::Instance
182
+ rule %r/\$\p{Word}+/, Name::Variable::Global
183
183
  rule %r(\$[!@&`'+~=/\\,;.<>_*\$?:"]), Name::Variable::Global
184
184
  rule %r/\$-[0adFiIlpvw]/, Name::Variable::Global
185
185
  rule %r/::/, Operator
@@ -193,7 +193,7 @@ module Rouge
193
193
  rule %r(
194
194
  (module)
195
195
  (\s+)
196
- ([a-zA-Z_][a-zA-Z0-9_]*(::[a-zA-Z_][a-zA-Z0-9_]*)*)
196
+ ([\p{L}_][\p{L}0-9_]*(::[\p{L}_][\p{L}0-9_]*)*)
197
197
  )x do
198
198
  groups Keyword, Text, Name::Namespace
199
199
  end
@@ -219,14 +219,14 @@ module Rouge
219
219
  # Otherwise, they will be parsed as :method_call
220
220
  rule %r/\.{2,3}/, Operator, :expr_start
221
221
 
222
- rule %r/[A-Z][a-zA-Z0-9_]*/, Name::Constant, :method_call
223
- rule %r/(\.|::)(\s*)([a-z_]\w*[!?]?|[*%&^`~+-\/\[<>=])/ do
222
+ rule %r/[\p{Lu}][\p{L}0-9_]*/, Name::Constant, :method_call
223
+ rule %r/(\.|::)(\s*)([\p{Ll}_]\p{Word}*[!?]?|[*%&^`~+-\/\[<>=])/ do
224
224
  groups Punctuation, Text, Name::Function
225
225
  push :method_call
226
226
  end
227
227
 
228
- rule %r/[a-zA-Z_]\w*[?!]/, Name, :expr_start
229
- rule %r/[a-zA-Z_]\w*/, Name, :method_call
228
+ rule %r/[\p{L}_]\p{Word}*[?!]/, Name, :expr_start
229
+ rule %r/[\p{L}_]\p{Word}*/, Name, :method_call
230
230
  rule %r/\*\*|<<?|>>?|>=|<=|<=>|=~|={3}|!~|&&?|\|\||\./,
231
231
  Operator, :expr_start
232
232
  rule %r/[-+\/*%=<>&!^|~]=?/, Operator, :expr_start
@@ -236,7 +236,7 @@ module Rouge
236
236
  end
237
237
 
238
238
  state :has_heredocs do
239
- rule %r/(?<!\w)(<<[-~]?)(["`']?)([a-zA-Z_]\w*)(\2)/ do |m|
239
+ rule %r/(?<!\p{Word})(<<[-~]?)(["`']?)([\p{L}_]\p{Word}*)(\2)/ do |m|
240
240
  token Operator, m[1]
241
241
  token Name::Constant, "#{m[2]}#{m[3]}#{m[4]}"
242
242
  @heredoc_queue << [['<<-', '<<~'].include?(m[1]), m[3]]
@@ -293,11 +293,11 @@ module Rouge
293
293
  rule %r/\s+/, Text
294
294
  rule %r/\(/, Punctuation, :defexpr
295
295
  rule %r(
296
- (?:([a-zA-Z_]\w*)(\.))?
296
+ (?:([\p{L}_]\p{Word}*)(\.))?
297
297
  (
298
- [a-zA-Z_]\w*[!?]? |
298
+ [\p{L}_]\p{Word}*[!?]? |
299
299
  \*\*? | [-+]@? | [/%&\|^`~] | \[\]=? |
300
- <<? | >>? | <=>? | >= | ===?
300
+ <=>? | <<? | >>? | >= | ===?
301
301
  )
302
302
  )x do |m|
303
303
  puts "matches: #{[m[0], m[1], m[2], m[3]].inspect}" if @debug
@@ -310,7 +310,7 @@ module Rouge
310
310
 
311
311
  state :classname do
312
312
  rule %r/\s+/, Text
313
- rule %r/\w+(::\w+)+/, Name::Class
313
+ rule %r/\p{Word}+(::\p{Word}+)+/, Name::Class
314
314
 
315
315
  rule %r/\(/ do
316
316
  token Punctuation
@@ -324,7 +324,7 @@ module Rouge
324
324
  goto :expr_start
325
325
  end
326
326
 
327
- rule %r/[A-Z_]\w*/, Name::Class, :pop!
327
+ rule %r/[\p{Lu}_]\p{Word}*/, Name::Class, :pop!
328
328
 
329
329
  rule(//) { pop! }
330
330
  end
@@ -364,7 +364,7 @@ module Rouge
364
364
 
365
365
  state :string_intp do
366
366
  rule %r/[#][{]/, Str::Interpol, :in_interp
367
- rule %r/#(@@?|\$)[a-z_]\w*/i, Str::Interpol
367
+ rule %r/#(@@?|\$)[\p{Ll}_]\p{Word}*/i, Str::Interpol
368
368
  end
369
369
 
370
370
  state :string_intp_escaped do
@@ -419,7 +419,7 @@ module Rouge
419
419
  rule %r(
420
420
  [?](\\[MC]-)* # modifiers
421
421
  (\\([\\abefnrstv\#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})|\S)
422
- (?!\w)
422
+ (?!\p{Word})
423
423
  )x, Str::Char, :pop!
424
424
 
425
425
  # special case for using a single space. Ruby demands that
@@ -155,7 +155,7 @@ module Rouge
155
155
  state :attr_common do
156
156
  mixin :has_interp
157
157
  rule id do |m|
158
- if CSS.attributes.include? m[0]
158
+ if CSS.properties.include? m[0]
159
159
  token Name::Label
160
160
  else
161
161
  token Name::Attribute
@@ -13,7 +13,8 @@ module Rouge
13
13
  mimetypes 'text/x-scala', 'application/x-scala'
14
14
 
15
15
  # As documented in the ENBF section of the scala specification
16
- # http://www.scala-lang.org/docu/files/ScalaReference.pdf
16
+ # https://scala-lang.org/files/archive/spec/2.13/13-syntax-summary.html
17
+ # https://en.wikipedia.org/wiki/Unicode_character_property#General_Category
17
18
  whitespace = /\p{Space}/
18
19
  letter = /[\p{L}$_]/
19
20
  upper = /[\p{Lu}$_]/
@@ -24,8 +25,10 @@ module Rouge
24
25
  # negative lookahead to filter out other classes
25
26
  op = %r(
26
27
  (?!#{whitespace}|#{letter}|#{digits}|#{parens}|#{delims})
27
- [\u0020-\u007F\p{Sm}\p{So}]
28
+ [-!#%&*/:?@\\^\p{Sm}\p{So}]
28
29
  )x
30
+ # manually removed +<=>|~ from regexp because they're in property Sm
31
+ # pp CHRS:(0x00..0x7f).map(&:chr).grep(/\p{Sm}/)
29
32
 
30
33
  idrest = %r(#{letter}(?:#{letter}|#{digits})*(?:(?<=_)#{op}+)?)x
31
34
 
@@ -115,7 +115,7 @@ module Rouge
115
115
  rule %r/"/, Name::Variable, :double_string
116
116
  rule %r/`/, Name::Variable, :backtick
117
117
 
118
- rule %r/\w[\w\d]*/ do |m|
118
+ rule %r/\w+/ do |m|
119
119
  if self.class.keywords_type.include? m[0].upcase
120
120
  token Name::Builtin
121
121
  elsif self.class.keywords.include? m[0].upcase
@@ -0,0 +1,91 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ load_lexer 'html.rb'
7
+
8
+ class Svelte < HTML
9
+ desc 'Svelte single-file components (https://svelte.dev/)'
10
+ tag 'svelte'
11
+ filenames '*.svelte'
12
+ mimetypes 'text/x-svelte', 'application/x-svelte'
13
+
14
+ def initialize(*)
15
+ super
16
+ # todo add support for typescript script blocks
17
+ @js = Javascript.new(options)
18
+ end
19
+
20
+ # Shorthand syntax for passing attributes - ex, `{src}` instead of `src={src}`
21
+ prepend :tag do
22
+ rule %r/(\{)\s*([a-zA-Z0-9_]+)\s*(})/m do
23
+ groups Str::Interpol, Name::Variable, Str::Interpol
24
+ pop!
25
+ end
26
+ end
27
+
28
+ prepend :attr do
29
+ # Duplicate template_start mixin here with a pop!
30
+ # Because otherwise we'll never exit the attr state
31
+ rule %r/\{/ do
32
+ token Str::Interpol
33
+ pop!
34
+ push :template
35
+ end
36
+ end
37
+
38
+ # handle templates within attribute single/double quotes
39
+ prepend :dq do
40
+ mixin :template_start
41
+ end
42
+
43
+ prepend :sq do
44
+ mixin :template_start
45
+ end
46
+
47
+ prepend :root do
48
+ # detect curly braces within HTML text (outside of tags/attributes)
49
+ rule %r/([^<&{]*)(\{)(\s*)/ do
50
+ groups Text, Str::Interpol, Text
51
+ push :template
52
+ end
53
+ end
54
+
55
+ state :template_start do
56
+ # open template
57
+ rule %r/\s*\{\s*/, Str::Interpol, :template
58
+ end
59
+
60
+ state :template do
61
+ # template end
62
+ rule %r/}/, Str::Interpol, :pop!
63
+
64
+ # Allow JS lexer to handle matched curly braces within template
65
+ rule(/(?<=^|[^\\])\{+.*?(?<=^|[^\\])\}+/) do
66
+ delegate @js
67
+ end
68
+
69
+ # keywords
70
+ rule %r/@(debug|html)\b/, Keyword
71
+ rule %r/(#await)(.*)(then|catch)(\s+)(\w+)/ do |m|
72
+ token Keyword, m[1]
73
+ delegate @js, m[2]
74
+ token Keyword, m[3]
75
+ token Text, m[4]
76
+ delegate @js, m[5]
77
+ end
78
+ rule %r/([#\/])(await|each|if|key)\b/, Keyword
79
+ rule %r/(:else)(\s+)(if)?\b/ do
80
+ groups Keyword, Text, Keyword
81
+ end
82
+ rule %r/:?(catch|then)\b/, Keyword
83
+
84
+ # allow JS parser to handle anything that's not a curly brace
85
+ rule %r/[^{}]+/ do
86
+ delegate @js
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -27,7 +27,6 @@ module Rouge
27
27
 
28
28
  comment = /#.*$/
29
29
  inline_spaces = /[ \t]+/
30
- eol_spaces = /[\n\r]+/
31
30
  spaces = /\s+/
32
31
 
33
32
  state :inline_break do
@@ -57,9 +57,9 @@ module Rouge
57
57
 
58
58
  def self.gen_command_state(name='')
59
59
  state(:"command#{name}") do
60
- mixin :word
60
+ rule %r/#/, Comment, :comment
61
61
 
62
- rule %r/##{NOT_CHARS[END_LINE]}+/, Comment::Single
62
+ mixin :word
63
63
 
64
64
  rule %r/(?=#{CHARS[END_WORD]})/ do
65
65
  push :"params#{name}"
@@ -163,6 +163,11 @@ module Rouge
163
163
  rule %r/\\./m, Str::Escape
164
164
  end
165
165
 
166
+ state :comment do
167
+ rule %r/.*[^\\]\n/, Comment, :pop!
168
+ rule %r/.*\\\n/, Comment
169
+ end
170
+
166
171
  state :string do
167
172
  rule %r/"/, Str::Double, :pop!
168
173
  mixin :interp
@@ -11,7 +11,7 @@ module Rouge
11
11
 
12
12
  tag 'terraform'
13
13
  aliases 'tf'
14
- filenames '*.tf'
14
+ filenames '*.tf', '*.tfvars', '*.tofu'
15
15
 
16
16
  def self.keywords
17
17
  @keywords ||= Set.new %w(
@@ -39,8 +39,9 @@ module Rouge
39
39
 
40
40
  state :strings do
41
41
  rule %r/\\./, Str::Escape
42
+ rule %r/(\$[\$]+|%[%]+)(\{)/, Str
42
43
  rule %r/\$\{/ do
43
- token Keyword
44
+ token Punctuation
44
45
  push :interpolation
45
46
  end
46
47
  end
@@ -66,7 +67,7 @@ module Rouge
66
67
 
67
68
  state :interpolation do
68
69
  rule %r/\}/ do
69
- token Keyword
70
+ token Punctuation
70
71
  pop!
71
72
  end
72
73