rouge 4.1.3 → 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b018694487d82223169762c7e7231fdc62382011f8b6b82bb57bd7677d7ba0c0
4
- data.tar.gz: 026d1ea6626c3df24491451ef54688af78123207d8d5147c6ac878da6605f029
3
+ metadata.gz: 37949922e331ce08a0d8270560930eca1a9b5b0f2c7a4beb8a0c70c47e39e9ac
4
+ data.tar.gz: 2a9bcecc9809c7211f74be3d294cf21408f76539b804733299b4a54f808a5d0a
5
5
  SHA512:
6
- metadata.gz: 6bc574ff5559d97bb347cdd2677abf1d2446ead33382a83ff7876876c6ad7bec715bd201debddf93cf2dac1ba004126d636a47958f372691c737174a37f9c7a9
7
- data.tar.gz: 1404ac65d64ba46dc54843f32ec93f7dc9106b6175d6f070ac0c64fdb59d255916c402e6442b7b75402d29de67728be7df3a25dc8d588e7a4ef6445515e2ea89
6
+ metadata.gz: a2f8da79bd3fcf3c5449a2cc4ccd3a2fdaca4c0bbc33748f3d4552061771f458d9b2fc890d72445576240a446672aa09fea559ed5eb7c65f68f700bf8c1999ed
7
+ data.tar.gz: f0908d8e6ad216c960496da16778ce6c2e5ff4762a4cf8e1de71b4a68c2d113293462a0186bcbee83280da6c1ef5c6fa8ef9456899e14aad8f9a2bafd903e7f0
data/Gemfile CHANGED
@@ -10,22 +10,22 @@ gem 'minitest', '>= 5.0'
10
10
  gem 'minitest-power_assert'
11
11
  gem 'power_assert', '~> 2.0'
12
12
 
13
- gem 'rubocop', '~> 1.0', '<= 1.11'
14
- gem 'rubocop-performance'
15
-
16
13
  # don't try to install redcarpet under jruby
17
14
  gem 'redcarpet', platforms: :ruby
18
15
 
19
16
  # Profiling
20
17
  gem 'memory_profiler', require: false
21
18
 
22
- # Needed for a Rake task
23
- gem 'git'
24
- gem 'yard'
25
-
26
19
  group :development do
27
20
  gem 'pry'
28
21
 
22
+ # Needed for a Rake task
23
+ gem 'git'
24
+ gem 'yard'
25
+
26
+ gem 'rubocop', '~> 1.0', '<= 1.11'
27
+ gem 'rubocop-performance'
28
+
29
29
  # docs
30
30
  gem 'github-markup'
31
31
 
data/lib/rouge/cli.rb CHANGED
@@ -347,8 +347,7 @@ module Rouge
347
347
  formatter.format(lexer.lex(input), &method(:print))
348
348
  end
349
349
 
350
- private_class_method
351
- def self.parse_cgi(str)
350
+ private_class_method def self.parse_cgi(str)
352
351
  pairs = CGI.parse(str).map { |k, v| [k.to_sym, v.first] }
353
352
  Hash[pairs]
354
353
  end
@@ -511,8 +510,7 @@ module Rouge
511
510
  end
512
511
 
513
512
 
514
- private_class_method
515
- def self.normalize_syntax(argv)
513
+ private_class_method def self.normalize_syntax(argv)
516
514
  out = []
517
515
  argv.each do |arg|
518
516
  case arg
