Class: Dendroid::Syntax::SymbolSeq
- Inherits:
-
Object
- Object
- Dendroid::Syntax::SymbolSeq
- Extended by:
- Forwardable
- Defined in:
- lib/dendroid/syntax/symbol_seq.rb
Overview
A sequence of grammar symbols. This class is used to represent members of right-hand side of production rules
Instance Attribute Summary collapse
-
#members ⇒ Array<Dendroid::Syntax::GrmSymbol>
readonly
The sequence of symbols.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Equality operator.
-
#initialize(symbols) ⇒ SymbolSeq
constructor
Create a sequence of grammar symbols (as in right-hand side of a production rule).
-
#nonterminals ⇒ Array<Dendroid::Syntax::NonTerminal>
Retrieve all the non-terminal symbols in the sequence.
-
#productive? ⇒ Boolean
Predicate method to check whether the sequence always derives (matches) a non-empty sequence of terminal symbols.
-
#terminals ⇒ Array<Dendroid::Syntax::Terminal>
Retrieve all the terminal symbols in the sequence.
-
#to_s ⇒ String
A text representation of the symbol sequence.
Constructor Details
#initialize(symbols) ⇒ SymbolSeq
Create a sequence of grammar symbols (as in right-hand side of a production rule).
21 22 23 |
# File 'lib/dendroid/syntax/symbol_seq.rb', line 21 def initialize(symbols) @members = symbols end |
Instance Attribute Details
#members ⇒ Array<Dendroid::Syntax::GrmSymbol> (readonly)
Returns The sequence of symbols.
14 15 16 |
# File 'lib/dendroid/syntax/symbol_seq.rb', line 14 def members @members end |
Instance Method Details
#==(other) ⇒ Boolean
Equality operator.
52 53 54 |
# File 'lib/dendroid/syntax/symbol_seq.rb', line 52 def ==(other) members == other.members end |
#nonterminals ⇒ Array<Dendroid::Syntax::NonTerminal>
Retrieve all the non-terminal symbols in the sequence.
32 33 34 |
# File 'lib/dendroid/syntax/symbol_seq.rb', line 32 def nonterminals members.reject(&:terminal?) end |
#productive? ⇒ Boolean
Predicate method to check whether the sequence always derives (matches) a non-empty sequence of terminal symbols.
45 46 47 |
# File 'lib/dendroid/syntax/symbol_seq.rb', line 45 def productive? empty? || members.all?(&:productive?) end |
#terminals ⇒ Array<Dendroid::Syntax::Terminal>
Retrieve all the terminal symbols in the sequence.
38 39 40 |
# File 'lib/dendroid/syntax/symbol_seq.rb', line 38 def terminals members.select(&:terminal?) end |
#to_s ⇒ String
Returns A text representation of the symbol sequence.
26 27 28 |
# File 'lib/dendroid/syntax/symbol_seq.rb', line 26 def to_s members.join(' ') end |