rouge 1.6.2 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f82ff03bdf4a459c29452a02d4e3b220f5153588
4
- data.tar.gz: a4d96c1f9407192aa7df705eb4d8d6925b0e85fd
3
+ metadata.gz: 93796c1d767a05a20dba729e4a35759571e8fe79
4
+ data.tar.gz: ad2c926cffb004c214e4d285c57c19a2b5c4e2e3
5
5
  SHA512:
6
- metadata.gz: b630dfbb83ed9a4913f2bf427a8d410348ec82c36f4d950209921ca08df736a473051da8b31cc9dfb3927941adbd2584e6adf2db40dad39d8f8f4ce392babdad
7
- data.tar.gz: 1165e7a648cd8b0e112b31ce9889256b4c41cde6cdee8d74de302225caf14af8d022cc2a5aa348aee31c08d89249a7515078fd6d0cc223c62b783a6e7b817120
6
+ metadata.gz: 8f39f87c0fbc32086f5de2668e73bb41083505d25d638691bccfa569baebbf9384f9cfa6997a100dd989e54df095f65250edba317d0541a126dd754077358c72
7
+ data.tar.gz: c8093c3490d759fc9363744ee4fa34896bc4785da2a7bb797aa48b6e74eb225cce4dbb5d890e06a72374cc9c1f00d4c3b48b706d09c4cc0d4181bee5178eb8d5
data/lib/rouge/lexer.rb CHANGED
@@ -292,7 +292,7 @@ module Rouge
292
292
 
293
293
  # @private
294
294
  def assert_utf8!(str)
