lib/parser/parser_nodes.rb in tla-parser-s-0.1.0 vs lib/parser/parser_nodes.rb in tla-parser-s-0.1.2
- old
+ new
@@ -78,10 +78,17 @@
end
class Parameters <IdentifierList
end
+ class ProcVariables <IdentifierList
+ def identifier_nodes
+ recursive_select( Sexp::VariableDef).first.recursive_select( Sexp::Identifier )
+ end
+
+ end
+
class ExpressionList <Root
end
@@ -313,11 +320,42 @@
def expression_val
text_value
end
end
+
+ class IfExpressionCondition < Root
+ end
+ class IfExpressionThen < Root
+ end
+ class IfExpressionElse < Root
+ end
+ class IfExpression < SimpleExpression
+
+ # Node for condition
+ # @return [Expression] for IF condition
+ def condition_node
+ recursive_select( Sexp::IfExpressionCondition ).first.recursive_select(Sexp::Expression).first
+ end
+ # @return [Expression] for THEN expression
+ def then_expression_node
+ recursive_select( Sexp::IfExpressionThen ).first.recursive_select(Sexp::Expression).first end
+
+ # @return [Expression] for ELSE expression
+ def else_expression_node
+ tree_node = recursive_select( Sexp::IfExpressionElse ).first
+ return tree_node unless tree_node
+ tree_node.recursive_select(Sexp::Expression).first
+ end
+
+ def name
+ 'IF'
+ end
+
+ end
+
class ChooseExpression < SimpleExpression
# @return [BoundInExpression] root node for x \in S
def binds_node
recursive_select( Sexp::BoundInExpression ).first
@@ -438,12 +476,12 @@
nil
end
def expression_val
"exprsssion"
end
- def record_identifier
- recursive_select( Sexp::RecordExceptIdentifier ).first.recursive_select( Sexp::Identifier ).first.expression_val
+ def record_base
+ recursive_select( Sexp::RecordExcepBase ).first.recursive_select( Sexp::Expression ).first
end
def record_field_definitions
# rigth recursion results to empty RecordExceptField -node
recursive_select( Sexp::RecordExceptField ).select{ |f| f.elements && f.elements.any? }
end
@@ -457,11 +495,11 @@
# first is expression for lvalue
recursive_select( Sexp::Expression ).last
end
end
- class RecordExceptIdentifier < Root
+ class RecordExcepBase < Root
end
class RecordDefinition < AbstactExpression
# output during 'AbstactExpression.traverse'
@@ -530,10 +568,11 @@
def tuples
recursive_select( Sexp::Expression )
end
end
+
class AbstractSetExpression < AbstactExpression
# AbstactExpression.traverse quit traversing the expression
def lhs_node
nil
end
@@ -562,10 +601,16 @@
# # ret = deffi.first.recursive_select( Sexp::SetExpression ).first
# puts "set_expression=#{ret.inspect}"
ret
end
+ # Elements defined on constructore
+ def set_elements
+ elems = recursive_select( Sexp::Expression )
+ elems
+ end
+
# For documentation purposes symbol table context needs a name
# (For procedures, and macros name is ovbious. For a set
# expression we define name set a string "Set+<generator set>"
#
# @return [String] name identifying context in symbol table
@@ -574,11 +619,11 @@
end
# Some variables in 'set_expression' (most likely) refer to
# variable defined in set constructor generate. Return name of
# this variables.
#
- # @return [Array] of one hash with ':node_type',':value' properties
+ # @return [Hash:Array] with :node_type,:value, :tree -properties
def symbol_definitions
return [] unless binds_node
[ { :node_type => node_type, :value => binds_node.bind_var.expression_val, :tree=>binds_node } ]
end
@@ -588,10 +633,13 @@
end
class SetExpression < AbstractSetExpression
end
+ class SetConstructor < AbstractSetExpression
+ end
+
class FieldBy < AbstactExpression
# AbstractExpression.traverse - do not recurse will evaluate separetetely
def lhs_node
nil
end
@@ -600,10 +648,12 @@
end
end
+
+
class FieldByName < FieldBy
# @return [AbstactExpression] defining the name
def field_name_expression
recursive_select( Sexp::AbstactExpression ).first
@@ -961,10 +1011,11 @@
end
def parameters
node = parameters_node
return node.value if node
end
+
def body_node
ret = recursive_select(Sexp::Statement).first
ret
end
@@ -979,25 +1030,64 @@
:parameters => parameters,
:body => body,
}
end
- # Symbols defined in this node
#
- # @return [Hash:Array] symbol hash with ':node_type', :value,
- # :tree properties
- def symbol_definitions
+ # @return [Hash:Array] symbol hash with ':node_type', :value,:tree properties
+ def parameter_definitions
parameter_def = parameters
return [] unless parameter_def
parameter_def[:value]
end
+
+ def declaration_definitions
+ []
+ end
+
+ # Symbols defined in this node. They include parameters
+ # and declarations (normally only in procedure)
+ def symbol_definitions
+ # unique b
+ return parameter_definitions + declaration_definitions
+ end
+
end
class Macro < Callable
end
class Procedure < Callable
+
+ # @return [Nil|ProcVariables] of variable definition node for procedure
+ def procedure_variables_node
+ tree_nodes = recursive_select(Sexp::ProcVariables)
+ return tree_nodes.first if tree_nodes
+ end
+
+ # @return [VariableDef:Array] variable declarations
+ def variable_declarations
+ return [] unless procedure_variables_node
+ return procedure_variables_node.recursive_select(Sexp::VariableDef)
+ end
+
+ def procedure_variables
+ # node = procedure_variables_node
+ # return node.value if node
+ variable_declarations.map { |variable_declaration| variable_declaration.variable.value }
+ end
+
+
+ # overrides method in parent to return decclartions in
+ # @return [VariableDef:Array] of variable definition, empty array if no definition
+ def declaration_definitions
+ declaration_def = procedure_variables
+ return [] unless declaration_def.any?
+ declaration_def
+ end
+
+
end
class OperatorDef < Callable
# For operator no body:
@@ -1014,9 +1104,15 @@
#
def name
recursive_select(Sexp::Identifier).first.node_value
end
+
+ # @return [Identifier] tree node for variable defined
+ def variable
+ tree_nodes = recursive_select(Sexp::Identifier).first
+ end
+
# @return [Expression] tree node for init expression
def init
tree_nodes = recursive_select(Sexp::Expression).first
end