lib/ustate/query_string.rb in ustate-client-0.0.6 vs lib/ustate/query_string.rb in ustate-client-0.0.7

- old
+ new

@@ -123,11 +123,11 @@ def space2 elements[2] end - def primary + def p elements[3] end end module And1 @@ -140,17 +140,17 @@ end end module And2 def query - rest.elements.map { |x| x.primary }.inject(first.query) do |a, sub| + rest.elements.map { |x| x.p }.inject(first.query) do |a, sub| Query::And.new a, sub.query end end def sql - rest.elements.map { |x| x.primary }. + rest.elements.map { |x| x.p }. inject(first.sql) do |a, sub| a & sub.sql end end end @@ -165,51 +165,75 @@ end return cached end i0, s0 = index, [] - r1 = _nt_primary + i1 = index + r2 = _nt_not + if r2 + r1 = r2 + else + r3 = _nt_primary + if r3 + r1 = r3 + else + @index = i1 + r1 = nil + end + end s0 << r1 if r1 - s2, i2 = [], index + s4, i4 = [], index loop do - i3, s3 = index, [] - r4 = _nt_space - s3 << r4 - if r4 + i5, s5 = index, [] + r6 = _nt_space + s5 << r6 + if r6 if has_terminal?('and', false, index) - r5 = instantiate_node(SyntaxNode,input, index...(index + 3)) + r7 = instantiate_node(SyntaxNode,input, index...(index + 3)) @index += 3 else terminal_parse_failure('and') - r5 = nil + r7 = nil end - s3 << r5 - if r5 - r6 = _nt_space - s3 << r6 - if r6 - r7 = _nt_primary - s3 << r7 + s5 << r7 + if r7 + r8 = _nt_space + s5 << r8 + if r8 + i9 = index + r10 = _nt_not + if r10 + r9 = r10 + else + r11 = _nt_primary + if r11 + r9 = r11 + else + @index = i9 + r9 = nil + end + end + s5 << r9 end end end - if s3.last - r3 = instantiate_node(SyntaxNode,input, i3...index, s3) - r3.extend(And0) + if s5.last + r5 = instantiate_node(SyntaxNode,input, i5...index, s5) + r5.extend(And0) else - @index = i3 - r3 = nil + @index = i5 + r5 = nil end - if r3 - s2 << r3 + if r5 + s4 << r5 else break end end - r2 = instantiate_node(SyntaxNode,input, i2...index, s2) - s0 << r2 + r4 = instantiate_node(SyntaxNode,input, i4...index, s4) + s0 << r4 end if s0.last r0 = instantiate_node(SyntaxNode,input, i0...index, s0) r0.extend(And1) r0.extend(And2) @@ -221,10 +245,84 @@ node_cache[:and][start_index] = r0 r0 end + module Not0 + def space + elements[1] + end + + def p + elements[2] + end + end + + module Not1 + def query + Query::Not.new p.query + end + + def sql + ~ p.sql + end + end + + def _nt_not + start_index = index + if node_cache[:not].has_key?(index) + cached = node_cache[:not][index] + if cached + cached = SyntaxNode.new(input, index...(index + 1)) if cached == true + @index = cached.interval.end + end + return cached + end + + i0, s0 = index, [] + if has_terminal?('not', false, index) + r1 = instantiate_node(SyntaxNode,input, index...(index + 3)) + @index += 3 + else + terminal_parse_failure('not') + r1 = nil + end + s0 << r1 + if r1 + r2 = _nt_space + s0 << r2 + if r2 + i3 = index + r4 = _nt_not + if r4 + r3 = r4 + else + r5 = _nt_primary + if r5 + r3 = r5 + else + @index = i3 + r3 = nil + end + end + s0 << r3 + end + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(Not0) + r0.extend(Not1) + else + @index = i0 + r0 = nil + end + + node_cache[:not][start_index] = r0 + + r0 + end + module Primary0 def x elements[2] end @@ -328,24 +426,54 @@ end return cached end i0 = index - r1 = _nt_equals + r1 = _nt_true if r1 r0 = r1 else - r2 = _nt_not_equals + r2 = _nt_false if r2 r0 = r2 else - r3 = _nt_approximately + r3 = _nt_less_equal if r3 r0 = r3 else - @index = i0 - r0 = nil + r4 = _nt_less + if r4 + r0 = r4 + else + r5 = _nt_greater_equal + if r5 + r0 = r5 + else + r6 = _nt_greater + if r6 + r0 = r6 + else + r7 = _nt_equals + if r7 + r0 = r7 + else + r8 = _nt_not_equals + if r8 + r0 = r8 + else + r9 = _nt_approximately + if r9 + r0 = r9 + else + @index = i0 + r0 = nil + end + end + end + end + end + end end end end node_cache[:predicate][start_index] = r0 @@ -431,10 +559,330 @@ node_cache[:approximately][start_index] = r0 r0 end + module LessEqual0 + def field + elements[0] + end + + def value + elements[4] + end + end + + module LessEqual1 + def query + Query::LessEqual.new field.sql, value.sql + end + + def sql + Sequel::SQL::BooleanExpression.new(:<=, field.sql, value.sql) + end + end + + def _nt_less_equal + start_index = index + if node_cache[:less_equal].has_key?(index) + cached = node_cache[:less_equal][index] + if cached + cached = SyntaxNode.new(input, index...(index + 1)) if cached == true + @index = cached.interval.end + end + return cached + end + + i0, s0 = index, [] + r1 = _nt_field + s0 << r1 + if r1 + r3 = _nt_space + if r3 + r2 = r3 + else + r2 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r2 + if r2 + if has_terminal?('<=', false, index) + r4 = instantiate_node(SyntaxNode,input, index...(index + 2)) + @index += 2 + else + terminal_parse_failure('<=') + r4 = nil + end + s0 << r4 + if r4 + r6 = _nt_space + if r6 + r5 = r6 + else + r5 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r5 + if r5 + r7 = _nt_value + s0 << r7 + end + end + end + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(LessEqual0) + r0.extend(LessEqual1) + else + @index = i0 + r0 = nil + end + + node_cache[:less_equal][start_index] = r0 + + r0 + end + + module Less0 + def field + elements[0] + end + + def value + elements[4] + end + end + + module Less1 + def query + Query::Less.new field.sql, value.sql + end + + def sql + Sequel::SQL::BooleanExpression.new(:<, field.sql, value.sql) + end + end + + def _nt_less + start_index = index + if node_cache[:less].has_key?(index) + cached = node_cache[:less][index] + if cached + cached = SyntaxNode.new(input, index...(index + 1)) if cached == true + @index = cached.interval.end + end + return cached + end + + i0, s0 = index, [] + r1 = _nt_field + s0 << r1 + if r1 + r3 = _nt_space + if r3 + r2 = r3 + else + r2 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r2 + if r2 + if has_terminal?('<', false, index) + r4 = instantiate_node(SyntaxNode,input, index...(index + 1)) + @index += 1 + else + terminal_parse_failure('<') + r4 = nil + end + s0 << r4 + if r4 + r6 = _nt_space + if r6 + r5 = r6 + else + r5 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r5 + if r5 + r7 = _nt_value + s0 << r7 + end + end + end + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(Less0) + r0.extend(Less1) + else + @index = i0 + r0 = nil + end + + node_cache[:less][start_index] = r0 + + r0 + end + + module GreaterEqual0 + def field + elements[0] + end + + def value + elements[4] + end + end + + module GreaterEqual1 + def query + Query::GreaterEqual.new field.sql, value.sql + end + + def sql + Sequel::SQL::BooleanExpression.new(:>=, field.sql, value.sql) + end + end + + def _nt_greater_equal + start_index = index + if node_cache[:greater_equal].has_key?(index) + cached = node_cache[:greater_equal][index] + if cached + cached = SyntaxNode.new(input, index...(index + 1)) if cached == true + @index = cached.interval.end + end + return cached + end + + i0, s0 = index, [] + r1 = _nt_field + s0 << r1 + if r1 + r3 = _nt_space + if r3 + r2 = r3 + else + r2 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r2 + if r2 + if has_terminal?('>=', false, index) + r4 = instantiate_node(SyntaxNode,input, index...(index + 2)) + @index += 2 + else + terminal_parse_failure('>=') + r4 = nil + end + s0 << r4 + if r4 + r6 = _nt_space + if r6 + r5 = r6 + else + r5 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r5 + if r5 + r7 = _nt_value + s0 << r7 + end + end + end + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(GreaterEqual0) + r0.extend(GreaterEqual1) + else + @index = i0 + r0 = nil + end + + node_cache[:greater_equal][start_index] = r0 + + r0 + end + + module Greater0 + def field + elements[0] + end + + def value + elements[4] + end + end + + module Greater1 + def query + Query::Greater.new field.sql, value.sql + end + + def sql + Sequel::SQL::BooleanExpression.new(:>, field.sql, value.sql) + end + end + + def _nt_greater + start_index = index + if node_cache[:greater].has_key?(index) + cached = node_cache[:greater][index] + if cached + cached = SyntaxNode.new(input, index...(index + 1)) if cached == true + @index = cached.interval.end + end + return cached + end + + i0, s0 = index, [] + r1 = _nt_field + s0 << r1 + if r1 + r3 = _nt_space + if r3 + r2 = r3 + else + r2 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r2 + if r2 + if has_terminal?('>', false, index) + r4 = instantiate_node(SyntaxNode,input, index...(index + 1)) + @index += 1 + else + terminal_parse_failure('>') + r4 = nil + end + s0 << r4 + if r4 + r6 = _nt_space + if r6 + r5 = r6 + else + r5 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r5 + if r5 + r7 = _nt_value + s0 << r7 + end + end + end + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(Greater0) + r0.extend(Greater1) + else + @index = i0 + r0 = nil + end + + node_cache[:greater][start_index] = r0 + + r0 + end + module NotEquals0 def field elements[0] end @@ -621,38 +1069,126 @@ end return cached end i0 = index - r1 = _nt_double_quoted_string + r1 = _nt_true if r1 r0 = r1 else - r2 = _nt_float + r2 = _nt_false if r2 r0 = r2 else - r3 = _nt_integer + r3 = _nt_double_quoted_string if r3 r0 = r3 else - r4 = _nt_null + r4 = _nt_float if r4 r0 = r4 else - @index = i0 - r0 = nil + r5 = _nt_integer + if r5 + r0 = r5 + else + r6 = _nt_null + if r6 + r0 = r6 + else + @index = i0 + r0 = nil + end + end end end end end node_cache[:value][start_index] = r0 r0 end + module True0 + def query + Query::True.new + end + + def ruby_value + true + end + + def sql + Sequel::TRUE + end + end + + def _nt_true + start_index = index + if node_cache[:true].has_key?(index) + cached = node_cache[:true][index] + if cached + cached = SyntaxNode.new(input, index...(index + 1)) if cached == true + @index = cached.interval.end + end + return cached + end + + if has_terminal?('true', false, index) + r0 = instantiate_node(SyntaxNode,input, index...(index + 4)) + r0.extend(True0) + @index += 4 + else + terminal_parse_failure('true') + r0 = nil + end + + node_cache[:true][start_index] = r0 + + r0 + end + + module False0 + def query + Query::False.new + end + + def ruby_value + false + end + + def sql + Sequel::FALSE + end + end + + def _nt_false + start_index = index + if node_cache[:false].has_key?(index) + cached = node_cache[:false][index] + if cached + cached = SyntaxNode.new(input, index...(index + 1)) if cached == true + @index = cached.interval.end + end + return cached + end + + if has_terminal?('false', false, index) + r0 = instantiate_node(SyntaxNode,input, index...(index + 5)) + r0.extend(False0) + @index += 5 + else + terminal_parse_failure('false') + r0 = nil + end + + node_cache[:false][start_index] = r0 + + r0 + end + module Integer0 end module Integer1 def ruby_value @@ -900,11 +1436,23 @@ end if r5 r0 = r5 r0.extend(Field0) else - @index = i0 - r0 = nil + if has_terminal?("time", false, index) + r6 = instantiate_node(SyntaxNode,input, index...(index + 4)) + @index += 4 + else + terminal_parse_failure("time") + r6 = nil + end + if r6 + r0 = r6 + r0.extend(Field0) + else + @index = i0 + r0 = nil + end end end end end end