Class: Rley::Syntax::GrmSymbol
- Inherits:
-
Object
- Object
- Rley::Syntax::GrmSymbol
- 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
Instance Attribute Summary collapse
-
#generative ⇒ Object
writeonly
An indicator that tells whether the grammar symbol can generate a non-empty string of terminals.
-
#name ⇒ String
readonly
The name of the grammar symbol.
Instance Method Summary collapse
-
#generative? ⇒ Boolean
True iff the symbol is generative.
-
#initialize(aName) ⇒ GrmSymbol
constructor
Constructor.
-
#terminal? ⇒ Boolean
True iff the symbol is a terminal.
-
#to_s ⇒ String
The String representation of the grammar symbol.
Constructor Details
#initialize(aName) ⇒ GrmSymbol
Constructor. aName [String] The name of the grammar symbol.
17 18 19 20 21 22 |
# File 'lib/rley/syntax/grm_symbol.rb', line 17 def initialize(aName) raise 'Internal error: nil name encountered' if aName.nil? @name = aName.dup @name.freeze end |
Instance Attribute Details
#generative=(value) ⇒ Object (writeonly)
An indicator that tells whether the grammar symbol can generate a non-empty string of terminals.
13 14 15 |
# File 'lib/rley/syntax/grm_symbol.rb', line 13 def generative=(value) @generative = value end |
#name ⇒ String (readonly)
Returns 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.
37 38 39 |
# File 'lib/rley/syntax/grm_symbol.rb', line 37 def generative? @generative end |
#terminal? ⇒ Boolean
Returns true iff the symbol is a terminal.
31 32 33 34 |
# File 'lib/rley/syntax/grm_symbol.rb', line 31 def terminal? # Default implementation to override if necessary false end |
#to_s ⇒ String
The String representation of the grammar symbol
26 27 28 |
# File 'lib/rley/syntax/grm_symbol.rb', line 26 def to_s name.to_s end |