Class: SbuilderSexp::Statement

Inherits:
Root show all
Defined in:
lib/parser/parser_nodes.rb

Overview

Tree node with ‘Label’ and Unlabeled statement

Direct Known Subclasses

UnlabeledStatement

Instance Method Summary collapse

Methods inherited from Treetop::Runtime::SyntaxNode

#node_type, #recursive_inject, #recursive_inject_parent, #recursive_select, #value

Instance Method Details

#find_labelnodeObject

Locate ‘Label’ as direct child. Compound statements may contain statement, which are also labeled, and we cannot just do ‘recursive_select’



865
866
867
868
869
870
871
872
873
874
875
# File 'lib/parser/parser_nodes.rb', line 865

def find_labelnode
  
  # return labelnode = recursive_select( SbuilderSexp::Label ).first
  if !elements.nil? then
    elements.each do |e|
      return e if e.is_a?( SbuilderSexp::Label ) 
    end
  end
  # Label node not found
  nil
end

#get_statementUnlabeledStatement:TreeNode

Returns TLA -language statement.

Returns:

  • (UnlabeledStatement:TreeNode)

    TLA -language statement



885
886
887
888
# File 'lib/parser/parser_nodes.rb', line 885

def get_statement
  ret = recursive_select( SbuilderSexp::UnlabeledStatement ).first
  ret
end

#node_valueObject



919
920
921
# File 'lib/parser/parser_nodes.rb', line 919

def node_value
  statement_val
end

#statement_labelLabel:SyntaxTree

Returns label assigned to the statement (nil if no label).

Returns:

  • (Label:SyntaxTree)

    label assigned to the statement (nil if no label)



878
879
880
881
882
# File 'lib/parser/parser_nodes.rb', line 878

def statement_label
  labelnode = find_labelnode
  return labelnode.label if labelnode
  return nil
end

#statement_valstring

Returns the value for traserval.

Returns:

  • (string)

    the value for traserval



900
901
902
# File 'lib/parser/parser_nodes.rb', line 900

def statement_val
  nil
end

#statementsObject

tree structure (for compund statments)



891
892
893
# File 'lib/parser/parser_nodes.rb', line 891

def statements
  nil
end

#traverse(memo = "", &blk) ⇒ Object



904
905
906
907
908
909
910
911
912
913
914
915
916
917
# File 'lib/parser/parser_nodes.rb', line 904

def traverse( memo="", &blk )
  # visit label as 'Statement' node
  memo = yield( memo, node_type, self ) if statement_label
  
  # visit the real thing 'as object sekf'
  uls = get_statement
  # raise "No unlabeled_statement statement found #{self} from \n '#{inspect}'  " unless uls

  memo = yield( memo, uls.node_type, uls )  if uls

  statements.each{ |s| memo = s.traverse( memo, &blk ) } if statements

  memo
end