#--
# DO NOT MODIFY!!!!
# This file is automatically generated by rex 1.0.5
# from lexical definition file "lib/csspool/css/tokenizer.rex".
#++

module CSSPool
module CSS
class Tokenizer < Parser
  require 'strscan'

  class ScanError < StandardError ; end

  attr_reader   :lineno
  attr_reader   :filename
  attr_accessor :state

  def scan_setup(str)
    @ss = StringScanner.new(str)
    @lineno =  1
    @state  = nil
  end

  def action
    yield
  end

  def scan_str(str)
    scan_setup(str)
    do_parse
  end
  alias :scan :scan_str

  def load_file( filename )
    @filename = filename
    open(filename, "r") do |f|
      scan_setup(f.read)
    end
  end

  def scan_file( filename )
    load_file(filename)
    do_parse
  end


  def next_token
    return if @ss.eos?
    
    # skips empty actions
    until token = _next_token or @ss.eos?; end
    token
  end

  def _next_token
    text = @ss.peek(1)
    @lineno  +=  1  if text == "\n"
    token = case @state
    when nil
      case
      when (text = @ss.scan(/url\([\s]*("([^\n\r\f\\"]|\\(\n|\r\n|\r|\f)|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*"|'([^\n\r\f\\']|\\(\n|\r\n|\r|\f)|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*')[\s]*\)/i))
         action { [:URI, st(text)] }

      when (text = @ss.scan(/url\([\s]*([!#\$%&*-~]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*[\s]*\)/i))
         action { [:URI, st(text)] }

      when (text = @ss.scan(/U\+[0-9a-fA-F?]{1,6}(-[0-9a-fA-F]{1,6})?/i))
         action {[:UNICODE_RANGE, st(text)] }

      when (text = @ss.scan(/[\s]*\/\*(.|\s)*?\*\/[\s]*/i))
         action { next_token }

      when (text = @ss.scan(/not\([\s]*/i))
         action { [:NOT_PSEUDO_CLASS, st(text)] }

      when (text = @ss.scan(/(nth\-child|nth\-last\-child|nth\-of\-type|nth\-last\-of\-type)\([\s]*([\+\-]?[0-9]*n([\s]*[\+\-][\s]*[0-9]+)?|[\+\-]?[0-9]+|odd|even)[\s]*\)/i))
         action { [:NTH_PSEUDO_CLASS, st(text)] }

      when (text = @ss.scan(/(\-[A-Za-z]+\-)?(matches|any)\(\s*/i))
         action { [:MATCHES_PSEUDO_CLASS, st(text)] }

      when (text = @ss.scan(/(domain|url\-prefix)\([\s]*("([^\n\r\f\\"]|\\(\n|\r\n|\r|\f)|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*"|'([^\n\r\f\\']|\\(\n|\r\n|\r|\f)|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*')[\s]*\)/i))
         action { [:FUNCTION_NO_QUOTE, st(text)] }

      when (text = @ss.scan(/(domain|url\-prefix)\([\s]*([!#\$%&*-~]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*[\s]*\)/i))
         action { [:FUNCTION_NO_QUOTE, st(text)] }

      when (text = @ss.scan(/(\-moz\-non\-element|\-moz\-anonymous\-block|\-moz\-anonymous\-positioned\-block|\-moz\-mathml\-anonymous\-block|\-moz\-xul\-anonymous\-block|\-moz\-hframeset\-border|\-moz\-vframeset\-border|\-moz\-line\-frame|\-moz\-button\-content|\-moz\-buttonlabel|\-moz\-cell\-content|\-moz\-dropdown\-list|\-moz\-fieldset\-content|\-moz\-frameset\-blank|\-moz\-display\-comboboxcontrol\-frame|\-moz\-html\-canvas\-content|\-moz\-inline\-table|\-moz\-table|\-moz\-table\-cell|\-moz\-table\-column\-group|\-moz\-table\-column|\-moz\-table\-outer|\-moz\-table\-row\-group|\-moz\-table\-row|\-moz\-canvas|\-moz\-pagebreak|\-moz\-page|\-moz\-pagecontent|\-moz\-page\-sequence|\-moz\-scrolled\-content|\-moz\-scrolled\-canvas|\-moz\-scrolled\-page\-sequence|\-moz\-column\-content|\-moz\-viewport|\-moz\-viewport\-scroll|\-moz\-anonymous\-flex\-item|\-moz\-tree\-column|\-moz\-tree\-row|\-moz\-tree\-separator|\-moz\-tree\-cell|\-moz\-tree\-indentation|\-moz\-tree\-line|\-moz\-tree\-twisty|\-moz\-tree\-image|\-moz\-tree\-cell\-text|\-moz\-tree\-checkbox|\-moz\-tree\-progressmeter|\-moz\-tree\-drop\-feedback|\-moz\-svg\-outer\-svg\-anon\-child|\-moz\-svg\-foreign\-content|\-moz\-svg\-text)\(/i))
         action { [:MOZ_PSEUDO_ELEMENT, st(text)] }

      when (text = @ss.scan(/[\s]*@media[\s]*/i))
         action { @state = :LOGICQUERY; [:MEDIA_SYM, st(text)] }

      when (text = @ss.scan(/[\s]*@supports[\s]*/i))
         action { @state = :LOGICQUERY; [:SUPPORTS_SYM, st(text)] }

      when (text = @ss.scan(/(\-[A-Za-z]+\-)?calc\(\s*/i))
         action { [:CALC_SYM, st(text)] }

      when (text = @ss.scan(/\-?([_A-Za-z]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])([_A-Za-z0-9-]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*\(\s*/i))
         action { [:FUNCTION, st(text)] }

      when (text = @ss.scan(/[\s]*@import[\s]*/i))
         action { [:IMPORT_SYM, st(text)] }

      when (text = @ss.scan(/[\s]*@page[\s]*/i))
         action { [:PAGE_SYM, st(text)] }

      when (text = @ss.scan(/[\s]*@charset[\s]*/i))
         action { [:CHARSET_SYM, st(text)] }

      when (text = @ss.scan(/[\s]*@(\-[A-Za-z]+\-)?document[\s]*/i))
         action { [:DOCUMENT_QUERY_SYM, st(text)] }

      when (text = @ss.scan(/[\s]*@namespace[\s]*/i))
         action { [:NAMESPACE_SYM, st(text)] }

      when (text = @ss.scan(/[\s]*@font\-face[\s]*/i))
         action { [:FONTFACE_SYM, st(text)] }

      when (text = @ss.scan(/[\s]*@(\-[A-Za-z]+\-)?keyframes[\s]*/i))
         action { [:KEYFRAMES_SYM, st(text)] }

      when (text = @ss.scan(/[\s]*!([\s]*|[\s]*\/\*(.|\s)*?\*\/[\s]*)important[\s]*/i))
         action { [:IMPORTANT_SYM, st(text)] }

      when (text = @ss.scan(/\-\-([_A-Za-z0-9-]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])+/i))
         action { [:VARIABLE_NAME, st(text)] }

      when (text = @ss.scan(/\-?([_A-Za-z]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])([_A-Za-z0-9-]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*/i))
         action { [:IDENT, st(text)] }

      when (text = @ss.scan(/\#([_A-Za-z0-9-]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])+/i))
         action { [:HASH, st(text)] }

      when (text = @ss.scan(/[\s]*~=[\s]*/i))
         action { [:INCLUDES, st(text)] }

      when (text = @ss.scan(/[\s]*\|=[\s]*/i))
         action { [:DASHMATCH, st(text)] }

      when (text = @ss.scan(/[\s]*\^=[\s]*/i))
         action { [:PREFIXMATCH, st(text)] }

      when (text = @ss.scan(/[\s]*\$=[\s]*/i))
         action { [:SUFFIXMATCH, st(text)] }

      when (text = @ss.scan(/[\s]*\*=[\s]*/i))
         action { [:SUBSTRINGMATCH, st(text)] }

      when (text = @ss.scan(/[\s]*!=[\s]*/i))
         action { [:NOT_EQUAL, st(text)] }

      when (text = @ss.scan(/[\s]*=[\s]*/i))
         action { [:EQUAL, st(text)] }

      when (text = @ss.scan(/[\s]*\)/i))
         action { [:RPAREN, st(text)] }

      when (text = @ss.scan(/[\s]*\(/i))
         action { [:LPAREN, st(text)] }

      when (text = @ss.scan(/\[[\s]*/i))
         action { [:LSQUARE, st(text)] }

      when (text = @ss.scan(/[\s]*\]/i))
         action { [:RSQUARE, st(text)] }

      when (text = @ss.scan(/[\s]*\+[\s]*/i))
         action { [:PLUS, st(text)] }

      when (text = @ss.scan(/[\s]*\{[\s]*/i))
         action { [:LBRACE, st(text)] }

      when (text = @ss.scan(/[\s]*\}[\s]*/i))
         action { [:RBRACE, st(text)] }

      when (text = @ss.scan(/[\s]*>[\s]*/i))
         action { [:GREATER, st(text)] }

      when (text = @ss.scan(/[\s]*,[\s]*/i))
         action { [:COMMA, st(',')] }

      when (text = @ss.scan(/[\s]*;[\s]*/i))
         action { [:SEMI, st(';')] }

      when (text = @ss.scan(/\:/i))
         action { [:COLON, st(text)] }

      when (text = @ss.scan(/\*/i))
         action { [:STAR, st(text)] }

      when (text = @ss.scan(/[\s]*~[\s]*/i))
         action { [:TILDE, st(text)] }

      when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)(px|cm|mm|in|pt|pc|mozmm|em|ex|ch|rem|vh|vw|vmin|vmax)[\s]*/i))
         action { [:LENGTH, st(text)] }

      when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)(deg|rad|grad)[\s]*/i))
         action { [:ANGLE, st(text)] }

      when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)(ms|s)[\s]*/i))
         action { [:TIME, st(text)] }

      when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)[k]?hz[\s]*/i))
         action { [:FREQ, st(text)] }

      when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)%[\s]*/i))
         action { [:PERCENTAGE, st(text)] }

      when (text = @ss.scan(/[\s]*[1-9][0-9]*[\s]*\/[\s]*[1-9][0-9]*[\s]*/i))
         action { [:RATIO, st(text)] }

      when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)[\s]*/i))
         action { [:NUMBER, st(text)] }

      when (text = @ss.scan(/[\s]*\/\/[\s]*/i))
         action { [:DOUBLESLASH, st(text)] }

      when (text = @ss.scan(/[\s]*\/[\s]*/i))
         action { [:SLASH, st('/')] }

      when (text = @ss.scan(/<!--/i))
         action { [:CDO, st(text)] }

      when (text = @ss.scan(/-->/i))
         action { [:CDC, st(text)] }

      when (text = @ss.scan(/[\s]*\-(?!\-?([_A-Za-z]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])([_A-Za-z0-9-]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*)[\s]*/i))
         action { [:MINUS, st(text)] }

      when (text = @ss.scan(/[\s]*\+[\s]*/i))
         action { [:PLUS, st(text)] }

      when (text = @ss.scan(/[\s]+/i))
         action { [:S, st(text)] }

      when (text = @ss.scan(/("([^\n\r\f\\"]|\\(\n|\r\n|\r|\f)|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*"|'([^\n\r\f\\']|\\(\n|\r\n|\r|\f)|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*')/i))
         action { [:STRING, st(text)] }

      when (text = @ss.scan(/("([^\n\r\f\\"]|\\(\n|\r\n|\r|\f)|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*|'([^\n\r\f\\']|\\(\n|\r\n|\r|\f)|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*)/i))
         action { [:INVALID, st(text)] }

      when (text = @ss.scan(/./i))
         action { [st(text), st(text)] }

      else
        text = @ss.string[@ss.pos .. -1]
        raise  ScanError, "can not match: '" + text + "'"
      end  # if

    when :LOGICQUERY
      case
      when (text = @ss.scan(/url\([\s]*("([^\n\r\f\\"]|\\(\n|\r\n|\r|\f)|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*"|'([^\n\r\f\\']|\\(\n|\r\n|\r|\f)|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*')[\s]*\)/i))
         action { [:URI, st(text)] }

      when (text = @ss.scan(/url\([\s]*([!#\$%&*-~]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*[\s]*\)/i))
         action { [:URI, st(text)] }

      when (text = @ss.scan(/\-?([_A-Za-z]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])([_A-Za-z0-9-]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*\(\s*/i))
         action { [:FUNCTION, st(text)] }

      when (text = @ss.scan(/[\s]*(and|only|not|or)[\s]+/i))
         action { [text.upcase.strip.intern, st(text)] }

      when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)(dpi|dpcm)/i))
         action { [:RESOLUTION, st(text)]}

      when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)(px|cm|mm|in|pt|pc|mozmm|em|ex|ch|rem|vh|vw|vmin|vmax)[\s]*/i))
         action { [:LENGTH, st(text)] }

      when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)(deg|rad|grad)[\s]*/i))
         action { [:ANGLE, st(text)] }

      when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)(ms|s)[\s]*/i))
         action { [:TIME, st(text)] }

      when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)[k]?hz[\s]*/i))
         action { [:FREQ, st(text)] }

      when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)%[\s]*/i))
         action { [:PERCENTAGE, st(text)] }

      when (text = @ss.scan(/[\s]*[1-9][0-9]*[\s]*\/[\s]*[1-9][0-9]*[\s]*/i))
         action { [:RATIO, st(text)] }

      when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)[\s]*/i))
         action { [:NUMBER, st(text)] }

      when (text = @ss.scan(/\-?([_A-Za-z]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])([_A-Za-z0-9-]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*/i))
         action { [:IDENT, st(text)] }

      when (text = @ss.scan(/[\s]*,[\s]*/i))
         action { [:COMMA, st(',')] }

      when (text = @ss.scan(/[\s]*\)/i))
         action { [:RPAREN, st(text)] }

      when (text = @ss.scan(/[\s]*\(/i))
         action { [:LPAREN, st(text)] }

      when (text = @ss.scan(/\:/i))
         action { [:COLON, st(text)] }

      when (text = @ss.scan(/[\s]*!([\s]*|[\s]*\/\*(.|\s)*?\*\/[\s]*)important[\s]*/i))
         action { [:IMPORTANT_SYM, st(text)] }

      when (text = @ss.scan(/[\s]*\{[\s]*/i))
         action { @state = nil; [:LBRACE, st(text)] }

      when (text = @ss.scan(/[\s]+/i))
         action { [:S, st(text)] }

      else
        text = @ss.string[@ss.pos .. -1]
        raise  ScanError, "can not match: '" + text + "'"
      end  # if

    else
      raise  ScanError, "undefined state: '" + state.to_s + "'"
    end  # case state
    token
  end  # def _next_token

def st o
  @st ||= Hash.new { |h,k| h[k] = k }
  @st[o]
end # class

end
end
end

# vim: syntax=lex
