Class: Sexpir::If

Inherits:
Ast
  • Object
show all
Defined in:
lib/sexpir/ast.rb,
lib/sexpir/ast_sexp.rb

Instance Attribute Summary collapse

Attributes inherited from Ast

#node

Instance Method Summary collapse

Methods inherited from Ast

#accept

Constructor Details

#initializeIf



67
68
69
# File 'lib/sexpir/ast.rb', line 67

def initialize
  @elsifs=[]
end

Instance Attribute Details

#condObject

Returns the value of attribute cond.



66
67
68
# File 'lib/sexpir/ast.rb', line 66

def cond
  @cond
end

#elseObject

Returns the value of attribute else.



66
67
68
# File 'lib/sexpir/ast.rb', line 66

def else
  @else
end

#elsifsObject

Returns the value of attribute elsifs.



66
67
68
# File 'lib/sexpir/ast.rb', line 66

def elsifs
  @elsifs
end

#thenObject

Returns the value of attribute then.



66
67
68
# File 'lib/sexpir/ast.rb', line 66

def then
  @then
end

Instance Method Details

#sexpObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/sexpir/ast_sexp.rb', line 112

def sexp
  code=Code.new
  code << "(if #{cond.sexp}"
  code.indent=2
  code << "(then"
  code.indent=4
  code << self.then.sexp
  code.indent=2
  code << ")"
  if self.else
    code << "(else"
    code.indent=4
    code << self.else.sexp
    code.indent=2
    code << ")"
  end
  code.indent=0
  code << ")"
  code
end