module Sass::SCSS::RX

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.

Constants

ANY
CDC
CDO
COMMENT
DASHMATCH
DOMAIN
ESCAPE
FUNCTION
GREATER
H
HASH
HEXCOLOR

Custom

IDENT
IDENT_HYPHEN_INTERP
IDENT_START
IMPORTANT
INCLUDES
INTERP_START
NAME
NL
NMCHAR
NMSTART
NONASCII
NOT
NUM
NUMBER
OPTIONAL
PERCENTAGE
PLUS

Defined in www.w3.org/TR/css3-selectors/#lex

PREFIXMATCH
RANGE

This is more liberal than the spec's definition, but that definition didn't work well with the greediness rules

S
SINGLE_LINE_COMMENT
STATIC_COMPONENT
STATIC_SELECTOR
STATIC_VALUE
STRING
STRING1
STRING1_NOINTERP
STRING2
STRING2_NOINTERP
STRING_NOINTERP
SUBSTRINGMATCH
SUFFIXMATCH
TILDE
UNICODE
UNICODERANGE
UNIT

A unit is like an IDENT, but disallows a hyphen followed by a digit. This allows “1px-2px” to be interpreted as subtraction rather than “1” with the unit “px-2px”. It also allows “%”.

UNITLESS_NUMBER
URI
URL
URLCHAR
URL_PREFIX

Defined in developer.mozilla.org/en/CSS/@-moz-document as a non-standard version of www.w3.org/TR/css3-conditional/

VARIABLE
W

Public Class Methods

escape_char(c) click to toggle source

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 =~ /[ -\/:-~]/
  "\\#{c}"
end
escape_ident(str) click to toggle source

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}
  out
end
quote(str, flags = 0) click to toggle source

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