Sha256: 1cb239eb4c97e5b847a2de2a7959821cbc14b48f75f1128dde76f8abaab6971c

Contents?: true

Size: 1.94 KB

Versions: 2

Compression:

Stored size: 1.94 KB

Contents

module Pione
  module Transformer
    # RuleDefinitionTransformer is a transformer for syntax tree of rule definitions.
    module RuleDefinitionTransformer
      include TransformerModule

      # @api private
      def check_model_type(obj, pione_model_type)
        pione_model_type.match(obj.pione_mode_type)
      end
      module_function :check_model_type

      # Transform +:rule_definition+ as Model::Rule.
      rule(:rule_definition => {
          :rule_header => simple(:rule_expr),
          :rule_conditions => sequence(:conditions),
          :block => simple(:block) }) {
        inputs = Naming::InputLine.values(conditions)
        outputs = Naming::OutputLine.values(conditions)
        params = Parameters.merge(*Naming::ParamLine.values(conditions))
        features = Feature::AndExpr.new(*Naming::FeatureLine.values(conditions))
        condition = RuleCondition.new(inputs, outputs, params, features, TicketExpr.empty, TicketExpr.empty)
        case block
        when ActionBlock
          ActionRule
        when FlowBlock
          FlowRule
        end.new(rule_expr, condition, block)
      }

      # Transform +:input_line+ as Naming::InputLine.
      rule(:input_line => simple(:data_expr)) {
        TypeDataExpr.check(data_expr)
        Naming.InputLine(data_expr)
      }

      # Transform +:output_line+ as Naming::OutputLine.
      rule(:output_line => simple(:data_expr)) {
        TypeDataExpr.check(data_expr)
        Naming.OutputLine(data_expr)
      }

      # Transform +:param_line+ as Naming::ParamLine.
      rule(:param_line => simple(:param)) {
        unless TypeAssignment.match(param) or TypeParameters.match(param)
          raise PioneModelTypeError.new(param, TypeAssignment)
        end
        Naming.ParamLine(param)
      }

      # Transform +:feature_line+ as Naming::FeatureLine.
      rule(:feature_line => simple(:feature)) {
        TypeFeature.check(feature)
        Naming.FeatureLine(feature)
      }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pione-0.1.3 lib/pione/transformer/rule-definition-transformer.rb
pione-0.1.2 lib/pione/transformer/rule-definition-transformer.rb