Class: Rley::Syntax::SymbolSeq

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rley/syntax/symbol_seq.rb

Overview

A symbol sequence is a suite of grammar symbols

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theSymbols) ⇒ SymbolSeq

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

Parameters:

  • theSymbols (Array<GrmSymbol>)

    An array of symbols.



18
19
20
# File 'lib/rley/syntax/symbol_seq.rb', line 18

def initialize(theSymbols)
  @members = theSymbols.dup
end

Instance Attribute Details

#membersArray<GrmSymbol> (readonly)

Returns The sequence of symbols.

Returns:

  • (Array<GrmSymbol>)

    The sequence of symbols



13
14
15
# File 'lib/rley/syntax/symbol_seq.rb', line 13

def members
  @members
end

Instance Method Details

#==(other) ⇒ Boolean

Equality operator.

Parameters:

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rley/syntax/symbol_seq.rb', line 25

def ==(other)
  return true if equal?(other)

  case other
    when SymbolSeq then result = other.members == members
    when Array then result = other == members
    else
      msg = "Cannot compare a SymbolSeq with a #{other.class}"
      raise StandardError, msg
  end

  return result
end

#inspectString

Returns a string containing a human-readable representation of the sequence of symbols.

Returns:

  • (String)


42
43
44
45
46
47
# File 'lib/rley/syntax/symbol_seq.rb', line 42

def inspect()
  result = +"#<#{self.class.name}:#{object_id}"
  symbol_names = members.map(&:name)
  result << " @members=#{symbol_names}>"
  return result
end