A module containing regular expressions used for lexing tokens in an SCSS document. Most of these are taken from [the CSS3 spec](www.w3.org/TR/css3-syntax/#lexical), although some have been modified for various reasons.
Custom
Defined in www.w3.org/TR/css3-selectors/#lex
This is more liberal than the spec's definition, but that definition didn't work well with the greediness rules
Can't use IDENT here, because it seems to take exponential time on 1.8. We could use it for 1.9 only, but I don't want to introduce a cross-version behavior difference. In any case, almost all CSS idents will be matched by this.
Defined in developer.mozilla.org/en/CSS/@-moz-document as a non-standard version of www.w3.org/TR/css3-conditional/
Escapes a single character for a CSS identifier.
@param c [String] The character to escape. Should have length 1 @return [String] The escaped character @private
# File lib/sass/scss/rx.rb, line 33 def self.escape_char(c) return "\\%06x" % Sass::Util.ord(c) unless c =~ /[ -\/:-~]/ return "\\#{c}" end
Takes a string and returns a CSS identifier that will have the value of the given string.
@param str [String] The string to escape @return [String] The escaped string
# File lib/sass/scss/rx.rb, line 13 def self.escape_ident(str) return "" if str.empty? return "\\#{str}" if str == '-' || str == '_' out = "" value = str.dup out << value.slice!(0...1) if value =~ /^[-_]/ if value[0...1] =~ NMSTART out << value.slice!(0...1) else out << escape_char(value.slice!(0...1)) end out << value.gsub(/[^a-zA-Z0-9_-]/) {|c| escape_char c} return out end
Creates a Regexp from a plain text string, escaping all significant characters.
@param str [String] The text of the regexp @param flags [Fixnum] Flags for the created regular expression @return [Regexp] @private
# File lib/sass/scss/rx.rb, line 45 def self.quote(str, flags = 0) Regexp.new(Regexp.quote(str), flags) end