Skip to content

Commit 0b19ccf

Browse files
committed
Merge branch 'master' into possible-speedups
2 parents e93cdf6 + 0ad3ddc commit 0b19ccf

File tree

9 files changed

+40
-12
lines changed

9 files changed

+40
-12
lines changed

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ rvm:
22
- 1.8.7
33
- ree
44
- 1.9.3
5-
- 2.0.0
5+
- 2.0
66
- 2.1
77
- 2.2
8+
- 2.3.0
89
- ruby-head
910
- jruby-18mode
1011
- jruby-19mode
@@ -21,3 +22,4 @@ matrix:
2122
- rvm: rbx-18mode
2223
- rvm: rbx-19mode
2324
script: "rake test" # test:scanners"
25+
sudo: false

Changes.textile

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ p=. _This files lists all changes in the CodeRay library since the 0.9.8 release
44

55
h2. Changes in 1.1.1
66

7-
* SQL scanner: fix open strings [#163, thanks to Adam]
7+
* SQL scanner: Allow @$@ signs in SQL identifiers [#164, thanks to jasir and Ben Basson]
8+
* SQL scanner: Fix open strings [#163, thanks to Adam]
9+
* Ruby scanner: Accept number literal suffixes @r@ and @i@ (Ruby 2.1)
10+
* Ruby scanner: Accept quoted hash keys like @{ "a": boss }@ (Ruby 2.2)
11+
* Ruby scanner: Accept save navigation operator @&.@ (Ruby 2.3)
12+
* Ruby scanner: Accept squiggly heredoc @<<~@ (Ruby 2.3)
13+
* Diff scanner: Prevent running out of regexp stack.
14+
* HTML encoder: You can keep tabs intact now by setting @tab_width: false@.
15+
* Alpha style: Tweaked colors for @:function@ group with @:content@.
816

917
h2. Changes in 1.1
1018

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ group :development do
1010
gem "rake"
1111
gem "RedCloth", RUBY_PLATFORM == 'java' ? ">= 4.2.7" : ">= 4.0.3"
1212
gem "term-ansicolor"
13+
gem 'tins', '~> 1.6.0'
1314
gem "shoulda-context"
1415
gem "test-unit"
1516
gem "json" if RUBY_VERSION < '1.9'

lib/coderay/encoders/html.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ module Encoders
2525
# == Options
2626
#
2727
# === :tab_width
28-
# Convert \t characters to +n+ spaces (a number.)
28+
# Convert \t characters to +n+ spaces (a number or false.)
29+
# false will keep tab characters untouched.
2930
#
3031
# Default: 8
3132
#

lib/coderay/scanners/ruby.rb

+13-6
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,19 @@ def scan_tokens encoder, options
164164
end
165165

166166
elsif match = scan(/ ' (?:(?>[^'\\]*) ')? | " (?:(?>[^"\\\#]*) ")? /mx)
167-
encoder.begin_group :string
168167
if match.size == 1
168+
kind = check(self.class::StringState.simple_key_pattern(match)) ? :key : :string
169+
encoder.begin_group kind
169170
encoder.text_token match, :delimiter
170-
state = self.class::StringState.new :string, match == '"', match # important for streaming
171+
state = self.class::StringState.new kind, match == '"', match # important for streaming
171172
else
173+
kind = value_expected == true && scan(/:/) ? :key : :string
174+
encoder.begin_group kind
172175
encoder.text_token match[0,1], :delimiter
173176
encoder.text_token match[1..-2], :content if match.size > 2
174177
encoder.text_token match[-1,1], :delimiter
175-
encoder.end_group :string
178+
encoder.end_group kind
179+
encoder.text_token ':', :operator if kind == :key
176180
value_expected = false
177181
end
178182

@@ -191,11 +195,14 @@ def scan_tokens encoder, options
191195
encoder.text_token match, :error
192196
method_call_expected = false
193197
else
194-
encoder.text_token match, self[1] ? :float : :integer # TODO: send :hex/:octal/:binary
198+
kind = self[1] ? :float : :integer # TODO: send :hex/:octal/:binary
199+
match << 'r' if match !~ /e/i && scan(/r/)
200+
match << 'i' if scan(/i/)
201+
encoder.text_token match, kind
195202
end
196203
value_expected = false
197204

198-
elsif match = scan(/ [-+!~^\/]=? | [:;] | [*|&]{1,2}=? | >>? /x)
205+
elsif match = scan(/ [-+!~^\/]=? | [:;] | &\. | [*|&]{1,2}=? | >>? /x)
199206
value_expected = true
200207
encoder.text_token match, :operator
201208

@@ -208,7 +215,7 @@ def scan_tokens encoder, options
208215
encoder.end_group kind
209216
heredocs ||= [] # create heredocs if empty
210217
heredocs << self.class::StringState.new(kind, quote != "'", delim,
211-
self[1] == '-' ? :indented : :linestart)
218+
self[1] ? :indented : :linestart)
212219
value_expected = false
213220

214221
elsif value_expected && match = scan(/#{patterns::FANCY_STRING_START}/o)

lib/coderay/scanners/ruby/patterns.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ module Ruby::Patterns # :nodoc: all
114114
# NOTE: This is not completely correct, but
115115
# nobody needs heredoc delimiters ending with \n.
116116
HEREDOC_OPEN = /
117-
<< (-)? # $1 = float
117+
<< ([-~])? # $1 = float
118118
(?:
119119
( [A-Za-z_0-9]+ ) # $2 = delim
120120
|

lib/coderay/scanners/ruby/string_state.rb

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ class StringState < Struct.new :type, :interpreted, :delim, :heredoc,
3737
end
3838
end
3939

40+
def self.simple_key_pattern delim
41+
if delim == "'"
42+
/ (?> (?: [^\\']+ | \\. )* ) ' : /mx
43+
else
44+
/ (?> (?: [^\\"\#]+ | \\. | \#\$[\\"] | \#\{[^\{\}]+\} | \#(?!\{) )* ) " : /mx
45+
end
46+
end
47+
4048
def initialize kind, interpreted, delim, heredoc = false
4149
if heredoc
4250
pattern = heredoc_pattern delim, interpreted, heredoc == :indented

lib/coderay/scanners/sql.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def scan_tokens encoder, options
9696
state = :string
9797
encoder.text_token match, :delimiter
9898

99-
elsif match = scan(/ @? [A-Za-z_][A-Za-z_0-9]* /x)
99+
elsif match = scan(/ @? [A-Za-z_][A-Za-z_0-9\$]* /x)
100100
encoder.text_token match, name_expected ? :ident : (match[0] == ?@ ? :variable : IDENT_KIND[match])
101101
name_expected = false
102102

lib/coderay/styles/alpha.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ class Alpha < Style
8282
.exception { color:#C00; font-weight:bold }
8383
.float { color:#60E }
8484
.function { color:#06B; font-weight:bold }
85-
.function .delimiter { color:#024; font-weight:bold }
85+
.function .delimiter { color:#059 }
86+
.function .content { color:#037 }
8687
.global-variable { color:#d70 }
8788
.hex { color:#02b }
8889
.id { color:#33D; font-weight:bold }

0 commit comments

Comments
 (0)