Class: Dendroid::Syntax::SymbolSeq

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(symbols) ⇒ SymbolSeq

Create a sequence of grammar symbols (as in right-hand side of a production rule).

Parameters:



21
22
23
# File 'lib/dendroid/syntax/symbol_seq.rb', line 21

def initialize(symbols)
  @members = symbols
end

Instance Attribute Details

#membersArray<Dendroid::Syntax::GrmSymbol> (readonly)

Returns The sequence of symbols.

Returns:



14
15
16
# File 'lib/dendroid/syntax/symbol_seq.rb', line 14

def members
  @members
end

Instance Method Details

#==(other) ⇒ Boolean

Equality operator.

Parameters:

Returns:

  • (Boolean)

    true when members are equal to the ones from ‘other`



52
53
54
# File 'lib/dendroid/syntax/symbol_seq.rb', line 52

def ==(other)
  members == other.members
end

#nonterminalsArray<Dendroid::Syntax::NonTerminal>

Retrieve all the non-terminal symbols in the sequence.

Returns:



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.

Returns:

  • (Boolean)


45
46
47
# File 'lib/dendroid/syntax/symbol_seq.rb', line 45

def productive?
  empty? || members.all?(&:productive?)
end

#terminalsArray<Dendroid::Syntax::Terminal>

Retrieve all the terminal symbols in the sequence.

Returns:



38
39
40
# File 'lib/dendroid/syntax/symbol_seq.rb', line 38

def terminals
  members.select(&:terminal?)
end

#to_sString

Returns A text representation of the symbol sequence.

Returns:

  • (String)

    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