Class: Rley::Syntax::GrmSymbol

Inherits:
Object
  • Object
show all
Defined in:
lib/rley/syntax/grm_symbol.rb

Overview

Abstract class for grammar symbols. A grammar symbol is an element that appears in grammar rules.

Direct Known Subclasses

NonTerminal, Terminal

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aName) ⇒ GrmSymbol

Constructor. aName [String] The name of the grammar symbol.



13
14
15
16
17
18
# File 'lib/rley/syntax/grm_symbol.rb', line 13

def initialize(aName)
  raise 'Internal error: nil name encountered' if aName.nil?

  @name = aName.dup
  @name.freeze
end

Instance Attribute Details

#nameString (readonly)

Returns The name of the grammar symbol.

Returns:

  • (String)

    The name of the grammar symbol



9
10
11
# File 'lib/rley/syntax/grm_symbol.rb', line 9

def name
  @name
end

Instance Method Details

#generative?Boolean

Returns true iff the symbol is generative.

Returns:

  • (Boolean)

    true iff the symbol is generative.



33
34
35
# File 'lib/rley/syntax/grm_symbol.rb', line 33

def generative?
  @generative
end

#terminal?Boolean

Returns true iff the symbol is a terminal.

Returns:

  • (Boolean)

    true iff the symbol is a terminal



27
28
29
30
# File 'lib/rley/syntax/grm_symbol.rb', line 27

def terminal?
  # Default implementation to override if necessary
  false
end

#to_sString

The String representation of the grammar symbol

Returns:

  • (String)


22
23
24
# File 'lib/rley/syntax/grm_symbol.rb', line 22

def to_s
  name.to_s
end