Class: Alf::Predicate::ToRubyCode

Inherits:
Sexpr::Processor
  • Object
show all
Defined in:
lib/alf-predicate/alf/predicate/processors/to_ruby_code.rb

Instance Method Summary collapse

Instance Method Details

#on_contradiction(sexpr) ⇒ Object



9
10
11
# File 'lib/alf-predicate/alf/predicate/processors/to_ruby_code.rb', line 9

def on_contradiction(sexpr)
  "false"
end

#on_dyadic(sexpr) ⇒ Object Also known as: on_eq, on_neq, on_lt, on_lte, on_gt, on_gte



33
34
35
36
37
# File 'lib/alf-predicate/alf/predicate/processors/to_ruby_code.rb', line 33

def on_dyadic(sexpr)
  sexpr.sexpr_body.map{|term|
    apply(term, sexpr)
  }.join(" #{sexpr.operator_symbol} ")
end

#on_in(sexpr) ⇒ Object



45
46
47
# File 'lib/alf-predicate/alf/predicate/processors/to_ruby_code.rb', line 45

def on_in(sexpr)
  "#{Support.to_ruby_literal(sexpr.values)}.include?(#{apply(sexpr.var_ref)})"
end

#on_literal(sexpr) ⇒ Object



58
59
60
# File 'lib/alf-predicate/alf/predicate/processors/to_ruby_code.rb', line 58

def on_literal(sexpr)
  Support.to_ruby_literal(sexpr.last)
end

#on_nadic_bool(sexpr) ⇒ Object Also known as: on_and, on_or



25
26
27
28
29
# File 'lib/alf-predicate/alf/predicate/processors/to_ruby_code.rb', line 25

def on_nadic_bool(sexpr)
  sexpr.sexpr_body.map{|term|
    apply(term, sexpr)
  }.join(" #{sexpr.operator_symbol} ")
end

#on_native(sexpr) ⇒ Object

Raises:



49
50
51
52
53
54
55
56
# File 'lib/alf-predicate/alf/predicate/processors/to_ruby_code.rb', line 49

def on_native(sexpr)
  proc = sexpr.to_proc
  if proc.respond_to?(:to_ruby_literal) &&
     (proc.to_ruby_literal =~ /^\s*lambda{\s*(.*?)\s*}\s*$/)
    return $1
  end
  raise NotSupportedError
end

#on_not(sexpr) ⇒ Object



21
22
23
# File 'lib/alf-predicate/alf/predicate/processors/to_ruby_code.rb', line 21

def on_not(sexpr)
  "#{sexpr.operator_symbol}" << apply(sexpr.last, sexpr)
end

#on_tautology(sexpr) ⇒ Object



5
6
7
# File 'lib/alf-predicate/alf/predicate/processors/to_ruby_code.rb', line 5

def on_tautology(sexpr)
  "true"
end

#on_var_ref(sexpr) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/alf-predicate/alf/predicate/processors/to_ruby_code.rb', line 13

def on_var_ref(sexpr)
  if s = options[:scope]
    "#{s}.#{sexpr.last.to_s}"
  else
    sexpr.last.to_s
  end
end