From f049cabb6c2f74d165d4d4b9e6f851b565d92b9d Mon Sep 17 00:00:00 2001 From: Joel Holdbrooks Date: Fri, 13 Jan 2012 12:25:37 -0800 Subject: ignore vim swp files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 80d9aa1..2bb9385 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ test/scanners bench/test.div.html diff.html etc/CodeRay.tmproj +*.swp -- cgit v1.2.1 From 5750b1c8e8a036d436d4d19b6c1024b7c2ae4605 Mon Sep 17 00:00:00 2001 From: Joel Holdbrooks Date: Fri, 13 Jan 2012 12:28:46 -0800 Subject: begin/end with group :function instead of :string --- lib/coderay/scanners/css.rb | 80 ++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/lib/coderay/scanners/css.rb b/lib/coderay/scanners/css.rb index 34eaecb..2758af4 100644 --- a/lib/coderay/scanners/css.rb +++ b/lib/coderay/scanners/css.rb @@ -2,9 +2,9 @@ module CodeRay module Scanners class CSS < Scanner - + register_for :css - + KINDS_NOT_LOC = [ :comment, :class, :pseudo_class, :type, @@ -12,7 +12,7 @@ module Scanners :key, :value, :operator, :color, :float, :string, :error, :important, ] # :nodoc: - + module RE # :nodoc: Hex = /[0-9a-fA-F]/ Unicode = /\\#{Hex}{1,6}(?:\r\n|\s)?/ # differs from standard because it allows uppercase hex too @@ -23,47 +23,47 @@ module Scanners String1 = /"(?:[^\n\r\f\\"]|\\#{NL}|#{Escape})*"?/ # TODO: buggy regexp String2 = /'(?:[^\n\r\f\\']|\\#{NL}|#{Escape})*'?/ # TODO: buggy regexp String = /#{String1}|#{String2}/ - + HexColor = /#(?:#{Hex}{6}|#{Hex}{3})/ Color = /#{HexColor}/ - + Num = /-?(?:[0-9]+|[0-9]*\.[0-9]+)/ Name = /#{NMChar}+/ Ident = /-?#{NMStart}#{NMChar}*/ AtKeyword = /@#{Ident}/ Percentage = /#{Num}%/ - + reldimensions = %w[em ex px] absdimensions = %w[in cm mm pt pc] Unit = Regexp.union(*(reldimensions + absdimensions + %w[s])) - + Dimension = /#{Num}#{Unit}/ - + Comment = %r! /\* (?: .*? \*/ | .* ) !mx Function = /(?:url|alpha|attr|counters?)\((?:[^)\n\r\f]|\\\))*\)?/ - + Id = /##{Name}/ Class = /\.#{Name}/ PseudoClass = /:#{Name}/ AttributeSelector = /\[[^\]]*\]?/ end - + protected - + def setup @state = :initial @value_expected = nil end - + def scan_tokens encoder, options states = Array(options[:state] || @state) value_expected = @value_expected - + until eos? - + if match = scan(/\s+/) encoder.text_token match, :space - + elsif case states.last when :initial, :media if match = scan(/(?>#{RE::Ident})(?!\()|\*/ox) @@ -89,7 +89,7 @@ module Scanners states.push :media_before_name next end - + when :block if match = scan(/(?>#{RE::Ident})(?!\()/ox) if value_expected @@ -99,52 +99,52 @@ module Scanners end next end - + when :media_before_name if match = scan(RE::Ident) encoder.text_token match, :type states[-1] = :media_after_name next end - + when :media_after_name if match = scan(/\{/) encoder.text_token match, :operator states[-1] = :media next end - + else #:nocov: raise_inspect 'Unknown state', encoder #:nocov: - + end - + elsif match = scan(/\/\*(?:.*?\*\/|\z)/m) encoder.text_token match, :comment - + elsif match = scan(/\{/) value_expected = false encoder.text_token match, :operator states.push :block - + elsif match = scan(/\}/) value_expected = false encoder.text_token match, :operator if states.last == :block || states.last == :media states.pop end - + elsif match = scan(/#{RE::String}/o) encoder.begin_group :string encoder.text_token match[0, 1], :delimiter encoder.text_token match[1..-2], :content if match.size > 2 encoder.text_token match[-1, 1], :delimiter if match.size >= 2 encoder.end_group :string - + elsif match = scan(/#{RE::Function}/o) - encoder.begin_group :string + encoder.begin_group :function start = match[/^\w+\(/] encoder.text_token start, :delimiter if match[-1] == ?) @@ -153,23 +153,23 @@ module Scanners else encoder.text_token match[start.size..-1], :content end - encoder.end_group :string - + encoder.end_group :function + elsif match = scan(/(?: #{RE::Dimension} | #{RE::Percentage} | #{RE::Num} )/ox) encoder.text_token match, :float - + elsif match = scan(/#{RE::Color}/o) encoder.text_token match, :color - + elsif match = scan(/! *important/) encoder.text_token match, :important - + elsif match = scan(/(?:rgb|hsl)a?\([^()\n]*\)?/) encoder.text_token match, :color - + elsif match = scan(RE::AtKeyword) encoder.text_token match, :directive - + elsif match = scan(/ [+>:;,.=()\/] /x) if match == ':' value_expected = true @@ -177,23 +177,23 @@ module Scanners value_expected = false end encoder.text_token match, :operator - + else encoder.text_token getch, :error - + end - + end - + if options[:keep_state] @state = states @value_expected = value_expected end - + encoder end - + end - + end end -- cgit v1.2.1 From e099e73ec807898d704177b7c6d246b35d03b1a3 Mon Sep 17 00:00:00 2001 From: Joel Holdbrooks Date: Fri, 20 Jan 2012 10:32:38 -0800 Subject: fix whitespace changes --- lib/coderay/scanners/css.rb | 76 ++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/lib/coderay/scanners/css.rb b/lib/coderay/scanners/css.rb index 2758af4..7b731ef 100644 --- a/lib/coderay/scanners/css.rb +++ b/lib/coderay/scanners/css.rb @@ -2,9 +2,9 @@ module CodeRay module Scanners class CSS < Scanner - + register_for :css - + KINDS_NOT_LOC = [ :comment, :class, :pseudo_class, :type, @@ -12,7 +12,7 @@ module Scanners :key, :value, :operator, :color, :float, :string, :error, :important, ] # :nodoc: - + module RE # :nodoc: Hex = /[0-9a-fA-F]/ Unicode = /\\#{Hex}{1,6}(?:\r\n|\s)?/ # differs from standard because it allows uppercase hex too @@ -23,47 +23,47 @@ module Scanners String1 = /"(?:[^\n\r\f\\"]|\\#{NL}|#{Escape})*"?/ # TODO: buggy regexp String2 = /'(?:[^\n\r\f\\']|\\#{NL}|#{Escape})*'?/ # TODO: buggy regexp String = /#{String1}|#{String2}/ - + HexColor = /#(?:#{Hex}{6}|#{Hex}{3})/ Color = /#{HexColor}/ - + Num = /-?(?:[0-9]+|[0-9]*\.[0-9]+)/ Name = /#{NMChar}+/ Ident = /-?#{NMStart}#{NMChar}*/ AtKeyword = /@#{Ident}/ Percentage = /#{Num}%/ - + reldimensions = %w[em ex px] absdimensions = %w[in cm mm pt pc] Unit = Regexp.union(*(reldimensions + absdimensions + %w[s])) - + Dimension = /#{Num}#{Unit}/ - + Comment = %r! /\* (?: .*? \*/ | .* ) !mx Function = /(?:url|alpha|attr|counters?)\((?:[^)\n\r\f]|\\\))*\)?/ - + Id = /##{Name}/ Class = /\.#{Name}/ PseudoClass = /:#{Name}/ AttributeSelector = /\[[^\]]*\]?/ end - + protected - + def setup @state = :initial @value_expected = nil end - + def scan_tokens encoder, options states = Array(options[:state] || @state) value_expected = @value_expected - + until eos? - + if match = scan(/\s+/) encoder.text_token match, :space - + elsif case states.last when :initial, :media if match = scan(/(?>#{RE::Ident})(?!\()|\*/ox) @@ -89,7 +89,7 @@ module Scanners states.push :media_before_name next end - + when :block if match = scan(/(?>#{RE::Ident})(?!\()/ox) if value_expected @@ -99,50 +99,50 @@ module Scanners end next end - + when :media_before_name if match = scan(RE::Ident) encoder.text_token match, :type states[-1] = :media_after_name next end - + when :media_after_name if match = scan(/\{/) encoder.text_token match, :operator states[-1] = :media next end - + else #:nocov: raise_inspect 'Unknown state', encoder #:nocov: - + end - + elsif match = scan(/\/\*(?:.*?\*\/|\z)/m) encoder.text_token match, :comment - + elsif match = scan(/\{/) value_expected = false encoder.text_token match, :operator states.push :block - + elsif match = scan(/\}/) value_expected = false encoder.text_token match, :operator if states.last == :block || states.last == :media states.pop end - + elsif match = scan(/#{RE::String}/o) encoder.begin_group :string encoder.text_token match[0, 1], :delimiter encoder.text_token match[1..-2], :content if match.size > 2 encoder.text_token match[-1, 1], :delimiter if match.size >= 2 encoder.end_group :string - + elsif match = scan(/#{RE::Function}/o) encoder.begin_group :function start = match[/^\w+\(/] @@ -154,22 +154,22 @@ module Scanners encoder.text_token match[start.size..-1], :content end encoder.end_group :function - + elsif match = scan(/(?: #{RE::Dimension} | #{RE::Percentage} | #{RE::Num} )/ox) encoder.text_token match, :float - + elsif match = scan(/#{RE::Color}/o) encoder.text_token match, :color - + elsif match = scan(/! *important/) encoder.text_token match, :important - + elsif match = scan(/(?:rgb|hsl)a?\([^()\n]*\)?/) encoder.text_token match, :color - + elsif match = scan(RE::AtKeyword) encoder.text_token match, :directive - + elsif match = scan(/ [+>:;,.=()\/] /x) if match == ':' value_expected = true @@ -177,23 +177,23 @@ module Scanners value_expected = false end encoder.text_token match, :operator - + else encoder.text_token getch, :error - + end - + end - + if options[:keep_state] @state = states @value_expected = value_expected end - + encoder end - + end - + end end -- cgit v1.2.1