295
- return if %w(US-ASCII UTF-8).include? str.encoding.name
295
+ return if %w(US-ASCII UTF-8 ASCII-8BIT).include? str.encoding.name
296
296
  raise EncodingError.new(
297
297
  "Bad encoding: #{str.encoding.names.join(',')}. " +
298
298
  "Please convert your string to UTF-8."
@@ -33,8 +33,8 @@ module Rouge
33
33
  push :tag
34
34
  end
35
35
 
36
- rule %r(<\s*[a-zA-Z0-9:]+), Name::Tag, :tag # opening tags
37
- rule %r(<\s*/\s*[a-zA-Z0-9:]+\s*>), Name::Tag # closing tags
36
+ rule %r(<\s*[a-zA-Z0-9:-]+), Name::Tag, :tag # opening tags
37
+ rule %r(<\s*/\s*[a-zA-Z0-9:-]+\s*>), Name::Tag # closing tags
38
38
  end
39
39
 
40
40
  state :comment do
@@ -42,7 +42,7 @@ module Rouge
42
42
  rule /@#{id}/, Name::Decorator
43
43
  rule /(?:#{keywords.join('|')})\b/, Keyword
44
44
  rule /(?:#{declarations.join('|')})\b/, Keyword::Declaration
45
- rule /(?:#{types.join('|')})/, Keyword::Type
45
+ rule /(?:#{types.join('|')})\b/, Keyword::Type
46
46
  rule /package\b/, Keyword::Namespace
47
47
  rule /(?:true|false|null)\b/, Keyword::Constant
48
48
  rule /(?:class|interface)\b/, Keyword::Declaration, :class
@@ -110,22 +110,21 @@ module Rouge
110
110
  )
111
111
 
112
112
  builtins_g = %w(
113
- Array Float Integer Str __id__ __send__ abort ancestors
114
- at_exit autoload binding callcc caller catch chomp chop
115
- class_eval class_variables clone const_defined\? const_get
116
- const_missing const_set constants display dup eval exec exit
117
- extend fail fork format freeze getc gets global_variables gsub
118
- hash id included_modules inspect instance_eval instance_method
119
- instance_methods instance_variable_get instance_variable_set
120
- instance_variables lambda load local_variables loop method
121
- method_missing methods module_eval name object_id open p
122
- print printf private_class_method private_instance_methods
123
- private_methods proc protected_instance_methods protected_methods
124
- public_class_method public_instance_methods public_methods putc
125
- puts raise rand readline readlines require scan select self send
126
- set_trace_func singleton_methods sleep split sprintf srand sub
127
- syscall system taint test throw to_a to_s trace_var trap untaint
128
- untrace_var warn
113
+ __id__ __send__ abort ancestors at_exit autoload binding callcc
114
+ caller catch chomp chop class_eval class_variables clone
115
+ const_defined\? const_get const_missing const_set constants
116
+ display dup eval exec exit extend fail fork format freeze
117
+ getc gets global_variables gsub hash id included_modules
118
+ inspect instance_eval instance_method instance_methods
119
+ instance_variable_get instance_variable_set instance_variables
120
+ lambda load local_variables loop method method_missing
121
+ methods module_eval name object_id open p print printf
122
+ private_class_method private_instance_methods private_methods proc
123
+ protected_instance_methods protected_methods public_class_method
124
+ public_instance_methods public_methods putc puts raise rand
125
+ readline readlines require scan select self send set_trace_func
126
+ singleton_methods sleep split sprintf srand sub syscall system
127
+ taint test throw to_a to_s trace_var trap untaint untrace_var warn
129
128
  )
130
129
 
131
130
  builtins_q = %w(
@@ -11,44 +11,26 @@ module Rouge
11
11
  id_head = /_|(?!\p{Mc})\p{Alpha}|[^\u0000-\uFFFF]/
12
12
  id_rest = /[\p{Alnum}_]|[^\u0000-\uFFFF]/
13
13
  id = /#{id_head}#{id_rest}*/
14
+
15
+ keywords = Set.new %w(
16
+ break case continue default do else fallthrough if in for return switch where while
14
17
 
15
- def self.keywords
16
- @keywords ||= Set.new %w(
17
- break case continue default do else fallthrough if in for return switch where while
18
+ as dynamicType is new super self Self Type __COLUMN__ __FILE__ __FUNCTION__ __LINE__
18
19
 
19
- as dynamicType is new super self Self Type __COLUMN__ __FILE__ __FUNCTION__ __LINE__
20
+ associativity didSet get infix inout left mutating none nonmutating operator override postfix precedence prefix right set unowned weak willSet
21
+ )
20
22
 
21
- associativity didSet get infix inout left mutating none nonmutating operator override postfix precedence prefix right set unowned unowned(safe) unowned(unsafe) weak willSet
22
- )
23
- end
23
+ declarations = Set.new %w(
24
+ class deinit enum extension final func import init internal lazy let optional private protocol public required static struct subscript typealias var dynamic
25
+ )
24
26
 
25
- def self.declarations
26
- @declarations ||= Set.new %w(
27
- class deinit enum extension final func import init internal lazy let optional private protocol public required static struct subscript typealias var dynamic
28
- )
29
- end
27
+ attributes = Set.new %w(
28
+ autoclosure IBAction IBDesignable IBInspectable IBOutlet noreturn NSCopying NSManaged objc UIApplicationMain NSApplicationMain
29
+ )
30
30
 
31
- def self.at_keywords
32
- @at_keywords ||= %w(
33
- autoclosure IBAction IBDesignable IBInspectable IBOutlet noreturn NSCopying NSManaged objc UIApplicationMain
34
- )
35
- end
36
-
37
- def self.types
38
- @types ||= Set.new %w(
39
- Int8 Int16 Int32 Int64 UInt8 UInt16 UInt32 UInt64 Int
40
- Double Float
41
- Bool
42
- String Character
43
- AnyObject Any
44
- )
45
- end
46
-
47
- def self.constants
48
- @constants ||= Set.new %w(
49
- true false nil
50
- )
51
- end
31
+ constants = Set.new %w(
32
+ true false nil
33
+ )
52
34
 
53
35
  state :whitespace do
54
36
  rule /\s+/m, Text
@@ -70,67 +52,66 @@ module Rouge
70
52
  rule /0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*/, Num::Hex
71
53
  rule /0b[01]+(?:_[01]+)*/, Num::Bin
72
54
  rule %r{[\d]+(?:_\d+)*}, Num::Integer
55
+
56
+ rule /@availability[(][^)]+[)]/, Keyword::Declaration
73
57
 
74
- rule /(?!\b(if|while|for|private|internal|@objc)\b)\b#{id}(?=\s*[(])/, Name::Function
75
-
76
- rule /(#?#{id})(\s*)(:)/ do
77
- groups Name::Variable, Text, Punctuation
78
- end
79
-
80
- rule /(let|var)\b(\s*)(#{id})/ do
81
- groups Keyword, Text, Name::Variable
58
+ rule /(@objc[(])([^)]+)([)])/ do
59
+ groups Keyword::Declaration, Name::Class, Keyword::Declaration
82
60
  end
83
61
 
84
62
  rule /@(#{id})/ do |m|
85
- if m[1] == 'objc'
86
- token Keyword::Declaration
87
- push :objc_setting
88
- elsif self.class.at_keywords.include? m[1]
63
+ if attributes.include? m[1]
89
64
  token Keyword
90
65
  else
91
66
  token Error
92
67
  end
93
68
  end
94
69
 
95
- rule id do |m|
96
- if self.class.keywords.include? m[0]
97
- token Keyword
98
- elsif self.class.declarations.include? m[0]
70
+ rule /(private|internal)(\([ ]*)(\w+)([ ]*\))/ do |m|
71
+ if m[3] == 'set'
99
72
  token Keyword::Declaration
100
- if %w(private internal).include? m[0]
101
- push :access_control_setting
102
- elsif %w(protocol class extension).include? m[0]
103
- push :type_definition
104
- end
105
- elsif self.class.types.include? m[0]
106
- token Keyword::Type
107
- elsif self.class.constants.include? m[0]
108
- token Keyword::Constant
109
73
  else
110
- token Name
74
+ groups Keyword::Declaration, Keyword::Declaration, Error, Keyword::Declaration
111
75
  end
112
76
  end
113
- rule id, Name
114
- end
115
-
116
- state :access_control_setting do
117
- rule /\( *(\w+) *\)/ do |m|
118
- if m[1] == 'set'
77
+
78
+ rule /(unowned\([ ]*)(\w+)([ ]*\))/ do |m|
79
+ if m[2] == 'safe' || m[2] == 'unsafe'
119
80
  token Keyword::Declaration
120
81
  else
121
- token Error
82
+ groups Keyword::Declaration, Error, Keyword::Declaration
122
83
  end
123
84
  end
124
- rule //, Keyword::Declaration, :pop!
125
- end
126
-
127
- state :objc_setting do
128
- rule /(\( *)(\w+)( *\))/ do |m|
129
- token Keyword::Declaration, m[1]
130
- token Name::Class, m[2]
131
- token Keyword::Declaration, m[3]
85
+
86
+ rule /(let|var)\b(\s*)(#{id})/ do
87
+ groups Keyword, Text, Name::Variable
88
+ end
89
+
90
+ rule /(?!\b(if|while|for|private|internal|unowned|switch|case)\b)\b#{id}(?=(\?|!)?\s*[(])/ do |m|
91
+ if m[0] =~ /^[[:upper:]]/
92
+ token Keyword::Type
93
+ else
94
+ token Name::Function
95
+ end
96
+ end
97
+
98
+ rule /(#?(?!default)(?![[:upper:]])#{id})(\s*)(:)/ do
99
+ groups Name::Variable, Text, Punctuation
100
+ end
101
+
102
+ rule id do |m|
103
+ if keywords.include? m[0]
104
+ token Keyword
105
+ elsif declarations.include? m[0]
106
+ token Keyword::Declaration
107
+ elsif constants.include? m[0]
108
+ token Keyword::Constant
109
+ elsif m[0] =~ /^[[:upper:]]/
110
+ token Keyword::Type
111
+ else
112
+ token Name
113
+ end
132
114
  end
133
- rule //, Keyword::Declaration, :pop!
134
115
  end
135
116
 
136
117
  state :dq do
@@ -152,17 +133,6 @@ module Rouge
152
133
  rule /[)]/, Punctuation, :pop!
153
134
  mixin :root
154
135
  end
155
-
156
- state :type_definition do
157
- mixin :whitespace
158
- rule id, Name::Class, :pop!
159
- end
160
-
161
- state :namespace do
162
- mixin :whitespace
163
- rule /(?=[(])/, Text, :pop!
164
- rule /(#{id}|[.])+/, Name::Namespace, :pop!
165
- end
166
136
  end
167
137
  end
168
138
  end
@@ -17,16 +17,13 @@ module Rouge
17
17
  code.gsub! /^ /, "\t"
18
18
  end
19
19
 
20
- formatter = rouge_formatter(
21
- :css_class => "highlight #{lexer.tag}"
22
- )
23
-
20
+ formatter = rouge_formatter(lexer)
24
21
  formatter.format(lexer.lex(code))
25
22
  end
26
23
 
27
- protected
28
- def rouge_formatter(opts={})
29
- Formatters::HTML.new(opts)
24
+ # override this method for custom formatting behavior
25
+ def rouge_formatter(lexer)
26
+ Formatters::HTML.new(:css_class => "highlight #{lexer.tag}")
30
27
  end
31
28
  end
32
29
  end
data/lib/rouge/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rouge
4
4
  def self.version
5
- "1.6.2"
5
+ "1.7.0"
6
6
  end
7
7
  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: 1.6.2
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeanine Adkisson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-17 00:00:00.000000000 Z
11
+ date: 2014-09-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: