rouge 1.4.0 → 1.5.0

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
  SHA1:
3
- metadata.gz: 7271e7e935f4e3a5e38187c5d53cd71578453f30
4
- data.tar.gz: 1bd9cdf5744f515565f86602c0d6ac7b382d1afc
3
+ metadata.gz: f56238615c98f486c5d3cd978aac53f45e6bb2ee
4
+ data.tar.gz: 4659578e0b792daf6e8ad9085a4d2dd0312d5749
5
5
  SHA512:
6
- metadata.gz: 4d8b40f7d369bab8e223ffa6cbea7742a707e849e9dc3f11a88eb30fd6c23accaf2b43a9176bdeae1cf671901fc61f9379897c220e0d0fc2ec124e2a851d07fe
7
- data.tar.gz: 4a4541ed068a997755964649ed02d56e332609877f1282d4ded0e84073fb867ae14021470f9bf6e8740885f71ead3f8b551028dc0cfd80c1266c49b1d1f9a248
6
+ metadata.gz: 97d1c64beea24ce75095a5f2975ff3aa8d902725120f4022ed69b3ac29681cd9e6e61ff88f44ec65733d7795f1a00ae17594e8d5d23ef4419570d1d50c43331e
7
+ data.tar.gz: b43ec6cbb46295bca0cd5185b1e21202c1583c10f6b0fb447c9ae5d53e5d5469dd0dbde18d13ecfc2044033cc0afd6b45055b2fe44cd11d05d635222b53a0ee0
@@ -0,0 +1,5 @@
1
+ // Say hello to poeple
2
+ func sayHello(personName: String) -> String {
3
+ let greeting = "Hello, " + personName + "!"
4
+ return greeting
5
+ }
@@ -19,7 +19,7 @@ module Rouge
19
19
  tokens.each do |tok, val|
20
20
  escape = escape_sequence(tok)
21
21
  yield escape.style_string
22
- yield val
22
+ yield val.gsub("\n", "\n#{escape.style_string}")
23
23
  yield escape.reset_string
24
24
  end
25
25
  end
@@ -126,11 +126,14 @@ module Rouge
126
126
  hexes.map { |h| h.to_i(16) }
127
127
  end
128
128
 
129
+ # max distance between two colors, #000000 to #ffffff
130
+ MAX_DISTANCE = 257 * 257 * 3
131
+
129
132
  def self.closest_color(r, g, b)
130
133
  @@colors_cache ||= {}
131
134
  key = (r << 16) + (g << 8) + b
132
135
  @@colors_cache.fetch(key) do
133
- distance = 257 * 257 * 3 # (max distance, from #000000 to #ffffff)
136
+ distance = MAX_DISTANCE
134
137
 
135
138
  match = 0
136
139
 
@@ -29,8 +29,8 @@ module Rouge
29
29
  rule /(?<!\.)\b(and|not|or|when|xor|in)\b/, Operator::Word
30
30
  rule %r{%=|\*=|\*\*=|\+=|\-=|\^=|\|\|=|
31
31
  <=>|<(?!<|=)|>(?!<|=|>)|<=|>=|===|==|=~|!=|!~|(?=[\s\t])\?|
32
- (?<=[\s\t])!+|&&|\|\||\^|\*|\+|\-|/|
33
- \||\+\+|\-\-|\*\*|\/\/|\<\-|\<\>|<<|>>|=|\.}x, Operator
32
+ (?<=[\s\t])!+|&(&&?|(?!\d))|\|\||\^|\*|\+|\-|/|
33
+ \||\+\+|\-\-|\*\*|\/\/|\<\-|\<\>|<<|>>|=|\.|~~~}x, Operator
34
34
  rule %r{(?<!:)(:)([a-zA-Z_]\w*([?!]|=(?![>=]))?|\<\>|===?|>=?|<=?|
35
35
  <=>|&&?|%\(\)|%\[\]|%\{\}|\+\+?|\-\-?|\|\|?|\!|//|[%&`/\|]|
36
36
  \*\*?|=?~|<\-)|([a-zA-Z_]\w*([?!])?)(:)(?!:)}, Str::Symbol
@@ -38,11 +38,11 @@ module Rouge
38
38
  rule /\b(nil|true|false)\b(?![?!])|\b[A-Z]\w*\b/, Name::Constant
39
39
  rule /\b(__(FILE|LINE|MODULE|MAIN|FUNCTION)__)\b(?![?!])/, Name::Builtin::Pseudo
40
40
  rule /[a-zA-Z_!][\w_]*[!\?]?/, Name
41
- rule %r{::|[(){};,/\|:\\\[\]]}, Punctuation
41
+ rule %r{::|[%(){};,/\|:\\\[\]]}, Punctuation
42
42
  rule /@[a-zA-Z_]\w*|&\d/, Name::Variable
