rouge 4.1.0 → 4.2.1

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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +7 -7
  3. data/lib/rouge/cli.rb +2 -4
  4. data/lib/rouge/demos/codeowners +6 -0
  5. data/lib/rouge/demos/svelte +29 -0
  6. data/lib/rouge/guessers/disambiguation.rb +7 -0
  7. data/lib/rouge/lexers/ada.rb +1 -1
  8. data/lib/rouge/lexers/bpf.rb +10 -10
  9. data/lib/rouge/lexers/clean.rb +4 -4
  10. data/lib/rouge/lexers/codeowners.rb +30 -0
  11. data/lib/rouge/lexers/cpp.rb +1 -1
  12. data/lib/rouge/lexers/dart.rb +6 -6
  13. data/lib/rouge/lexers/dot.rb +1 -0
  14. data/lib/rouge/lexers/ecl.rb +2 -2
  15. data/lib/rouge/lexers/elixir.rb +5 -1
  16. data/lib/rouge/lexers/gdscript.rb +4 -4
  17. data/lib/rouge/lexers/ghc_cmm.rb +3 -3
  18. data/lib/rouge/lexers/groovy.rb +3 -3
  19. data/lib/rouge/lexers/hcl.rb +3 -2
  20. data/lib/rouge/lexers/irb.rb +7 -1
  21. data/lib/rouge/lexers/javascript.rb +8 -1
  22. data/lib/rouge/lexers/jinja.rb +10 -10
  23. data/lib/rouge/lexers/julia.rb +3 -2
  24. data/lib/rouge/lexers/kotlin.rb +1 -1
  25. data/lib/rouge/lexers/liquid.rb +164 -164
  26. data/lib/rouge/lexers/make.rb +1 -1
  27. data/lib/rouge/lexers/meson.rb +0 -1
  28. data/lib/rouge/lexers/mosel.rb +0 -4
  29. data/lib/rouge/lexers/nasm.rb +5 -4
  30. data/lib/rouge/lexers/nginx.rb +1 -0
  31. data/lib/rouge/lexers/objective_c/common.rb +0 -2
  32. data/lib/rouge/lexers/ocl.rb +2 -2
  33. data/lib/rouge/lexers/openedge.rb +581 -378
  34. data/lib/rouge/lexers/php.rb +2 -2
  35. data/lib/rouge/lexers/plsql.rb +5 -5
  36. data/lib/rouge/lexers/python.rb +19 -5
  37. data/lib/rouge/lexers/ruby.rb +3 -2
  38. data/lib/rouge/lexers/rust.rb +7 -6
  39. data/lib/rouge/lexers/scala.rb +5 -2
  40. data/lib/rouge/lexers/shell.rb +6 -2
  41. data/lib/rouge/lexers/sql.rb +1 -1
  42. data/lib/rouge/lexers/svelte.rb +91 -0
  43. data/lib/rouge/lexers/swift.rb +32 -16
  44. data/lib/rouge/lexers/syzlang.rb +0 -1
  45. data/lib/rouge/lexers/terraform.rb +0 -8
  46. data/lib/rouge/lexers/toml.rb +12 -12
  47. data/lib/rouge/lexers/ttcn3.rb +0 -2
  48. data/lib/rouge/lexers/twig.rb +9 -9
  49. data/lib/rouge/lexers/typescript.rb +2 -2
  50. data/lib/rouge/lexers/wollok.rb +6 -2
  51. data/lib/rouge/lexers/xojo.rb +6 -6
  52. data/lib/rouge/lexers/xquery.rb +1 -1
  53. data/lib/rouge/lexers/yang.rb +1 -1
  54. data/lib/rouge/tex_theme_renderer.rb +1 -1
  55. data/lib/rouge/version.rb +1 -1
  56. metadata +7 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 555fb3207f31723860f17a269418bbaea9dff23c0ae97dc5f27fabd797fc4ad5
4
- data.tar.gz: ad0c9a8de4f66de72f487f8310abda1e763c92816ef2de031a7aea89bcd155c0
3
+ metadata.gz: 37949922e331ce08a0d8270560930eca1a9b5b0f2c7a4beb8a0c70c47e39e9ac
4
+ data.tar.gz: 2a9bcecc9809c7211f74be3d294cf21408f76539b804733299b4a54f808a5d0a
5
5
  SHA512:
6
- metadata.gz: fcdb09306c5640839523e4ade20a7a272d835f0cd7eec7d2a3b43ae4598d5f0ef50ce2c64e24de31d98e10501f5a8ea53b0e064b51a0e3166756a0669e76b3e9
7
- data.tar.gz: 8c2deba5fc1d897f655642ed01f1817743d249fe1a8dabcc9de873b5203378b63315c5f5fd18c25a479d97aed5e726c9efffb43b1f0c83fbcc6aaf75ce1cf23d
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>
@@ -129,6 +129,7 @@ module Rouge
129
129
 
130
130
  disambiguate '*.cls' do
131
131
  next TeX if matches?(/\A\s*(?:\\|%)/)
132
+ next OpenEdge if matches?(/(no\-undo|BLOCK\-LEVEL|ROUTINE\-LEVEL|&ANALYZE\-SUSPEND)/i)
132
133
  next Apex
133
134
  end
134
135
 
@@ -139,6 +140,12 @@ module Rouge
139
140
 
140
141
  Puppet
141
142
  end
143
+
144
+ disambiguate '*.p' do
145
+ next Prolog if contains?(':-')
146
+ next Prolog if matches?(/\A\w+(\(\w+\,\s*\w+\))*\./)
147
+ next OpenEdge
148
+ end
142
149
  end
143
150
  end
144
151
  end
@@ -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
@@ -12,16 +12,16 @@ module Rouge
12
12
  mimetypes 'text/x-dart'