@@ -0,0 +1,6 @@
1
+ # Specify a default Code Owner by using a wildcard:
2
+ * @default-codeowner
3
+
4
+ /docs/ @all-docs
5
+
6
+ [Development] @dev-team
@@ -0,0 +1,29 @@
1
+ <!-- This file is made up from several examples on https://svelte.dev/examples and is not expected to function. -->
2
+ <script lang="ts">
3
+ import Image from './Image.svelte';
4
+
5
+ let src: string = '/tutorial/image.gif';
6
+ let count: number = 1;
7
+ $: doubled = count * 2; // the `$:` is special in svelte
8
+ </script>
9
+
10
+ <Image {src} bind:alt="{name.capitalize()} dancing" user={name.toUpperCase(false, 42, {key: 'value'})}
11
+ tooltip="I'm helping" false text=asdf on:message={handleMessage} />
12
+
13
+ {#await loadSrc(src)}
14
+ loading...
15
+ {:then data}
16
+ {#each cats as { name }, i}
17
+ <li>{name}</li>
18
+ {/each}
19
+
20
+ <!-- Keyed Each Block -->
21
+ {#each cats as cat (cat.id)}
22
+ <li>{cat.name}</li>
23
+ {/each}
24
+ {:catch err}
25
+ {@debug err}
26
+ {#await solveErr(err, {x: 'asdf'}) then reason}{@html reason}{/await}
27
+ {/await}
28
+
29
+ <style>p {font-family: 'Comic Sans MS', cursive;}</style>
@@ -155,7 +155,7 @@ module Rouge
155
155
  end
156
156
 
157
157
  # Flag word-like things that don't match the ID pattern.
158
- rule %r{\b(\p{Pc}|[[alpha]])\p{Word}*}, Error
158
+ rule %r{\b(\p{Pc}|[[:alpha:]])\p{Word}*}, Error
159
159
  end
160
160
  end
161
161
  end
@@ -9,11 +9,11 @@ module Rouge
9
9
  tag 'bpf'
10
10
 
11
11
  TYPE_KEYWORDS = %w(
12
- u8 u16 u32 u64 ll
12
+ u8 u16 u32 u64 s8 s16 s32 s64 ll
13
13
  ).join('|')
14
14
 
15
15
  MISC_KEYWORDS = %w(
16
- be16 be32 be64 exit lock map
16
+ be16 be32 be64 le16 le32 le64 bswap16 bswap32 bswap64 exit lock map
17
17
  ).join('|')
18
18
 
19
19
  state :root do
@@ -32,21 +32,21 @@ module Rouge
32
32
  rule %r/(call)(\s+)(\d+)/i do
33
33
  groups Keyword, Text::Whitespace, Literal::Number::Integer
34
34
  end
35
- rule %r/(call)(\s+)(\w+)(#)(\d+)/i do
35
+ rule %r/(call)(\s+)(\w+)(?:(#)(\d+))?/i do
36
36
  groups Keyword, Text::Whitespace, Name::Builtin, Punctuation, Literal::Number::Integer
37
37
  end
38
38
 
39
39
  # Unconditional jumps
40
- rule %r/(goto)(\s*)(\+\d+)?(\s*)(<?\w+>?)/i do
41
- groups Keyword, Text::Whitespace, Literal::Number::Integer, Text::Whitespace, Name::Label
40
+ rule %r/(gotol?)(\s*)([-+]0x\w+)?([-+]\d+)?(\s*)(<?\w+>?)/i do
41
+ groups Keyword, Text::Whitespace, Literal::Number::Hex, Literal::Number::Integer, Text::Whitespace, Name::Label
42
42
  end
43
43
 
44
44
  # Conditional jumps
45
- rule %r/(if)(\s+)([rw]\d+)(\s*)([s!=<>]+)(\s*)(0x\h+|[-]?\d+)(\s*)(goto)(\s*)(\+\d+)?(\s*)(<?\w+>?)/i do
46
- groups Keyword, Text::Whitespace, Name, Text::Whitespace, Operator, Text::Whitespace, Literal::Number, Text::Whitespace, Keyword, Text::Whitespace, Literal::Number::Integer, Text::Whitespace, Name::Label
45
+ rule %r/(if)(\s+)([rw]\d+)(\s*)([s!=<>]+)(\s*)(0x\h+|[-]?\d+)(\s*)(gotol?)(\s*)([-+]0x\w+)?([-+]\d+)?(\s*)(<?\w+>?)/i do
46
+ groups Keyword, Text::Whitespace, Name, Text::Whitespace, Operator, Text::Whitespace, Literal::Number, Text::Whitespace, Keyword, Text::Whitespace, Literal::Number::Hex, Literal::Number::Integer, Text::Whitespace, Name::Label
47
47
  end
48
- rule %r/(if)(\s+)([rw]\d+)(\s*)([s!=<>]+)(\s*)([rw]\d+)(\s*)(goto)(\s*)(\+\d+)?(\s*)(<?\w+>?)/i do
49
- groups Keyword, Text::Whitespace, Name, Text::Whitespace, Operator, Text::Whitespace, Name, Text::Whitespace, Keyword, Text::Whitespace, Literal::Number::Integer, Text::Whitespace, Name::Label
48
+ rule %r/(if)(\s+)([rw]\d+)(\s*)([s!=<>]+)(\s*)([rw]\d+)(\s*)(gotol?)(\s*)([-+]0x\w+)?([-+]\d+)?(\s*)(<?\w+>?)/i do
49
+ groups Keyword, Text::Whitespace, Name, Text::Whitespace, Operator, Text::Whitespace, Name, Text::Whitespace, Keyword, Text::Whitespace, Literal::Number::Hex, Literal::Number::Integer, Text::Whitespace, Name::Label
50
50
  end
51
51
 
52
52
  # Dereferences
@@ -70,7 +70,7 @@ module Rouge
70
70
  rule %r/#{MISC_KEYWORDS}/i, Keyword
71
71
 
72
72
  # Literals and global objects (maps) refered by name
73
- rule %r/(0x\h+|[-]?\d+)(\s*)(ll)?/i do
73
+ rule %r/([-]?0x\h+|[-]?\d+)(\s*)(ll)?/i do
74
74
  groups Literal::Number, Text::Whitespace, Keyword::Type
75
75
  end
76
76
  rule %r/(\w+)(\s*)(ll)/i do
@@ -79,7 +79,7 @@ module Rouge
79
79
 
80
80
  rule %r/code(\s+inline)?\s*{/, Comment::Preproc, :abc
81
81
 
82
- rule %r/_*[a-z][\w_`]*/ do |m|
82
+ rule %r/_*[a-z][\w`]*/ do |m|
83
83
  if self.class.keywords.include?(m[0])
84
84
  token Keyword
85
85
  else
@@ -87,7 +87,7 @@ module Rouge
87
87
  end
88
88
  end
89
89
 
90
- rule %r/_*[A-Z][\w_`]*/ do |m|
90
+ rule %r/_*[A-Z][\w`]*/ do |m|
91
91
  if m[0]=='True' || m[0]=='False'
92
92
  token Keyword::Constant
93
93
  else
@@ -95,7 +95,7 @@ module Rouge
95
95
  end
96
96
  end
97
97
 
98
- rule %r/[^\w_\s`]/, Punctuation
98
+ rule %r/[^\w\s`]/, Punctuation
99
99
  rule %r/_\b/, Punctuation
100
100
  end
101
101
 
@@ -136,7 +136,7 @@ module Rouge
136
136
 
137
137
  rule %r/}/, Comment::Preproc, :pop!
138
138
  rule %r/\.\w*/, Keyword, :abc_rest_of_line
139
- rule %r/[\w_]+/, Name::Builtin, :abc_rest_of_line
139
+ rule %r/[\w]+/, Name::Builtin, :abc_rest_of_line
140
140
  end
141
141
 
142
142
  state :abc_rest_of_line do
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class Codeowners < RegexLexer
7
+ title 'CODEOWNERS'
8
+ desc 'Code Owners syntax (https://docs.gitlab.com/ee/user/project/codeowners/reference.html)'
9
+ tag 'codeowners'
10
+ filenames 'CODEOWNERS'
11
+
12
+ state :root do
13
+ rule %r/[ \t\r\n]+/, Text::Whitespace
14
+ rule %r/^\s*#.*$/, Comment::Single
15
+
16
+ rule %r(
17
+ (\^?\[(?!\d+\])[^\]]+\])
18
+ (\[\d+\])?
19
+ )x do
20
+ groups Name::Namespace, Literal::Number
21
+ end
22
+
23
+ rule %r/\S*@\S+/, Name::Function
24
+
25
+ rule %r/[\p{Word}\.\/\-\*]+/, Name
26
+ rule %r/.*\\[\#\s]/, Name
27
+ end
28
+ end
29
+ end
30
+ end
@@ -27,7 +27,7 @@ module Rouge
27
27
  delete dynamic_cast explicit export friend
28
28
  mutable namespace new operator private protected public
29
29
  reinterpret_cast requires restrict size_of static_cast this throw throws
30
- typeid typename using virtual final override
30
+ typeid typename using virtual final override import module
31
31
 
32
32
  alignas alignof decltype noexcept static_assert
33
33
  thread_local try
@@ -18,7 +18,7 @@ module Rouge
18
18
 
19
19
  declarations = %w(
20
20
  abstract base async dynamic const covariant external extends factory final get implements
21
- inline interface late native on operator required sealed set static sync typedef var
21
+ interface late native on operator required sealed set static sync typedef var
22
22
  )
23
23
 
24
24
  types = %w(bool Comparable double Dynamic enum Function int List Map Never Null num Object Pattern Record Set String Symbol Type Uri void)
@@ -114,8 +114,8 @@ module Rouge
114
114
  mixin :single_quote
115
115
 
116
116
  rule %r(\b(?i:(and|not|or|in))\b), Operator::Word
117
- rule %r([:=|>|<|<>|/|\\|\+|-|=]), Operator
118
- rule %r([\[\]{}();,\&,\.,\%]), Punctuation
117
+ rule %r(:=|>|<|<>|/|\\|\+|-|=), Operator
118
+ rule %r([\[\]{}();,\&\.\%]), Punctuation
119
119
 
120
120
  rule %r(\b(?i:(beginc\+\+.*?endc\+\+)))m, Str::Single
121
121
  rule %r(\b(?i:(embed.*?endembed)))m, Str::Single
@@ -14,6 +14,10 @@ module Rouge
14
14
 
15
15
  filenames '*.ex', '*.exs'
16
16
 
17
+ def self.detect?(text)
18
+ return true if text.shebang?('elixir')
19
+ end
20
+
17
21
  mimetypes 'text/x-elixir', 'application/x-elixir'
18
22
 
19
23
  state :root do
@@ -131,7 +135,7 @@ module Rouge
131
135
  rule %r/[\\#]/, toktype
132
136
  end
133
137
 
134
- uniq_chars = "#{open}#{close}".squeeze
138
+ uniq_chars = [open, close].uniq.join
135
139
  rule %r/[^##{uniq_chars}\\]+/m, toktype
136
140
  end
137
141
  end
@@ -12,7 +12,7 @@ module Rouge
12
12
  mimetypes 'text/x-gdscript', 'application/x-gdscript'
13
13
 
14
14
  def self.keywords
15
- @keywords = %w(
15
+ @keywords ||= %w(
16
16
  and in not or as breakpoint class class_name extends is func setget
17
17
  signal tool const enum export onready static var break continue
18
18
  if elif else for pass return match while remote master puppet
@@ -22,13 +22,13 @@ module Rouge
22
22
 
23
23
  # Reserved for future implementation
24
24
  def self.keywords_reserved
25
- @keywords_reserved = %w(
25
+ @keywords_reserved ||= %w(
26
26
  do switch case
27
27
  ).join('|')
28
28
  end
29
29
 
30
30
  def self.builtins
31
- builtins = %w(
31
+ @builtins ||= %w(
32
32
  Color8 ColorN abs acos asin assert atan atan2 bytes2var ceil char
33
33
  clamp convert cos cosh db2linear decimals dectime deg2rad dict2inst
34
34
  ease exp floor fmod fposmod funcref hash inst2dict instance_from_id
@@ -41,7 +41,7 @@ module Rouge
41
41
  end
42
42
 
43
43
  def self.builtins_type
44
- @builtins_type = %w(
44
+ @builtins_type ||= %w(
45
45
  bool int float String Vector2 Rect2 Transform2D Vector3 AABB
46
46
  Plane Quat Basis Transform Color RID Object NodePath Dictionary
47
47
  Array PoolByteArray PoolIntArray PoolRealArray PoolStringArray
@@ -22,11 +22,11 @@ module Rouge
22
22
  ws = %r(\s|//.*?\n|/[*](?:[^*]|(?:[*][^/]))*[*]+/)mx
23
23
 
24
24
  # Make sure that this is not a preprocessor macro, e.g. `#if` or `#define`.
25
- id = %r((?!\#[a-zA-Z])[\w#\$%_']+)
25
+ id = %r((?!\#[a-zA-Z])[\w#\$%']+)
26
26
 
27
27
  complex_id = %r(
28
- (?:[\w#$%_']|\(\)|\(,\)|\[\]|[0-9])*
29
- (?:[\w#$%_']+)
28
+ (?:[\w#$%']|\(\)|\(,\)|\[\]|[0-9])*
29
+ (?:[\w#$%']+)
30
30
  )mx
31
31
 
32
32
  state :root do
@@ -23,7 +23,7 @@ module Rouge
23
23
 
24
24
  def self.declarations
25
25
  @declarations ||= Set.new %w(
26
- abstract const enum extends final implements native private
26
+ abstract const extends final implements native private
27
27
  protected public static strictfp super synchronized throws
28
28
  transient volatile
29
29
  )
@@ -31,7 +31,7 @@ module Rouge
31
31
 
32
32
  def self.types
33
33
  @types ||= Set.new %w(
34
- def boolean byte char double float int long short void
34
+ def var boolean byte char double float int long short void
35
35
  )
36
36
  end
37
37
 
@@ -56,7 +56,7 @@ module Rouge
56
56
  rule %r(//.*?$), Comment::Single
57
57
  rule %r(/[*].*?[*]/)m, Comment::Multiline
58
58
  rule %r/@\w[\w.]*/, Name::Decorator
59
- rule %r/(class|interface|trait)\b/, Keyword::Declaration, :class
59
+ rule %r/(class|interface|trait|enum|record)\b/, Keyword::Declaration, :class
60
60
  rule %r/package\b/, Keyword::Namespace, :import
61
61
  rule %r/import\b/, Keyword::Namespace, :import
62
62
 
@@ -252,15 +252,16 @@ module Rouge
252
252
  rule %r/\d+/, Literal::Number::Integer
253
253
  end
254
254
 
255
+ NAME_RE = %r/[\p{L}\p{Nl}\p{S}_][\p{Word}\p{S}\p{Po}!]*/
255
256
 
256
257
  state :funcname do
257
- rule %r/[\p{L}\p{Nl}\p{S}_][\p{Word}\p{S}\p{Po}!]*/, Name::Function, :pop!
258
+ rule NAME_RE, Name::Function, :pop!
258
259
  rule %r/\([^\s\w{]{1,2}\)/, Operator, :pop!
259
260
  rule %r/[^\s\w{]{1,2}/, Operator, :pop!
260
261
  end
261
262
 
262
263
  state :typename do
263
- rule %r/[\p{L}\p{Nl}\p{S}_][\p{Word}\p{S}\p{Po}!]*/, Name::Class, :pop!
264
+ rule NAME_RE, Name::Class, :pop!
264
265
  end
265
266
 
266
267
  state :stringescape do
@@ -24,7 +24,7 @@ module Rouge
24
24
  while yield
25
25
  )
26
26
 
27
- name_chars = %r'[-_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Nl}\p{Nd}\p{Pc}\p{Cf}\p{Mn}\p{Mc}]*'
27
+ name_chars = %r'[-\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Nl}\p{Nd}\p{Pc}\p{Cf}\p{Mn}\p{Mc}]*'
28
28
 
29
29
  class_name = %r'`?[\p{Lu}]#{name_chars}`?'
30
30
  name = %r'`?[_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Nl}]#{name_chars}`?'
@@ -73,7 +73,7 @@ module Rouge
73
73
  end
74
74
 
75
75
  state :export do
76
- rule %r/[\w[\$]{1,2}{}()-]/, Name::Variable
76
+ rule %r/[\w\${}()-]/, Name::Variable
77
77
  rule %r/\n/, Text, :pop!
78
78
  rule %r/[\t ]+/, Text
79
79
  end
@@ -38,7 +38,6 @@ module Rouge
38
38
  end
39
39
 
40
40
  identifier = /[[:alpha:]_][[:alnum:]_]*/
41
- dotted_identifier = /[[:alpha:]_.][[:alnum:]_.]*/
42
41
 
43
42
  def current_string
44
43
  @current_string ||= StringRegister.new
@@ -14,11 +14,12 @@ module Rouge
14
14
  mimetypes 'text/x-nasm'
15
15
 
16
16
  state :root do
17
- rule %r/^\s*%/, Comment::Preproc, :preproc
17
+ rule %r/^\s*%/, Comment::Preproc, :preproc
18
18
 
19
- mixin :whitespace
19
+ mixin :whitespace
20
+ mixin :punctuation
20
21
 
21
- rule %r/[a-z$._?][\w$.?#@~]*:/i, Name::Label
22
+ rule %r/[a-z$._?][\w$.?#@~]*:/i, Name::Label
22
23
 
23
24
  rule %r/([a-z$._?][\w$.?#@~]*)(\s+)(equ)/i do
24
25
  groups Name::Constant, Keyword::Declaration, Keyword::Declaration
@@ -32,7 +33,7 @@ module Rouge
32
33
  end
33
34
 
34
35
  state :instruction_args do
35
- rule %r/"(\\\\"|[^"\\n])*"|'(\\\\'|[^'\\n])*'|`(\\\\`|[^`\\n])*`/, Str
36
+ rule %r/"(\\\\"|[^"\\n])*"|'(\\\\'|[^'\\n])*'|`(\\\\`|[^`\\n])*`/, Str
36
37
  rule %r/(?:0x[\da-f]+|$0[\da-f]*|\d+[\da-f]*h)/i, Num::Hex
37
38
  rule %r/[0-7]+q/i, Num::Oct
38
39
  rule %r/[01]+b/i, Num::Bin
@@ -53,6 +53,7 @@ module Rouge
53
53
  # mimetype
54
54
  rule %r([a-z-]+/[a-z-]+)i, Name::Class
55
55
 
56
+ rule %r/\d+\.\d+/, Num::Float
56
57
  rule %r/[0-9]+[kmg]?\b/i, Num::Integer
57
58
  rule %r/(~)(\s*)([^\s{]+)/ do
58
59
  groups Punctuation, Text, Str::Regex
@@ -4,8 +4,6 @@
4
4
  module Rouge
5
5
  module Lexers
6
6
  module ObjectiveCCommon
7
- id = /[a-z$_][a-z0-9$_]*/i
8
-
9
7
  def at_keywords
10
8
  @at_keywords ||= %w(
11
9
  selector private protected public encode synchronized try
@@ -61,9 +61,9 @@ module Rouge
61
61
  rule %r/--.*/, Comment::Single
62
62
  rule %r/\d+/, Num::Integer
63
63
  rule %r/'/, Str::Single, :single_string
64
- rule %r([->|+*/<>=~!@#%&|?^-]), Operator
64
+ rule %r([-|+*/<>=~!@#%&?^]), Operator
65
65
  rule %r/[;:()\[\],.]/, Punctuation
66
- rule %r/\w[\w\d]*/ do |m|
66
+ rule %r/[a-zA-Z]\w*/ do |m|
67
67
  if self.class.operators.include? m[0]
68
68
  token Operator
69
69
  elsif self.class.keywords_type.include? m[0]
@@ -12,8 +12,6 @@ module Rouge
12
12
  title 'OpenEdge ABL'
13
13
  desc 'The OpenEdge ABL programming language'
14
14
 
15
- # optional comment or whitespace
16
- ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+)
17
15
  id = /[a-zA-Z_&{}!][a-zA-Z0-9_\-&!}]*/
18
16
 
19
17
  def self.keywords
@@ -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)
@@ -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
@@ -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
@@ -20,20 +20,9 @@ module Rouge
20
20
  rule %r/(true|false)/, Keyword::Constant
21
21
 
22
22
  rule %r/(#{identifier})(\s*)(=)(\s*)(\{)/ do
23
- groups Name::Namespace, Text, Operator, Text, Punctuation
23
+ groups Name::Property, Text, Operator, Text, Punctuation
24
24
  push :inline
25
25
  end
26
-
27
- rule %r/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/, Literal::Date
28
-
29
- rule %r/[+-]?\d+(?:_\d+)*\.\d+(?:_\d+)*(?:[eE][+-]?\d+(?:_\d+)*)?/, Num::Float
30
- rule %r/[+-]?\d+(?:_\d+)*[eE][+-]?\d+(?:_\d+)*/, Num::Float
31
- rule %r/[+-]?(?:nan|inf)/, Num::Float
32
-
33
- rule %r/0x\h+(?:_\h+)*/, Num::Hex
34
- rule %r/0o[0-7]+(?:_[0-7]+)*/, Num::Oct
35
- rule %r/0b[01]+(?:_[01]+)*/, Num::Bin
36
- rule %r/[+-]?\d+(?:_\d+)*/, Num::Integer
37
26
  end
38
27
 
39
28
  state :root do
@@ -59,6 +48,17 @@ module Rouge
59
48
  groups Name::Property, Text, Punctuation
60
49
  end
61
50
 
51
+ rule %r/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/, Literal::Date
52
+
53
+ rule %r/[+-]?\d+(?:_\d+)*\.\d+(?:_\d+)*(?:[eE][+-]?\d+(?:_\d+)*)?/, Num::Float
54
+ rule %r/[+-]?\d+(?:_\d+)*[eE][+-]?\d+(?:_\d+)*/, Num::Float
55
+ rule %r/[+-]?(?:nan|inf)/, Num::Float
56
+
57
+ rule %r/0x\h+(?:_\h+)*/, Num::Hex
58
+ rule %r/0o[0-7]+(?:_[0-7]+)*/, Num::Oct
59
+ rule %r/0b[01]+(?:_[01]+)*/, Num::Bin
60
+ rule %r/[+-]?\d+(?:_\d+)*/, Num::Integer
61
+
62
62
  rule %r/"""/, Str, :mdq
63
63
  rule %r/"/, Str, :dq
64
64
  rule %r/'''/, Str, :msq
@@ -46,8 +46,6 @@ module Rouge
46
46
  )
47
47
  end
48
48
 
49
- # optional comment or whitespace
50
- ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+)
51
49
  id = /[a-zA-Z_]\w*/
52
50
  digit = /\d_+\d|\d/
53
51
  bin_digit = /[01]_+[01]|[01]/
@@ -12,20 +12,20 @@ module Rouge
12
12
 
13
13
  keywords = %w(
14
14
  addhandler aggregates array asc assigns attributes begin break
15
- byref byval call case catch class const continue char ctype declare
15
+ byref byval call case catch class const continue color ctype declare
16
16
  delegate dim do downto each else elseif end enum event exception
17
17
  exit extends false finally for function global goto if
18
18
  implements inherits interface lib loop mod module
19
19
  new next nil object of optional paramarray
20
20
  private property protected public raise raiseevent rect redim
21
21
  removehandler return select shared soft static step sub super
22
- then to true try until using uend uhile
22
+ then to true try until using var wend while
23
23
  )
24
24
 
25
25
  keywords_type = %w(
26
- boolean cfstringref cgfloat cstring curency date double int8 int16
27
- int32 int64 integer ostype pstring ptr short single
28
- single string structure variant uinteger uint8 uint16 uint32 uint64
26
+ boolean byte cfstringref cgfloat cstring currency date datetime double int8 int16
27
+ int32 int64 integer ostype pair pstring ptr short single
28
+ string structure variant uinteger uint8 uint16 uint32 uint64
29
29
  ushort windowptr wstring
30
30
  )
31
31
 
@@ -37,7 +37,7 @@ module Rouge
37
37
  rule %r/\s+/, Text::Whitespace
38
38
 
39
39
  rule %r/rem\b.*?$/i, Comment::Single
40
- rule %r([//'].*$), Comment::Single
40
+ rule %r((?://|').*$), Comment::Single
41
41
  rule %r/\#tag Note.*?\#tag EndNote/mi, Comment::Preproc
42
42
  rule %r/\s*[#].*$/x, Comment::Preproc
43
43
 
@@ -10,7 +10,7 @@ module Rouge
10
10
  filenames '*.yang'
11
11
  mimetypes 'application/yang'
12
12
 
13
- id = /[\w_-]+(?=[^\w\-\:])\b/
13
+ id = /[\w-]+(?=[^\w\-\:])\b/
14
14
 
15
15
  #Keywords from RFC7950 ; oriented at BNF style
16
16
  def self.top_stmts_keywords
@@ -109,7 +109,7 @@ END
109
109
  end
110
110
 
111
111
  def render_blank(tok, &b)
112
- out = "\\expandafter\\def#{token_name(tok)}#1{#1}"
112
+ "\\expandafter\\def#{token_name(tok)}#1{#1}"
113
113
  end
114
114
 
115
115
  def render_style(tok, style, &b)
data/lib/rouge/version.rb CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  module Rouge
5
5
  def self.version
6
- "4.1.3"
6
+ "4.2.1"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rouge
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.3
4
+ version: 4.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeanine Adkisson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-31 00:00:00.000000000 Z
11
+ date: 2024-03-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Rouge aims to a be a simple, easy-to-extend drop-in replacement for pygments.
14
14
  email:
@@ -49,6 +49,7 @@ files:
49
49
  - lib/rouge/demos/clojure
50
50
  - lib/rouge/demos/cmake
51
51
  - lib/rouge/demos/cmhg
52
+ - lib/rouge/demos/codeowners
52
53
  - lib/rouge/demos/coffeescript
53
54
  - lib/rouge/demos/common_lisp
54
55
  - lib/rouge/demos/conf
@@ -210,6 +211,7 @@ files:
210
211
  - lib/rouge/demos/stan
211
212
  - lib/rouge/demos/stata
212
213
  - lib/rouge/demos/supercollider
214
+ - lib/rouge/demos/svelte
213
215
  - lib/rouge/demos/swift
214
216
  - lib/rouge/demos/systemd
215
217
  - lib/rouge/demos/syzlang
@@ -290,6 +292,7 @@ files:
290
292
  - lib/rouge/lexers/clojure.rb
291
293
  - lib/rouge/lexers/cmake.rb
292
294
  - lib/rouge/lexers/cmhg.rb
295
+ - lib/rouge/lexers/codeowners.rb
293
296
  - lib/rouge/lexers/coffeescript.rb
294
297
  - lib/rouge/lexers/common_lisp.rb
295
298
  - lib/rouge/lexers/conf.rb
@@ -463,6 +466,7 @@ files:
463
466
  - lib/rouge/lexers/stan.rb
464
467
  - lib/rouge/lexers/stata.rb
465
468
  - lib/rouge/lexers/supercollider.rb
469
+ - lib/rouge/lexers/svelte.rb
466
470
  - lib/rouge/lexers/swift.rb
467
471
  - lib/rouge/lexers/systemd.rb
468
472
  - lib/rouge/lexers/syzlang.rb
@@ -543,7 +547,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
543
547
  - !ruby/object:Gem::Version
544
548
  version: '0'
545
549
  requirements: []
546
- rubygems_version: 3.4.13
550
+ rubygems_version: 3.5.3
547
551
  signing_key:
548
552
  specification_version: 4
549
553
  summary: A pure-ruby colorizer based on pygments