Skip to content

Commit

Permalink
Refactor to syntax.treetop. Identifier in Field. Comparison has field…
Browse files Browse the repository at this point in the history
… and argument
  • Loading branch information
eduardoneira committed Nov 28, 2019
1 parent 14d46fa commit 8dc147a
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion lib/rasti/db/nql/nodes/comparisons/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Comparisons
class Base < Treetop::Runtime::SyntaxNode

def dependency_tables
left.tables.empty? ? [] : [left.tables.join('.')]
field.tables.empty? ? [] : [field.tables.join('.')]
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/rasti/db/nql/nodes/comparisons/equal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Comparisons
class Equal < Base

def to_filter
{ left.to_filter => right.value }
{ field.identifier => argument.value }
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/rasti/db/nql/nodes/comparisons/greater_than.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Comparisons
class GreaterThan < Base

def to_filter
left.to_filter > right.value
field.identifier > argument.value
end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Comparisons
class GreaterThanOrEqual < Base

def to_filter
left.to_filter >= right.value
field.identifier >= argument.value
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/rasti/db/nql/nodes/comparisons/include.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Comparisons
class Include < Base

def to_filter
Sequel.ilike(left.to_filter, "%#{right.value}%")
Sequel.ilike(field.identifier, "%#{argument.value}%")
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/rasti/db/nql/nodes/comparisons/less_than.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Comparisons
class LessThan < Base

def to_filter
left.to_filter < right.value
field.identifier < argument.value
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/rasti/db/nql/nodes/comparisons/less_than_or_equal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Comparisons
class LessThanOrEqual < Base

def to_filter
left.to_filter <= right.value
field.identifier <= argument.value
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/rasti/db/nql/nodes/comparisons/like.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Comparisons
class Like < Base

def to_filter
Sequel.ilike(left.to_filter, right.value)
Sequel.ilike(field.identifier, argument.value)
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/rasti/db/nql/nodes/comparisons/not_equal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Comparisons
class NotEqual < Base

def to_filter
Sequel.negate(left.to_filter => right.value)
Sequel.negate(field.identifier => argument.value)
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/rasti/db/nql/nodes/comparisons/not_include.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Comparisons
class NotInclude < Base

def to_filter
~ Sequel.ilike(left.to_filter, "%#{right.value}%")
~ Sequel.ilike(field.identifier, "%#{argument.value}%")
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/rasti/db/nql/nodes/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module NQL
module Nodes
class Field < Treetop::Runtime::SyntaxNode

def to_filter
def identifier
tables.empty? ? Sequel[column.to_sym] : Sequel[tables.join('__').to_sym][column.to_sym]
end

Expand Down
36 changes: 18 additions & 18 deletions lib/rasti/db/nql/syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -510,15 +510,15 @@ def _nt_field
end

module ComparisonInclude0
def left
def field
elements[0]
end

def comparator
elements[2]
end

def right
def argument
elements[4]
end
end
Expand Down Expand Up @@ -591,15 +591,15 @@ def _nt_comparison_include
end

module ComparisonNotInclude0
def left
def field
elements[0]
end

def comparator
elements[2]
end

def right
def argument
elements[4]
end
end
Expand Down Expand Up @@ -672,15 +672,15 @@ def _nt_comparison_not_include
end

module ComparisonLike0
def left
def field
elements[0]
end

def comparator
elements[2]
end

def right
def argument
elements[4]
end
end
Expand Down Expand Up @@ -753,15 +753,15 @@ def _nt_comparison_like
end

module ComparisonGreaterThan0
def left
def field
elements[0]
end

def comparator
elements[2]
end

def right
def argument
elements[4]
end
end
Expand Down Expand Up @@ -834,15 +834,15 @@ def _nt_comparison_greater_than
end

module ComparisonGreaterThanOrEqual0
def left
def field
elements[0]
end

def comparator
elements[2]
end

def right
def argument
elements[4]
end
end
Expand Down Expand Up @@ -915,15 +915,15 @@ def _nt_comparison_greater_than_or_equal
end

module ComparisonLessThan0
def left
def field
elements[0]
end

def comparator
elements[2]
end

def right
def argument
elements[4]
end
end
Expand Down Expand Up @@ -996,15 +996,15 @@ def _nt_comparison_less_than
end

module ComparisonLessThanOrEqual0
def left
def field
elements[0]
end

def comparator
elements[2]
end

def right
def argument
elements[4]
end
end
Expand Down Expand Up @@ -1077,15 +1077,15 @@ def _nt_comparison_less_than_or_equal
end

module ComparisonNotEqual0
def left
def field
elements[0]
end

def comparator
elements[2]
end

def right
def argument
elements[4]
end
end
Expand Down Expand Up @@ -1158,15 +1158,15 @@ def _nt_comparison_not_equal
end

module ComparisonEqual0
def left
def field
elements[0]
end

def comparator
elements[2]
end

def right
def argument
elements[4]
end
end
Expand Down
18 changes: 9 additions & 9 deletions lib/rasti/db/nql/syntax.treetop
Original file line number Diff line number Diff line change
Expand Up @@ -47,39 +47,39 @@ module Rasti
end

rule comparison_include
left:field space* comparator:':' space* right:basic <Nodes::Comparisons::Include>
field:field space* comparator:':' space* argument:basic <Nodes::Comparisons::Include>
end

rule comparison_not_include
left:field space* comparator:'!:' space* right:basic <Nodes::Comparisons::NotInclude>
field:field space* comparator:'!:' space* argument:basic <Nodes::Comparisons::NotInclude>
end

rule comparison_like
left:field space* comparator:'~' space* right:basic <Nodes::Comparisons::Like>
field:field space* comparator:'~' space* argument:basic <Nodes::Comparisons::Like>
end

rule comparison_greater_than
left:field space* comparator:'>' space* right:basic <Nodes::Comparisons::GreaterThan>
field:field space* comparator:'>' space* argument:basic <Nodes::Comparisons::GreaterThan>
end

rule comparison_greater_than_or_equal
left:field space* comparator:'>=' space* right:basic <Nodes::Comparisons::GreaterThanOrEqual>
field:field space* comparator:'>=' space* argument:basic <Nodes::Comparisons::GreaterThanOrEqual>
end

rule comparison_less_than
left:field space* comparator:'<' space* right:basic <Nodes::Comparisons::LessThan>
field:field space* comparator:'<' space* argument:basic <Nodes::Comparisons::LessThan>
end

rule comparison_less_than_or_equal
left:field space* comparator:'<=' space* right:basic <Nodes::Comparisons::LessThanOrEqual>
field:field space* comparator:'<=' space* argument:basic <Nodes::Comparisons::LessThanOrEqual>
end

rule comparison_not_equal
left:field space* comparator:'!=' space* right:basic <Nodes::Comparisons::NotEqual>
field:field space* comparator:'!=' space* argument:basic <Nodes::Comparisons::NotEqual>
end

rule comparison_equal
left:field space* comparator:'=' space* right:basic <Nodes::Comparisons::Equal>
field:field space* comparator:'=' space* argument:basic <Nodes::Comparisons::Equal>
end

rule basic
Expand Down

0 comments on commit 8dc147a

Please sign in to comment.