13
13
 
14
14
  keywords = %w(
15
- as assert await break case catch continue default do else finally for
16
- if in is new rethrow return super switch this throw try while with yield
15
+ as assert await break case catch continue default do else finally for if
16
+ in is new rethrow return super switch this throw try while when with yield
17
17
  )
18
18
 
19
19
  declarations = %w(
20
- abstract async dynamic const covariant external extends factory final get
21
- implements late native on operator required set static sync typedef var
20
+ abstract base async dynamic const covariant external extends factory final get implements
21
+ interface late native on operator required sealed set static sync typedef var
22
22
  )
23
23
 
24
- types = %w(bool Comparable double Dynamic enum Function int List Map Never Null num Object Pattern Set String Symbol Type Uri void)
24
+ types = %w(bool Comparable double Dynamic enum Function int List Map Never Null num Object Pattern Record Set String Symbol Type Uri void)
25
25
 
26
26
  imports = %w(import deferred export library part\s*of part source)
27
27
 
@@ -53,7 +53,7 @@ module Rouge
53
53
  rule %r/(?:#{declarations.join('|')})\b/, Keyword::Declaration
54
54
  rule %r/(?:#{types.join('|')})\b/, Keyword::Type
55
55
  rule %r/(?:true|false|null)\b/, Keyword::Constant
56
- rule %r/(?:class|interface|mixin)\b/, Keyword::Declaration, :class
56
+ rule %r/(?:class|mixin)\b/, Keyword::Declaration, :class
57
57
  rule %r/(?:#{imports.join('|')})\b/, Keyword::Namespace, :import
58
58
  rule %r/(\.)(#{id})/ do
59
59
  groups Operator, Name::Attribute
@@ -8,6 +8,7 @@ module Rouge
8
8
  desc "graph description language"
9
9
 
10
10
  tag 'dot'
11
+ aliases 'graphviz'
11
12
  filenames '*.dot'
12
13
  mimetypes 'text/vnd.graphviz'
13
14
 
@@ -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
 
@@ -56,7 +56,7 @@ module Rouge
56
56
  @builtins ||= %w()
57
57
  end
58
58
 
59
- id = /[$a-z_][a-z0-9_]*/io
59
+ id = /[$a-z_\-][a-z0-9_\-]*/io
60
60
 
61
61
  state :root do
62
62
  mixin :comments_and_whitespace
@@ -114,6 +114,7 @@ module Rouge
114
114
  state :hash do
115
115
  mixin :comments_and_whitespace
116
116
 
117
+ rule %r/[.,()\\\/*]/, Punctuation
117
118
  rule %r/\=/, Punctuation
118
119
  rule %r/\}/, Punctuation, :pop!
119
120
 
@@ -123,7 +124,7 @@ module Rouge
123
124
  state :array do
124
125
  mixin :comments_and_whitespace
125
126
 
126
- rule %r/,/, Punctuation
127
+ rule %r/[.,()\\\/*]/, Punctuation
127
128
  rule %r/\]/, Punctuation, :pop!
128
129
 
129
130
  mixin :root
@@ -23,7 +23,13 @@ module Rouge
23
23
  end
24
24
 
25
25
  def prompt_regex
26
- /^.*?(irb|pry).*?[>"*]/
26
+ %r(
27
+ ^.*?
28
+ (
29
+ (irb|pry).*?[>"*] |
30
+ [>"*]>
31
+ )
32
+ )x
27
33
  end
28
34
 
29
35
  def allow_comments?
@@ -190,7 +190,14 @@ module Rouge
190
190
 
191
191
  rule %r/function(?=(\(.*\)))/, Keyword::Declaration # For anonymous functions
192
192
 
193
- rule %r/(#{id})[ \t]*(?=(\(.*\)))/m, Name::Function
193
+ rule %r/(#{id})[ \t]*(?=(\(.*\)))/m do |m|
194
+ if self.class.keywords.include? m[1]
195
+ # "if" in "if (...)" or "switch" in "switch (...)" are recognized as keywords.
196
+ token Keyword
197
+ else
198
+ token Name::Function
199
+ end
200
+ end
194
201
 
195
202
  rule %r/[{}]/, Punctuation, :statement
196
203
 
@@ -14,25 +14,25 @@ module Rouge
14
14
  'text/html+django', 'text/html+jinja'
15
15
 
16
16
  def self.keywords
17
- @@keywords ||= %w(as context do else extends from ignore missing
18
- import include reversed recursive scoped
19
- autoescape endautoescape block endblock call endcall
20
- filter endfilter for endfor if endif macro endmacro
21
- set endset trans endtrans with endwith without)
17
+ @keywords ||= %w(as context do else extends from ignore missing
18
+ import include reversed recursive scoped
19
+ autoescape endautoescape block endblock call endcall
20
+ filter endfilter for endfor if endif macro endmacro
21
+ set endset trans endtrans with endwith without)
22
22
  end
23
23
 
24
24
  def self.tests
25
- @@tests ||= %w(callable defined divisibleby equalto escaped even iterable
26
- lower mapping none number odd sameas sequence string
27
- undefined upper)
25
+ @tests ||= %w(callable defined divisibleby equalto escaped even iterable
26
+ lower mapping none number odd sameas sequence string
27
+ undefined upper)
28
28
  end
29
29
 
30
30
  def self.pseudo_keywords
31
- @@pseudo_keywords ||= %w(true false none True False None)
31
+ @pseudo_keywords ||= %w(true false none True False None)
32
32
  end
33
33
 
34
34
  def self.word_operators
35
- @@word_operators ||= %w(is in and or not)
35
+ @word_operators ||= %w(is in and or not)
36
36
  end
37
37
 
38
38
  state :root do
@@ -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}`?'