Sha256: ced041d1d18ea51f2612ba26aea4db67f01d197f5f351c95f167f29705b7b1d4

Contents?: true

Size: 1.74 KB

Versions: 10

Compression:

Stored size: 1.74 KB

Contents

grammar SQLHelpers

  rule where_tree
    where_condition_or_empty {
      def eval
        init_clause = where_condition.where_clause rescue false
          
        (init_clause) ? build_where_tree(init_clause) : nil
      end
      def build_where_tree(init_clause)
        clauses = []
        clause = init_clause
        while clause
          parens = clause.OPEN_PARENS rescue false
          if parens
            clauses << build_where_tree(clause.where_clause)
            break
          end
          
          clause_obj = false
          begin
            clause_obj = clause.clause1
          rescue
            clause_obj = clause if clause.one_column_name rescue false
          end
          if clause_obj
            clauses << {
              :column => clause_obj.one_column_name.eval,
              :condition => clause_obj.joiner_or_null.condition_joiner.eval,
              :value => clause_obj.joiner_or_null.primitive.eval
            }
            
            dc_joiner = clause.disjunction_or_conjunction_joiner.text_value rescue dc_joiner = false
            clauses << dc_joiner if dc_joiner
            
            clause = clause.clause2 rescue false
            if !clause
              clause = clause.where_clause rescue false
            end
          else
            clause = clause.where_clause rescue false
          end
        end
        clauses
      end
    }
  end
  
  rule where_condition_or_empty
    SPACES where_condition {
      def eval
        where_condition.eval
      end
    }
    /  
    EMPTY_STRING
  end

  rule limit_condition_or_empty
    SPACE limit { def eval; limit.eval; end } / EMPTY_STRING
  end

  rule order_by_condition_or_empty
    SPACE order_by { def eval; order_by.eval; end } / EMPTY_STRING
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hipster_sql_to_hbase-0.3.29 lib/sql_parser/sql_helpers.treetop
hipster_sql_to_hbase-0.3.20 lib/sql_parser/sql_helpers.treetop
hipster_sql_to_hbase-0.3.12 lib/sql_parser/sql_helpers.treetop
hipster_sql_to_hbase-0.3.2 lib/sql_parser/sql_helpers.treetop
hipster_sql_to_hbase-0.3.1 lib/sql_parser/sql_helpers.treetop
hipster_sql_to_hbase-0.3.0 lib/sql_parser/sql_helpers.treetop
hipster_sql_to_hbase-0.2.2 lib/sql_parser/sql_helpers.treetop
hipster_sql_to_hbase-0.2.0 lib/sql_parser/sql_helpers.treetop
hipster_sql_to_hbase-0.1.85 lib/sql_parser/sql_helpers.treetop
hipster_sql_to_hbase-0.1.8 lib/sql_parser/sql_helpers.treetop