#
# DO NOT MODIFY!!!!
# This file is automatically generated by racc 1.4.3
# from racc grammer file "queryparser.y".
#

require 'racc/parser'


#:nodoc:
#
# queryparser.rb generated from $Id: queryparser.y 269 2003-06-01 15:39:17Z bolzer $
# with "racc -o query.rb query.y" 
#
# Author:: Oliver M. Bolzer (mailto:oliver@fakeroot.net)
# Copyright:: (c) Oliver M. Bolzer, 2003
# Licence:: Ruby licence
#
# Parse a Vapor Query into a Vapor::QueryStatement

require 'vapor/utils'


module Vapor

  class QueryParser < Racc::Parser

module_eval <<'..end queryparser.y modeval..idddc212e6e5', 'queryparser.y', 38
  include Exceptions

  def parse( query, arguments )
    raise TypeError unless query.is_a? String
    raise TypeError unless arguments.is_a? Array
    
    @tokens = []
    @arguments = arguments
    @ph_count = 0

    # break up into tokens
    query.strip!
    query.scan(/\w+|=|~|\?|\(|\)/).each{ |token|
      case token
      when /\AAND/
        @tokens.push [:BOOL, $&]
      when /\A\w+/
         @tokens.push [:IDENT, $& ]
      when /\A\?/
         @tokens.push [:PLACEHOLDER, $& ]
      when /\A(=|~)/
         @tokens.push [:COMP, $& ]
      else
         @tokens.push [ $&, $& ]
      end
      
    }
    
    # check that number of placeholders match number of arguments
    num_ph = @tokens.select{|t| t[0] == :PLACEHOLDER }.size
    if num_ph > arguments.size then
      raise InvalidQueryError, "too few arguments to query"
    end

    # replace all Persistables with their OID
    arguments.map!{|arg|
      if arg.kind_of? Persistable then
        arg.oid
      else
        arg
      end
    }

    begin
      do_parse
    rescue Racc::ParseError => e
      raise InvalidQueryError, e.message
    end
  end

  private
  def next_token
    @tokens.shift
  end

..end queryparser.y modeval..idddc212e6e5

##### racc 1.4.3 generates ###

racc_reduce_table = [
 0, 0, :racc_error,
 3, 9, :_reduce_1,
 3, 9, :_reduce_2,
 3, 9, :_reduce_3 ]

racc_reduce_n = 4

racc_shift_n = 12

racc_action_table = [
     1,     1,     2,     2,     1,     6,     2,     7,     7,     9,
     8,    10,     5 ]

racc_action_check = [
     0,     1,     0,     1,     7,     3,     7,     3,     4,     5,
     4,     6,     2 ]

racc_action_pointer = [
    -3,    -2,     6,     5,     6,     2,    11,     1,   nil,   nil,
   nil,   nil ]

racc_action_default = [
    -4,    -4,    -4,    -4,    -4,    -4,    -4,    -4,    -1,    -2,
    12,    -3 ]

racc_goto_table = [
     3,     4,   nil,   nil,   nil,   nil,   nil,    11 ]

racc_goto_check = [
     1,     1,   nil,   nil,   nil,   nil,   nil,     1 ]

racc_goto_pointer = [
   nil,     0 ]

racc_goto_default = [
   nil,   nil ]

racc_token_table = {
 false => 0,
 Object.new => 1,
 :BOOL => 2,
 "(" => 3,
 ")" => 4,
 :IDENT => 5,
 :COMP => 6,
 :PLACEHOLDER => 7 }

racc_use_result_var = true

racc_nt_base = 8

Racc_arg = [
 racc_action_table,
 racc_action_check,
 racc_action_default,
 racc_action_pointer,
 racc_goto_table,
 racc_goto_check,
 racc_goto_default,
 racc_goto_pointer,
 racc_nt_base,
 racc_reduce_table,
 racc_token_table,
 racc_shift_n,
 racc_reduce_n,
 racc_use_result_var ]

Racc_token_to_s_table = [
'$end',
'error',
'BOOL',
'"("',
'")"',
'IDENT',
'COMP',
'PLACEHOLDER',
'$start',
'statement']

Racc_debug_parser = false

##### racc system variables end #####

 # reduce 0 omitted

module_eval <<'.,.,', 'queryparser.y', 16
  def _reduce_1( val, _values, result )
 result = val[1]
   result
  end
.,.,

module_eval <<'.,.,', 'queryparser.y', 17
  def _reduce_2( val, _values, result )
 result = BasicQueryStatement.new( val[0], val[1], @arguments[@ph_count] ); @ph_count += 1
   result
  end
.,.,

module_eval <<'.,.,', 'queryparser.y', 18
  def _reduce_3( val, _values, result )
 result =  ComplexQueryStatement.new( val[0], val[1], val[2] )
   result
  end
.,.,

 def _reduce_none( val, _values, result )
  result
 end

  end   # class QueryParser

end   # module Vapor
