Sha256: ed804b94db94c0044805293935daab30a5a376ceb1406b5482891c2f99aad828

Contents?: true

Size: 1.65 KB

Versions: 6

Compression:

Stored size: 1.65 KB

Contents

module Pione
  module Transformer
    # FeatureExprTransformer is a transformer for syntax tree of feature
    # expressions.
    module FeatureExprTransformer
      include TransformerModule

      # Transform +:feature_name+ as feature expression model corresponding to
      # the operator.
      rule(:atomic_feature =>
           { :operator => simple(:operator),
             :symbol => simple(:symbol) }
           ) do
        case operator
        when "+"
          Feature::RequisiteExpr.new(symbol.str)
        when "-"
          Feature::BlockingExpr.new(symbol.str)
        when "?"
          Feature::PreferredExpr.new(symbol.str)
        when "^"
          Feature::PossibleExpr.new(symbol.str)
        when "!"
          Feature::RestrictiveExpr.new(symbol.str)
        end
      end

      # Transform +:atomic_feature+ as empty feature or boundless feature.
      rule(:atomic_feature => {:symbol => simple(:symbol)}) {
        case symbol
        when "*"
          Feature.empty
        when "@"
          Feature.boundless
        end
      }

      # Extract the content of +:feature_expr+.
      rule(:feature_expr => simple(:expr)) do
        expr
      end

      # Transform +:feature conjunction+ as Feature::AndExpr.
      rule(:feature_conjunction => {
             :left => simple(:left),
             :right => simple(:right)
           }) do
        Feature::AndExpr.new(left, right)
      end

      # Transform +:feature_disjunction+ as Feature::OrExpr.
      rule(:feature_disjunction => {
             :left => simple(:left),
             :right => simple(:right)
           }) do
        Feature::OrExpr.new(left, right)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pione-0.2.2 lib/pione/transformer/feature-expr-transformer.rb
pione-0.2.1 lib/pione/transformer/feature-expr-transformer.rb
pione-0.2.0 lib/pione/transformer/feature-expr-transformer.rb
pione-0.1.4 lib/pione/transformer/feature-expr-transformer.rb
pione-0.1.3 lib/pione/transformer/feature-expr-transformer.rb
pione-0.1.2 lib/pione/transformer/feature-expr-transformer.rb