diff --git a/lib/guillotine/parser/primitives.treetop b/lib/guillotine/parser/primitives.treetop index d2720be..abcef37 100644 --- a/lib/guillotine/parser/primitives.treetop +++ b/lib/guillotine/parser/primitives.treetop @@ -2,6 +2,24 @@ module Guillotine module Parser grammar SQLPrimitives rule primitive + open_parens primitive close_parens { + def eval + simple_primitive.eval + end + } + / + simple_primitive + end + + rule open_parens + '(' + end + + rule close_parens + ')' + end + + rule simple_primitive datetime / date / boolean / quoted_string / backtick_string / number / string end diff --git a/spec/guillotine/parser/sql_select_spec.rb b/spec/guillotine/parser/sql_select_spec.rb index 4069b84..d441c3a 100644 --- a/spec/guillotine/parser/sql_select_spec.rb +++ b/spec/guillotine/parser/sql_select_spec.rb @@ -126,6 +126,14 @@ module Parser select = parse_and_eval_with_upcasing(first_statement) select.where.key.should equal(:foo) end + + it "should parse a paren around a value" do + parse("SELECT * FROM foo WHERE id = (7)").should_not be_nil + end + + it "should parse two parens around a value" do + parse("SELECT * FROM foo WHERE id = ((7))").should_not be_nil + end end end end