class RedParse::ListInNode::CaseNode

Attributes

empty_else[R]

Public Class Methods

new(caseword, condition, semi, whens, otherwise, endword) click to toggle source
Calls superclass method RedParse::ListInNode::Node::new
# File lib/redparse/node.rb, line 4492
def initialize(caseword, condition, semi, whens, otherwise, endword)
  @offset=caseword.offset
  if otherwise
    otherwise=otherwise.val
    @empty_else=!otherwise
  else
    @empty_else=false
  end
  whens.extend ListInNode
  super(condition,whens,otherwise)
end

Public Instance Methods

image() click to toggle source
# File lib/redparse/node.rb, line 4517
def image; "(case)" end
parsetree(o) click to toggle source
# File lib/redparse/node.rb, line 4526
def parsetree(o)
  result=[:case, condition&&condition.parsetree(o)]+ 
           whens.map{|whennode| whennode.parsetree(o)}
  other=otherwise&&otherwise.parsetree(o)
  return [] if result==[:case, nil] and !other
  if other and other[0..1]==[:case, nil] and !condition
    result.concat other[2..-1]
  else
    result<<other
  end
  return result
end
to_lisp() click to toggle source
# File lib/redparse/node.rb, line 4519
def to_lisp
  "(case #{case_.to_lisp}\n"+
    whens.map{|x| x.to_lisp}.join("\n")+"\n"+
    "(else #{else_.to_lisp}"+
  "\n)"
end
unparse(o=default_unparse_options) click to toggle source
# File lib/redparse/node.rb, line 4506
def unparse o=default_unparse_options
  result="case #{condition&&condition.unparse(o)}"+
         whens.map{|wh| wh.unparse o}.join

  result += unparse_nl(otherwise,o)+"else "+otherwise.unparse(o) if otherwise
  result += ";else;" if @empty_else
  result += ";end"

  return result
end