Sha256: 753f16b236cacb17e8e96bda9ce5c1626af65d32cc621dc25bcaa546e6f40946
Contents?: true
Size: 1.87 KB
Versions: 3
Compression:
Stored size: 1.87 KB
Contents
class Predicate class ToS < Sexpr::Processor def on_tautology(sexpr) "true" end def on_contradiction(sexpr) "false" end def on_qualified_identifier(sexpr) "#{sexpr.qualifier}.#{sexpr.name}" end def on_identifier(sexpr) if s = options[:scope] "#{s}.#{sexpr.last.to_s}" else "@#{sexpr.last.to_s}" end end def on_not(sexpr) "not(" << apply(sexpr.last, sexpr) << ")" end def on_and(sexpr) sexpr.sexpr_body.map{|term| apply(term, sexpr) }.join(" AND ") end def on_or(sexpr) sexpr.sexpr_body.map{|term| apply(term, sexpr) }.join(" OR ") end def on_dyadic(sexpr) sexpr.sexpr_body.map{|term| apply(term, sexpr) }.join(" #{sexpr.operator_symbol} ") end alias :on_eq :on_dyadic alias :on_neq :on_dyadic alias :on_lt :on_dyadic alias :on_lte :on_dyadic alias :on_gt :on_dyadic alias :on_gte :on_dyadic def on_in(sexpr) "#{apply(sexpr.identifier)} IN #{apply(sexpr.right)}" end def on_intersect(sexpr) "#{apply(sexpr.identifier)} INTERSECTS #{to_literal(sexpr.values)}" end def on_literal(sexpr) to_literal(sexpr.last) end def on_opaque(sexpr) "OPAQUE #{sexpr.last}" end def on_match(sexpr) "#{apply(sexpr.left)} =~ #{apply(sexpr.right)}" end def on_native(sexpr) sexpr.last.inspect end def on_missing(sexpr) raise "Unimplemented: #{sexpr.first}" end protected def to_literal(x) case x when Array then "{" << x.map{|y| to_literal(y) }.join(',') << "}" else x.inspect end end def apply(sexpr, parent = nil) code = super(sexpr) if parent && (parent.priority >= sexpr.priority) code = "(" << code << ")" end code end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
predicate-2.2.1 | lib/predicate/processors/to_s.rb |
predicate-2.2.0 | lib/predicate/processors/to_s.rb |
predicate-2.1.0 | lib/predicate/processors/to_s.rb |