Module: Dhall::Parser::Expression

Defined in:
lib/dhall/parser.rb

Instance Method Summary collapse

Instance Method Details

#arrowObject



56
57
58
59
60
61
# File 'lib/dhall/parser.rb', line 56

def arrow
  Forall.of_arguments(
    capture(:operator_expression).value,
    body: capture(:expression).value
  )
end

#forallObject



48
49
50
51
52
53
54
# File 'lib/dhall/parser.rb', line 48

def forall
  Forall.new(
    var:  capture(:nonreserved_label).value,
    type: captures(:expression)[0].value,
    body: captures(:expression)[1].value
  )
end

#ifObject



63
64
65
66
67
68
69
# File 'lib/dhall/parser.rb', line 63

def if
  If.new(
    predicate: captures(:expression)[0].value,
    then:      captures(:expression)[1].value,
    else:      captures(:expression)[2].value
  )
end

#lambdaObject



40
41
42
43
44
45
46
# File 'lib/dhall/parser.rb', line 40

def lambda
  Function.new(
    var:  capture(:nonreserved_label).value,
    type: captures(:expression)[0].value,
    body: captures(:expression)[1].value
  )
end

#let_bindingObject



33
34
35
36
37
38
# File 'lib/dhall/parser.rb', line 33

def let_binding
  LetBlock.for(
    lets: captures(:let_binding).map(&:value),
    body: capture(:expression).value
  )
end

#listObject



79
80
81
# File 'lib/dhall/parser.rb', line 79

def list
  EmptyList.new(type: capture(:application_expression).value)
end

#mergeObject



71
72
73
74
75
76
77
# File 'lib/dhall/parser.rb', line 71

def merge
  Merge.new(
    record: captures(:import_expression)[0].value,
    input:  captures(:import_expression)[1].value,
    type:   capture(:application_expression)&.value
  )
end

#tomapObject



83
84
85
86
87
88
# File 'lib/dhall/parser.rb', line 83

def tomap
  ToMap.new(
    record: capture(:import_expression).value,
    type:   capture(:application_expression).value
  )
end

#valueObject



23
24
25
26
27
28
29
30
31
# File 'lib/dhall/parser.rb', line 23

def value
  return list if string =~ /\A\[\s*\]/

  key =
    [:let_binding, :lambda, :forall, :arrow, :if, :merge, :tomap]
    .find { |k| captures.key?(k) }

  key ? public_send(key) : super
end