Class: Expressir::Express::Builders::RuleDeclBuilder
- Inherits:
-
Object
- Object
- Expressir::Express::Builders::RuleDeclBuilder
- Defined in:
- lib/expressir/express/builders/rule_decl_builder.rb
Overview
Builds rule declaration nodes.
Instance Method Summary collapse
Instance Method Details
#call(ast_data) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/expressir/express/builders/rule_decl_builder.rb', line 8 def call(ast_data) head = ast_data[:rule_head] algorithm_head = ast_data[:algorithm_head] stmts = ast_data[:stmt] where_clause = ast_data[:where_clause] id = Builder.build_optional(head[:rule_id]) if head applies_to = build_applies_to(head) declarations = [] if algorithm_head.is_a?(Hash) declarations = Builder.build_children(algorithm_head[:declaration]) end types = declarations.grep(Expressir::Model::Declarations::Type) entities = declarations.grep(Expressir::Model::Declarations::Entity) subtype_constraints = declarations.grep(Expressir::Model::Declarations::SubtypeConstraint) functions = declarations.grep(Expressir::Model::Declarations::Function) procedures = declarations.grep(Expressir::Model::Declarations::Procedure) constants = if algorithm_head.is_a?(Hash) && algorithm_head[:constant_decl] build_constant_decl(algorithm_head[:constant_decl]) else [] end variables = if algorithm_head.is_a?(Hash) && algorithm_head[:local_decl] build_local_decl(algorithm_head[:local_decl]) else [] end statements = Builder.build_children(stmts) where_rules = where_clause ? Builder.build({ where_clause: where_clause }) : [] Expressir::Model::Declarations::Rule.new( id: id, applies_to: Builder.ensure_array(applies_to), types: types, entities: entities, subtype_constraints: subtype_constraints, functions: functions, procedures: procedures, constants: constants, variables: variables, statements: statements.compact, where_rules: [where_rules].flatten, ) end |