Class: Pione::Lang::FeatureSequence
- Inherits:
-
OrdinalSequence
- Object
- StructX
- Expr
- Sequence
- OrdinalSequence
- Pione::Lang::FeatureSequence
- Includes:
- ComplexFeatureMethod
- Defined in:
- lib/pione/lang/feature-expr.rb
Overview
FeatureSequence represents disjunction of feature pieces.
Class Method Summary collapse
Instance Method Summary collapse
- #_match(provider_piece, request_piece) ⇒ Object
- #concat(other) ⇒ Object
-
#match(other) ⇒ Object
(also: #===)
Return true if the feature accepts other feature.
Methods included from ComplexFeatureMethod
Methods inherited from OrdinalSequence
#empty, #fold, fold, fold2, #fold2, #inspect, make_piece, #map, map, map2, #map2, map3, #map3, #map_by
Methods inherited from Sequence
#assertive?, #attribute, #each, #eval, index_type, inherited, piece_class, piece_classes, #push, #set_annotation_type, set_index_type, #update_pieces, void, #void?
Methods included from Callable
Methods included from Util::Positionable
#line_and_column, #pos, #set_source_position
Methods inherited from Expr
#eval, #eval!, inherited, pione_type, set_pione_type, #textize, #to_s
Class Method Details
.of(*args) ⇒ Object
170 171 172 173 |
# File 'lib/pione/lang/feature-expr.rb', line 170 def of(*args) args.each {|arg| raise ArgumentError(arg) unless arg.is_a?(FeaturePiece)} args.size > 0 ? new(args) : new([EmptyFeature.new]) end |
Instance Method Details
#_match(provider_piece, request_piece) ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/pione/lang/feature-expr.rb', line 211 def _match(provider_piece, request_piece) # apply eliminations _provider_piece, _request_piece = Eliminator.new(provider_piece, request_piece).eliminate # features are matched if both pieces are empty return true if _provider_piece.is_a?(EmptyFeature) and _request_piece.is_a?(EmptyFeature) # feature are unmatched if peaces are not elminated return false if provider_piece == _provider_piece and request_piece == _request_piece # next return _match(_provider_piece, _request_piece) end |
#concat(other) ⇒ Object
178 179 180 181 182 183 184 185 186 |
# File 'lib/pione/lang/feature-expr.rb', line 178 def concat(other) acceptable = feature_type.nil? or feature_type == :both other_acceptable = other.feature_type.nil? or other.feature_type == :both if feature_type == other.feature_type or acceptable or other_acceptable super(other) else raise SequenceAttributeError.new(other) end end |
#match(other) ⇒ Object Also known as: ===
Return true if the feature accepts other feature.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/pione/lang/feature-expr.rb', line 189 def match(other) provider_pieces = pieces request_pieces = other.pieces if feature_type == :request or other.feature_type == :provider provider_pieces = other.pieces request_pieces = pieces end provider_pieces = [EmptyFeature.new] if provider_pieces.empty? request_pieces = [EmptyFeature.new] if request_pieces.empty? provider_pieces.any? do |provider_piece| request_pieces.any? do |request_piece| _match(provider_piece, request_piece) end end end |