43
43
  rule %r{\b(0[xX][0-9A-Fa-f]+|\d(_?\d)*(\.(?![^\d\s])
44
44
  (_?\d)*)?([eE][-+]?\d(_?\d)*)?|0[bB][01]+)\b}x, Num
45
- rule %r{%r\/.*\/}, Str::Regex
45
+ rule %r{~r\/.*\/}, Str::Regex
46
46
 
47
47
  mixin :strings
48
48
  end
@@ -14,7 +14,7 @@ module Rouge
14
14
  @at_keywords ||= %w(
15
15
  selector private protected public encode synchronized try
16
16
  throw catch finally end property synthesize dynamic optional
17
- interface implementation
17
+ interface implementation import
18
18
  )
19
19
  end
20
20
 
@@ -196,18 +196,18 @@ module Rouge
196
196
  mixin :has_heredocs
197
197
 
198
198
  rule /[A-Z][a-zA-Z0-9_]+/, Name::Constant, :method_call
199
- rule /(\.|::)([a-z_]\w*[!?]?|[*%&^`~+-\/\[<>=])/ do
200
- groups Punctuation, Name::Function
199
+ rule /(\.|::)(\s*)([a-z_]\w*[!?]?|[*%&^`~+-\/\[<>=])/ do
200
+ groups Punctuation, Text, Name::Function
201
201
  push :expr_start
202
202
  end
203
203
 
204
204
  rule /[a-zA-Z_]\w*[?!]/, Name, :expr_start
205
205
  rule /[a-zA-Z_]\w*/, Name, :method_call
206
- rule /\[|\]|\*\*|<<?|>>?|>=|<=|<=>|=~|={3}|!~|&&?|\|\||\.{1,3}/,
206
+ rule /\*\*|<<?|>>?|>=|<=|<=>|=~|={3}|!~|&&?|\|\||\.{1,3}/,
207
207
  Operator, :expr_start
208
208
  rule /[-+\/*%=<>&!^|~]=?/, Operator, :expr_start
209
- rule %r<[({,?:\\;/]>, Punctuation, :expr_start
210
- rule %r<[)}]>, Punctuation
209
+ rule %r<[\[({,?:\\;/]>, Punctuation, :expr_start
210
+ rule %r<[\])}]>, Punctuation
211
211
  end
212
212
 
213
213
  state :has_heredocs do
@@ -0,0 +1,128 @@
1
+ # encoding: utf-8
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Swift < RegexLexer
6
+ tag 'swift'
7
+ filenames '*.swift'
8
+
9
+ desc 'Multi paradigm, compiled programming language developed by Apple for iOS and OS X development. (developer.apple.com/swift)'
10
+
11
+ id_head = /_|(?!\p{Mc})\p{Alpha}|[^\u0000-\uFFFF]/
12
+ id_rest = /[\p{Alnum}_]|[^\u0000-\uFFFF]/
13
+ id = /#{id_head}#{id_rest}*/
14
+
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
+
19
+ as dynamicType is new super self Self Type __COLUMN__ __FILE__ __FUNCTION__ __LINE__
20
+
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
24
+
25
+ def self.declarations
26
+ @declarations ||= Set.new %w(
27
+ class deinit enum extension func import init let protocol static struct subscript typealias var
28
+ )
29
+ end
30
+
31
+ def self.types
32
+ @types ||= Set.new %w(
33
+ Int8 Int16 Int32 Int64 UInt8 UInt16 UInt32 UInt64 Int
34
+ Double Float
35
+ Bool
36
+ String Character
37
+ )
38
+ end
39
+
40
+ def self.constants
41
+ @constants ||= Set.new %w(
42
+ true false nil
43
+ )
44
+ end
45
+
46
+ state :whitespace do
47
+ rule /\s+/m, Text
48
+ rule %r(\/\/.*?\n), Comment::Single
49
+ rule %r((?<re>\/\*(?:(?>[^\/\*\*\/]+)|\g<re>)*\*\/))m, Comment::Multiline
50
+ end
51
+
52
+ state :root do
53
+ mixin :whitespace
54
+ rule /\$(([1-9]\d*)?\d)/, Name::Variable
55
+
56
+ rule %r{[()\[\]{}:;,?]}, Punctuation
57
+ rule %r([-/=+*%<>!&|^.~]+), Operator
58
+ rule /@?"/, Str, :dq
59
+ rule /'(\\.|.)'/, Str::Char
60
+ rule /(\d+\*|\d*\.\d+)(e[+-]?[0-9]+)?/i, Num::Float
61
+ rule /\d+e[+-]?[0-9]+/i, Num::Float
62
+ rule /0_?[0-7]+(?:_[0-7]+)*/, Num::Oct
63
+ rule /0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*/, Num::Hex
64
+ rule /0b[01]+(?:_[01]+)*/, Num::Bin
65
+ rule %r{[\d]+(?:_\d+)*}, Num::Integer
66
+
67
+ rule /(?!\b(if|while|for)\b)\b#{id}(?=\s*[(])/, Name::Function
68
+
69
+ rule /(#?#{id})(\s*)(:)/ do
70
+ groups Name::Variable, Text, Punctuation
71
+ end
72
+
73
+ rule /(let|var)\b(\s*)(#{id})/ do
74
+ groups Keyword, Text, Name::Variable
75
+ end
76
+
77
+ rule id do |m|
78
+ if self.class.keywords.include? m[0]
79
+ token Keyword
80
+ elsif self.class.declarations.include? m[0]
81
+ token Keyword::Declaration
82
+ elsif self.class.types.include? m[0]
83
+ token Keyword::Type
84
+ elsif self.class.constants.include? m[0]
85
+ token Keyword::Constant
86
+ else
87
+ token Name
88
+ end
89
+ end
90
+ rule id, Name
91
+ end
92
+
93
+ state :dq do
94
+ rule /\\[\\0tnr'"]/, Str::Escape
95
+ rule /\\[(]/, Str::Escape, :interp
96
+ rule /\\x\h{2}/, Str::Escape
97
+ rule /\\u\h{4}/, Str::Escape
98
+ rule /\\U\h{8}/, Str::Escape
99
+ rule /[^\\"]+/, Str
100
+ rule /"/, Str, :pop!
101
+ end
102
+
103
+ state :interp do
104
+ rule /[(]/, Punctuation, :interp_inner
105
+ rule /[)]/, Str::Escape, :pop!
106
+ mixin :root
107
+ end
108
+
109
+ state :interp_inner do
110
+ rule /[(]/, Punctuation, :push
111
+ rule /[)]/, Punctuation, :pop!
112
+ mixin :root
113
+ end
114
+
115
+ state :class do
116
+ mixin :whitespace
117
+ rule id, Name::Class, :pop!
118
+ end
119
+
120
+ state :namespace do
121
+ mixin :whitespace
122
+ rule /(?=[(])/, Text, :pop!
123
+ rule /(#{id}|[.])+/, Name::Namespace, :pop!
124
+ end
125
+
126
+ end
127
+ end
128
+ end
data/lib/rouge/theme.rb CHANGED
@@ -90,7 +90,11 @@ module Rouge
90
90
  end
91
91
 
92
92
  def get_style(token)
93
- get_own_style(token) || styles[Token::Tokens::Text]
93
+ get_own_style(token) || base_style
94
+ end
95
+
96
+ def base_style
97
+ styles[Token::Tokens::Text]
94
98
  end
95
99
 
96
100
  def name(n=nil)
@@ -148,6 +152,10 @@ module Rouge
148
152
  end
149
153
  end
150
154
 
155
+ def render_base(selector, &b)
156
+ self.class.base_style.render(selector, &b)
157
+ end
158
+
151
159
  def style_for(tok)
152
160
  self.class.get_style(tok)
153
161
  end
data/lib/rouge/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Rouge
2
2
  def self.version
3
- "1.4.0"
3
+ "1.5.0"
4
4
  end
5
5
  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.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Adkisson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-29 00:00:00.000000000 Z
11
+ date: 2014-07-12 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:
@@ -82,6 +82,7 @@ files:
82
82
  - lib/rouge/demos/smalltalk
83
83
  - lib/rouge/demos/sml
84
84
  - lib/rouge/demos/sql
85
+ - lib/rouge/demos/swift
85
86
  - lib/rouge/demos/tcl
86
87
  - lib/rouge/demos/tex
87
88
  - lib/rouge/demos/toml
@@ -157,6 +158,7 @@ files:
157
158
  - lib/rouge/lexers/smalltalk.rb
158
159
  - lib/rouge/lexers/sml.rb
159
160
  - lib/rouge/lexers/sql.rb
161
+ - lib/rouge/lexers/swift.rb
160
162
  - lib/rouge/lexers/tcl.rb
161
163
  - lib/rouge/lexers/tex.rb
162
164
  - lib/rouge/lexers/toml.rb
@@ -199,8 +201,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
201
  version: '0'
200
202
  requirements: []
201
203
  rubyforge_project: rouge
202
- rubygems_version: 2.2.0
204
+ rubygems_version: 2.2.2
203
205
  signing_key:
204
206
  specification_version: 4
205
207
  summary: A pure-ruby colorizer based on pygments
206
208
  test_files: []
209
+ has_rdoc: