Class: Dhall::ExpressionVisitor
- Inherits:
-
Object
- Object
- Dhall::ExpressionVisitor
- Defined in:
- lib/dhall/normalize.rb
Constant Summary collapse
- ExpressionHash =
Util::HashOf.new( ValueSemantics::Anything, ValueSemantics::Either.new([Expression, nil]) )
- ExpressionArray =
Util::ArrayOf.new(Expression)
Instance Method Summary collapse
-
#initialize(&block) ⇒ ExpressionVisitor
constructor
A new instance of ExpressionVisitor.
- #one_visit(value) ⇒ Object
- #visit(expr) ⇒ Object
Constructor Details
#initialize(&block) ⇒ ExpressionVisitor
Returns a new instance of ExpressionVisitor.
15 16 17 |
# File 'lib/dhall/normalize.rb', line 15 def initialize(&block) @block = block end |
Instance Method Details
#one_visit(value) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dhall/normalize.rb', line 26 def one_visit(value) case value when Expression @block[value] when ExpressionArray value.map(&@block) when ExpressionHash Hash[value.map { |k, v| [k, v.nil? ? v : @block[v]] }.sort] end end |
#visit(expr) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/dhall/normalize.rb', line 19 def visit(expr) expr.to_h.each_with_object({}) do |(attr, value), h| result = one_visit(value) h[attr] = result if result end end |