Skip to content

Commit e1abb68

Browse files
committed
Merge branch 'master' into go-scanner
2 parents a2c625b + ee72fe9 commit e1abb68

File tree

5 files changed

+23
-24
lines changed

5 files changed

+23
-24
lines changed

Changes.textile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ h2. Changes in 1.1
1313
* Ruby scanner: Accept keywords as Ruby 1.9 hash keys [#126]
1414
* HTML scanner displays style tags and attributes now [#145]
1515
* Remove double-click toggle handler from HTML table output
16-
* Fixes to CSS scanner (floats, pseudoclasses)
16+
* Fixes to CSS scanner (floats, pseudoclasses, nth-child) [#143]
1717
* Fixed empty tokens and unclosed token groups in HTML, CSS, Diff, Goovy, PHP, Raydebug, Ruby, SQL, and YAML scanners [#144]
1818
* Added @:keep_state@ functionality to more scanners [#116]
1919
* CSS scanner uses @:id@ and @:tag@ now [#27]

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'bundler/gem_tasks'
2+
13
$:.unshift File.dirname(__FILE__) unless $:.include? '.'
24

35
ROOT = '.'

lib/coderay.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ module CodeRay
127127

128128
$CODERAY_DEBUG ||= false
129129

130-
CODERAY_PATH = File.join File.dirname(__FILE__), 'coderay'
130+
CODERAY_PATH = File.expand_path('../coderay', __FILE__)
131131

132132
# Assuming the path is a subpath of lib/coderay/
133133
def self.coderay_path *path

lib/coderay/scanners/css.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module RE # :nodoc:
2525

2626
HexColor = /#(?:#{Hex}{6}|#{Hex}{3})/
2727

28-
Num = /-?(?:[0-9]*\.[0-9]+|[0-9]+)/
28+
Num = /-?(?:[0-9]*\.[0-9]+|[0-9]+)n?/
2929
Name = /#{NMChar}+/
3030
Ident = /-?#{NMStart}#{NMChar}*/
3131
AtKeyword = /@#{Ident}/
@@ -53,7 +53,7 @@ def setup
5353
end
5454

5555
def scan_tokens encoder, options
56-
states = Array(options[:state] || @state)
56+
states = Array(options[:state] || @state).dup
5757
value_expected = @value_expected
5858

5959
until eos?

lib/coderay/scanners/sass.rb

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,16 @@ class Sass < CSS
77
register_for :sass
88
file_extension 'sass'
99

10-
STRING_CONTENT_PATTERN = {
11-
"'" => /(?:[^\n\'\#]+|\\\n|#{RE::Escape}|#(?!\{))+/,
12-
'"' => /(?:[^\n\"\#]+|\\\n|#{RE::Escape}|#(?!\{))+/,
13-
}
14-
1510
protected
1611

1712
def setup
1813
@state = :initial
1914
end
2015

2116
def scan_tokens encoder, options
22-
states = Array(options[:state] || @state)
23-
string_delimiter = nil
17+
states = Array(options[:state] || @state).dup
18+
19+
encoder.begin_group :string if states.last == :sqstring || states.last == :dqstring
2420

2521
until eos?
2622

@@ -48,7 +44,7 @@ def scan_tokens encoder, options
4844
elsif case states.last
4945
when :initial, :media, :sass_inline
5046
if match = scan(/(?>#{RE::Ident})(?!\()/ox)
51-
encoder.text_token match, value_expected ? :value : (check(/.*:/) ? :key : :tag)
47+
encoder.text_token match, value_expected ? :value : (check(/.*:(?![a-z])/) ? :key : :tag)
5248
next
5349
elsif !value_expected && (match = scan(/\*/))
5450
encoder.text_token match, :tag
@@ -91,24 +87,23 @@ def scan_tokens encoder, options
9187
next
9288
end
9389

94-
when :string
95-
if match = scan(STRING_CONTENT_PATTERN[string_delimiter])
90+
when :sqstring, :dqstring
91+
if match = scan(states.last == :sqstring ? /(?:[^\n\'\#]+|\\\n|#{RE::Escape}|#(?!\{))+/o : /(?:[^\n\"\#]+|\\\n|#{RE::Escape}|#(?!\{))+/o)
9692
encoder.text_token match, :content
9793
elsif match = scan(/['"]/)
9894
encoder.text_token match, :delimiter
9995
encoder.end_group :string
100-
string_delimiter = nil
10196
states.pop
10297
elsif match = scan(/#\{/)
10398
encoder.begin_group :inline
10499
encoder.text_token match, :inline_delimiter
105100
states.push :sass_inline
106101
elsif match = scan(/ \\ | $ /x)
107-
encoder.end_group :string
102+
encoder.end_group states.last
108103
encoder.text_token match, :error unless match.empty?
109104
states.pop
110105
else
111-
raise_inspect "else case #{string_delimiter} reached; %p not handled." % peek(1), encoder
106+
raise_inspect "else case #{states.last} reached; %p not handled." % peek(1), encoder
112107
end
113108

114109
when :include
@@ -119,7 +114,7 @@ def scan_tokens encoder, options
119114

120115
else
121116
#:nocov:
122-
raise_inspect 'Unknown state', encoder
117+
raise_inspect 'Unknown state: %p' % [states.last], encoder
123118
#:nocov:
124119

125120
end
@@ -157,15 +152,15 @@ def scan_tokens encoder, options
157152

158153
elsif match = scan(/['"]/)
159154
encoder.begin_group :string
160-
string_delimiter = match
161155
encoder.text_token match, :delimiter
162156
if states.include? :sass_inline
163-
content = scan_until(/(?=#{string_delimiter}|\}|\z)/)
157+
# no nesting, just scan the string until delimiter
158+
content = scan_until(/(?=#{match}|\}|\z)/)
164159
encoder.text_token content, :content unless content.empty?
165-
encoder.text_token string_delimiter, :delimiter if scan(/#{string_delimiter}/)
160+
encoder.text_token match, :delimiter if scan(/#{match}/)
166161
encoder.end_group :string
167162
else
168-
states.push :string
163+
states.push match == "'" ? :sqstring : :dqstring
169164
end
170165

171166
elsif match = scan(/#{RE::Function}/o)
@@ -214,14 +209,16 @@ def scan_tokens encoder, options
214209

215210
end
216211

212+
states.pop if states.last == :include
213+
217214
if options[:keep_state]
218-
@state = states
215+
@state = states.dup
219216
end
220217

221218
while state = states.pop
222219
if state == :sass_inline
223220
encoder.end_group :inline
224-
elsif state == :string
221+
elsif state == :sqstring || state == :dqstring
225222
encoder.end_group :string
226223
end
227224
end

0 commit comments

Comments
 (0)