summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2013-07-13 20:16:21 +0200
committerKornelius Kalnbach <murphy@rubychan.de>2013-07-13 20:16:21 +0200
commite1abb68eb8e6a87d8b3f5b04244b429b738003d9 (patch)
treedff8342c9f4640c62a151879a92c95c0f8f9e10b
parenta2c625b78d9cb7ff4e89176ade6869364b4f2f9b (diff)
parentee72fe95fcfca2848c3cff51b13ee78b662ba50f (diff)
downloadcoderay-e1abb68eb8e6a87d8b3f5b04244b429b738003d9.tar.gz
Merge branch 'master' into go-scanner
-rw-r--r--Changes.textile2
-rw-r--r--Rakefile2
-rw-r--r--lib/coderay.rb2
-rw-r--r--lib/coderay/scanners/css.rb4
-rw-r--r--lib/coderay/scanners/sass.rb37
5 files changed, 23 insertions, 24 deletions
diff --git a/Changes.textile b/Changes.textile
index 89b66c8..cc401e9 100644
--- a/Changes.textile
+++ b/Changes.textile
@@ -13,7 +13,7 @@ h2. Changes in 1.1
* Ruby scanner: Accept keywords as Ruby 1.9 hash keys [#126]
* HTML scanner displays style tags and attributes now [#145]
* Remove double-click toggle handler from HTML table output
-* Fixes to CSS scanner (floats, pseudoclasses)
+* Fixes to CSS scanner (floats, pseudoclasses, nth-child) [#143]
* Fixed empty tokens and unclosed token groups in HTML, CSS, Diff, Goovy, PHP, Raydebug, Ruby, SQL, and YAML scanners [#144]
* Added @:keep_state@ functionality to more scanners [#116]
* CSS scanner uses @:id@ and @:tag@ now [#27]
diff --git a/Rakefile b/Rakefile
index ba6c34e..5577009 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,3 +1,5 @@
+require 'bundler/gem_tasks'
+
$:.unshift File.dirname(__FILE__) unless $:.include? '.'
ROOT = '.'
diff --git a/lib/coderay.rb b/lib/coderay.rb
index 0c66f49..f759ed6 100644
--- a/lib/coderay.rb
+++ b/lib/coderay.rb
@@ -127,7 +127,7 @@ module CodeRay
$CODERAY_DEBUG ||= false
- CODERAY_PATH = File.join File.dirname(__FILE__), 'coderay'
+ CODERAY_PATH = File.expand_path('../coderay', __FILE__)
# Assuming the path is a subpath of lib/coderay/
def self.coderay_path *path
diff --git a/lib/coderay/scanners/css.rb b/lib/coderay/scanners/css.rb
index 9ed4618..55d5239 100644
--- a/lib/coderay/scanners/css.rb
+++ b/lib/coderay/scanners/css.rb
@@ -25,7 +25,7 @@ module Scanners
HexColor = /#(?:#{Hex}{6}|#{Hex}{3})/
- Num = /-?(?:[0-9]*\.[0-9]+|[0-9]+)/
+ Num = /-?(?:[0-9]*\.[0-9]+|[0-9]+)n?/
Name = /#{NMChar}+/
Ident = /-?#{NMStart}#{NMChar}*/
AtKeyword = /@#{Ident}/
@@ -53,7 +53,7 @@ module Scanners
end
def scan_tokens encoder, options
- states = Array(options[:state] || @state)
+ states = Array(options[:state] || @state).dup
value_expected = @value_expected
until eos?
diff --git a/lib/coderay/scanners/sass.rb b/lib/coderay/scanners/sass.rb
index e20bebe..e3296b9 100644
--- a/lib/coderay/scanners/sass.rb
+++ b/lib/coderay/scanners/sass.rb
@@ -7,11 +7,6 @@ module Scanners
register_for :sass
file_extension 'sass'
- STRING_CONTENT_PATTERN = {
- "'" => /(?:[^\n\'\#]+|\\\n|#{RE::Escape}|#(?!\{))+/,
- '"' => /(?:[^\n\"\#]+|\\\n|#{RE::Escape}|#(?!\{))+/,
- }
-
protected
def setup
@@ -19,8 +14,9 @@ module Scanners
end
def scan_tokens encoder, options
- states = Array(options[:state] || @state)
- string_delimiter = nil
+ states = Array(options[:state] || @state).dup
+
+ encoder.begin_group :string if states.last == :sqstring || states.last == :dqstring
until eos?
@@ -48,7 +44,7 @@ module Scanners
elsif case states.last
when :initial, :media, :sass_inline
if match = scan(/(?>#{RE::Ident})(?!\()/ox)
- encoder.text_token match, value_expected ? :value : (check(/.*:/) ? :key : :tag)
+ encoder.text_token match, value_expected ? :value : (check(/.*:(?![a-z])/) ? :key : :tag)
next
elsif !value_expected && (match = scan(/\*/))
encoder.text_token match, :tag
@@ -91,24 +87,23 @@ module Scanners
next
end
- when :string
- if match = scan(STRING_CONTENT_PATTERN[string_delimiter])
+ when :sqstring, :dqstring
+ if match = scan(states.last == :sqstring ? /(?:[^\n\'\#]+|\\\n|#{RE::Escape}|#(?!\{))+/o : /(?:[^\n\"\#]+|\\\n|#{RE::Escape}|#(?!\{))+/o)
encoder.text_token match, :content
elsif match = scan(/['"]/)
encoder.text_token match, :delimiter
encoder.end_group :string
- string_delimiter = nil
states.pop
elsif match = scan(/#\{/)
encoder.begin_group :inline
encoder.text_token match, :inline_delimiter
states.push :sass_inline
elsif match = scan(/ \\ | $ /x)
- encoder.end_group :string
+ encoder.end_group states.last
encoder.text_token match, :error unless match.empty?
states.pop
else
- raise_inspect "else case #{string_delimiter} reached; %p not handled." % peek(1), encoder
+ raise_inspect "else case #{states.last} reached; %p not handled." % peek(1), encoder
end
when :include
@@ -119,7 +114,7 @@ module Scanners
else
#:nocov:
- raise_inspect 'Unknown state', encoder
+ raise_inspect 'Unknown state: %p' % [states.last], encoder
#:nocov:
end
@@ -157,15 +152,15 @@ module Scanners
elsif match = scan(/['"]/)
encoder.begin_group :string
- string_delimiter = match
encoder.text_token match, :delimiter
if states.include? :sass_inline
- content = scan_until(/(?=#{string_delimiter}|\}|\z)/)
+ # no nesting, just scan the string until delimiter
+ content = scan_until(/(?=#{match}|\}|\z)/)
encoder.text_token content, :content unless content.empty?
- encoder.text_token string_delimiter, :delimiter if scan(/#{string_delimiter}/)
+ encoder.text_token match, :delimiter if scan(/#{match}/)
encoder.end_group :string
else
- states.push :string
+ states.push match == "'" ? :sqstring : :dqstring
end
elsif match = scan(/#{RE::Function}/o)
@@ -214,14 +209,16 @@ module Scanners
end
+ states.pop if states.last == :include
+
if options[:keep_state]
- @state = states
+ @state = states.dup
end
while state = states.pop
if state == :sass_inline
encoder.end_group :inline
- elsif state == :string
+ elsif state == :sqstring || state == :dqstring
encoder.end_group :string
end
end