summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2013-06-11 16:30:26 +0200
committerKornelius Kalnbach <murphy@rubychan.de>2013-06-11 16:30:26 +0200
commit2e4e83bf84282d6ce7fbc9eeff2cbe1c79788a9b (patch)
treef38d981e077b08df9423e864a2f2656e169fe325
parentb159057934d2c84c0a25c83f6cbe59010345d0a7 (diff)
downloadcoderay-2e4e83bf84282d6ce7fbc9eeff2cbe1c79788a9b.tar.gz
tweak Sass scanner: comments, includes, functions
-rw-r--r--lib/coderay/scanners/sass.rb40
1 files changed, 30 insertions, 10 deletions
diff --git a/lib/coderay/scanners/sass.rb b/lib/coderay/scanners/sass.rb
index 218ee57..167051d 100644
--- a/lib/coderay/scanners/sass.rb
+++ b/lib/coderay/scanners/sass.rb
@@ -7,8 +7,6 @@ module Scanners
register_for :sass
file_extension 'sass'
- SASS_FUNCTION = /(?:inline-image|linear-gradient|color-stops|mix|lighten|darken|rotate|image-url|image-width|image-height|sprite-url|sprite-path|sprite-file|sprite-map|sprite-position|sprite|unquote|join|round|ceil|floor|nth)/
-
STRING_CONTENT_PATTERN = {
"'" => /(?:[^\n\'\#]+|\\\n|#{RE::Escape}|#(?!\{))+/,
'"' => /(?:[^\n\"\#]+|\\\n|#{RE::Escape}|#(?!\{))+/,
@@ -26,10 +24,22 @@ module Scanners
until eos?
- if match = scan(/\s+/)
+ if bol? && (match = scan(/(?>( +)?(\/[\*\/])(.+)?)(?=\n)/))
+ encoder.text_token self[1], :space if self[1]
+ encoder.begin_group :comment
+ encoder.text_token self[2], :delimiter
+ encoder.text_token self[3], :content if self[3]
+ if match = scan(/(?:\n+#{self[1]} .*)+/)
+ encoder.text_token match, :content
+ end
+ encoder.end_group :comment
+ elsif match = scan(/\n|[^\n\S]+\n?/)
encoder.text_token match, :space
- value_expected = false if match.index(/\n/)
-
+ if match.index(/\n/)
+ value_expected = false
+ states.pop if states.last == :include
+ end
+
elsif states.last == :sass_inline && (match = scan(/\}/))
encoder.text_token match, :inline_delimiter
encoder.end_group :inline
@@ -61,7 +71,11 @@ module Scanners
elsif match = scan(/(\=|@mixin +)#{RE::Ident}/o)
encoder.text_token match, :function
next
- elsif match = scan(/@media/)
+ elsif match = scan(/@import\b/)
+ encoder.text_token match, :directive
+ states << :include
+ next
+ elsif match = scan(/@media\b/)
encoder.text_token match, :directive
# states.push :media_before_name
next
@@ -90,13 +104,19 @@ module Scanners
encoder.text_token match, :inline_delimiter
states.push :sass_inline
elsif match = scan(/ \\ | $ /x)
- encoder.end_group state
+ encoder.end_group :string
encoder.text_token match, :error unless match.empty?
states.pop
else
raise_inspect "else case #{string_delimiter} reached; %p not handled." % peek(1), encoder
end
+ when :include
+ if match = scan(/[^\s'",]+/)
+ encoder.text_token match, :include
+ next
+ end
+
else
#:nocov:
raise_inspect 'Unknown state', encoder
@@ -148,9 +168,6 @@ module Scanners
states.push :string
end
- elsif match = scan(/#{SASS_FUNCTION}/o)
- encoder.text_token match, :predefined
-
elsif match = scan(/#{RE::Function}/o)
encoder.begin_group :function
start = match[/^[-\w]+\(/]
@@ -163,6 +180,9 @@ module Scanners
end
encoder.end_group :function
+ elsif match = scan(/[a-z][-a-z_]*(?=\()/o)
+ encoder.text_token match, :predefined
+
elsif match = scan(/(?: #{RE::Dimension} | #{RE::Percentage} | #{RE::Num} )/ox)
encoder.text_token match, :float