Module | Sass::SCSS::RX |
In: |
lib/sass/scss/rx.rb
|
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.
H | = | /[0-9a-fA-F]/ | ||
NL | = | /\n|\r\n|\r|\f/ | ||
UNICODE | = | /\\#{H}{1,6}[ \t\r\n\f]?/ | ||
NONASCII | = | /[#{s}]/ | ||
ESCAPE | = | /#{UNICODE}|\\[ -~#{s}]/ | ||
NMSTART | = | /[_a-zA-Z]|#{NONASCII}|#{ESCAPE}/ | ||
NMCHAR | = | /[a-zA-Z0-9_-]|#{NONASCII}|#{ESCAPE}/ | ||
STRING1 | = | /\"((?:[^\n\r\f\\"]|\\#{NL}|#{ESCAPE})*)\"/ | ||
STRING2 | = | /\'((?:[^\n\r\f\\']|\\#{NL}|#{ESCAPE})*)\'/ | ||
IDENT | = | /-*#{NMSTART}#{NMCHAR}*/ | ||
NAME | = | /#{NMCHAR}+/ | ||
STRING | = | /#{STRING1}|#{STRING2}/ | ||
URLCHAR | = | /[#%&*-~]|#{NONASCII}|#{ESCAPE}/ | ||
URL | = | /(#{URLCHAR}*)/ | ||
W | = | /[ \t\r\n\f]*/ | ||
VARIABLE | = | /(\$)(#{Sass::SCSS::RX::IDENT})/ | ||
RANGE | = | /(?:#{H}|\?){1,6}/ | This is more liberal than the spec‘s definition, but that definition didn‘t work well with the greediness rules | |
S | = | /[ \t\r\n\f]+/ | ||
COMMENT | = | %r{/\*([^*]|\*+[^/*])*\**\*/} | ||
SINGLE_LINE_COMMENT | = | %r{//.*(\n[ \t]*//.*)*} | ||
CDO | = | quote("<!--") | ||
CDC | = | quote("-->") | ||
INCLUDES | = | quote("~=") | ||
DASHMATCH | = | quote("|=") | ||
PREFIXMATCH | = | quote("^=") | ||
SUFFIXMATCH | = | quote("$=") | ||
SUBSTRINGMATCH | = | quote("*=") | ||
HASH | = | /##{NAME}/ | ||
IMPORTANT | = | /!#{W}important/i | ||
UNIT | = | /-?#{NMSTART}(?:[a-zA-Z0-9_]|#{NONASCII}|#{ESCAPE}|-(?!\.?\d))*|%/ | 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 | = | /(?:[0-9]+|[0-9]*\.[0-9]+)(?:[eE][+-]?\d+)?/ | ||
NUMBER | = | /#{UNITLESS_NUMBER}(?:#{UNIT})?/ | ||
PERCENTAGE | = | /#{UNITLESS_NUMBER}%/ | ||
URI | = | /url\(#{W}(?:#{STRING}|#{URL})#{W}\)/i | ||
FUNCTION | = | /#{IDENT}\(/ | ||
UNICODERANGE | = | /u\+(?:#{H}{1,6}-#{H}{1,6}|#{RANGE})/i | ||
PLUS | = | /#{W}\+/ | Defined in www.w3.org/TR/css3-selectors/#lex | |
GREATER | = | /#{W}>/ | ||
TILDE | = | /#{W}~/ | ||
NOT | = | quote(":not(", Regexp::IGNORECASE) | ||
URL_PREFIX | = | /url-prefix\(#{W}(?:#{STRING}|#{URL})#{W}\)/i | Defined in developer.mozilla.org/en/CSS/@-moz-document as a non-standard version of www.w3.org/TR/css3-conditional/ | |
DOMAIN | = | /domain\(#{W}(?:#{STRING}|#{URL})#{W}\)/i | ||
HEXCOLOR | = | /\#[0-9a-fA-F]+/ | Custom | |
INTERP_START | = | /#\{/ | ||
ANY | = | /:(-[-\w]+-)?any\(/i | ||
OPTIONAL | = | /!#{W}optional/i | ||
IDENT_START | = | /-|#{NMSTART}/ | ||
IDENT_HYPHEN_INTERP | = | /-(#\{)/ | ||
STRING1_NOINTERP | = | /\"((?:[^\n\r\f\\"#]|#(?!\{)|#{ESCAPE})*)\"/ | ||
STRING2_NOINTERP | = | /\'((?:[^\n\r\f\\'#]|#(?!\{)|#{ESCAPE})*)\'/ | ||
STRING_NOINTERP | = | /#{STRING1_NOINTERP}|#{STRING2_NOINTERP}/ | ||
STATIC_COMPONENT | = | /#{IDENT}|#{STRING_NOINTERP}|#{HEXCOLOR}|[+-]?#{NUMBER}|\!important/i | ||
STATIC_VALUE | = | %r(#{STATIC_COMPONENT}(\s*[\s,/]\s*#{STATIC_COMPONENT})*([;}]))i | ||
STATIC_SELECTOR | = | /(#{NMCHAR}|[ \t]|[,>+*]|[:#.]#{NMSTART}){1,50}([{])/i |
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
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