Class: Mapper::RuleAlt

Inherits:
Array
  • Object
show all
Defined in:
../lib/grammar.rb

Overview

One rule alternative. Mapper::RuleAlt is, in fact, an array of Mapper::Token structures. For instance:


  <expr> ::= X*Y  
  

defines the Mapper::Rule of one RuleAlt alternative for the symbol . The first and only RuleAlt consists of this sequence:


  Mapper::Token.new( :symbol, 'X' )
  Mapper::Token.new( :literal, '*' )
  Mapper::Token.new( :symbol, 'Y' )

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (RuleAlt) initialize(ary = nil, recursive = nil, arity = nil, min_depth = nil)

Initialize the array of the rules. The src argument is the instance of an array of Mapper::Token instances. The recursive argument will be copied into self.recursivity attribute. The arity argument will be copied into self.arity attribute. The min_depth will be copied into self.min_depth attribute.



74
75
76
77
78
79
# File '../lib/grammar.rb', line 74

def initialize( ary=nil, recursive=nil, arity=nil, min_depth=nil )
  super ary unless ary.nil? 
  @recursivity = recursive
  @arity = arity
  @min_depth = min_depth
end

Instance Attribute Details

- (Object) arity

The RuleAlt arity used in Validator.analyze_arity process (see). ‘arity’ is the number of tokens with type == :symbol in the RuleAlt



97
98
99
# File '../lib/grammar.rb', line 97

def arity
  @arity
end

- (Object) min_depth

The RuleAlt min_depth used in Validator.analyze_min_depth process (see).


 This is a minimal number of mapping steps required by the generator to finish the mapping process.


101
102
103
# File '../lib/grammar.rb', line 101

def min_depth
  @min_depth
end

- (Object) recursivity

The RuleAlt recursivity used in Validator.analyze_recursivity process (see), based on nonterminal :symbol-ic Token-s. Allowed values are:


  :infinite ... the RuleAlt contains at least one :infinite :symbol, 
  :cyclic ... the RuleAlt contains no :infinite symbol and contains at least one :cyclic :symbol, 
  :terminating .. the RuleAlt does not contain :infinite nor :cyclic :symbol-s (ie. contains only :literal-s).


93
94
95
# File '../lib/grammar.rb', line 93

def recursivity
  @recursivity
end

Instance Method Details

- (Object) deep_copy

Return a deep copy of the instance.



82
83
84
85
# File '../lib/grammar.rb', line 82

def deep_copy
  alt = map {|t| Token.new( t.type, t.data, t.depth ) } 
  RuleAlt.new( alt, @recursivity, @arity, @min_depth )
end