Class: Ibex::IR::GrammarSymbol
- Inherits:
-
Object
- Object
- Ibex::IR::GrammarSymbol
- Defined in:
- lib/ibex/ir/grammar_ir.rb
Overview
An interned terminal or nonterminal.
Instance Attribute Summary collapse
-
#display_name ⇒ Object
readonly
: String?.
-
#documentation ⇒ Object
readonly
: String?.
-
#id ⇒ Object
readonly
: Integer.
-
#kind ⇒ Object
readonly
: Symbol.
-
#location ⇒ Object
readonly
: location?.
-
#name ⇒ Object
readonly
: String.
-
#precedence ⇒ Object
readonly
: precedence?.
-
#reserved ⇒ Object
readonly
: bool.
-
#semantic_type ⇒ Object
readonly
: String?.
Instance Method Summary collapse
-
#initialize(id:, name:, kind:, reserved: false, precedence: nil, location: nil, display_name: nil, semantic_type: nil, documentation: nil) ⇒ GrammarSymbol
constructor
A new instance of GrammarSymbol.
- #nonterminal? ⇒ Boolean
- #terminal? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(id:, name:, kind:, reserved: false, precedence: nil, location: nil, display_name: nil, semantic_type: nil, documentation: nil) ⇒ GrammarSymbol
Returns a new instance of GrammarSymbol.
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ibex/ir/grammar_ir.rb', line 44 def initialize(id:, name:, kind:, reserved: false, precedence: nil, location: nil, display_name: nil, semantic_type: nil, documentation: nil) @id = id @name = name.dup.freeze @kind = kind.to_sym @reserved = reserved @precedence = IR.deep_freeze(precedence) @location = IR.deep_freeze(location) @display_name = display_name&.dup&.freeze @semantic_type = semantic_type&.dup&.freeze @documentation = documentation&.dup&.freeze freeze end |
Instance Attribute Details
#display_name ⇒ Object (readonly)
: String?
38 39 40 |
# File 'lib/ibex/ir/grammar_ir.rb', line 38 def display_name @display_name end |
#documentation ⇒ Object (readonly)
: String?
40 41 42 |
# File 'lib/ibex/ir/grammar_ir.rb', line 40 def documentation @documentation end |
#id ⇒ Object (readonly)
: Integer
32 33 34 |
# File 'lib/ibex/ir/grammar_ir.rb', line 32 def id @id end |
#kind ⇒ Object (readonly)
: Symbol
34 35 36 |
# File 'lib/ibex/ir/grammar_ir.rb', line 34 def kind @kind end |
#location ⇒ Object (readonly)
: location?
37 38 39 |
# File 'lib/ibex/ir/grammar_ir.rb', line 37 def location @location end |
#name ⇒ Object (readonly)
: String
33 34 35 |
# File 'lib/ibex/ir/grammar_ir.rb', line 33 def name @name end |
#precedence ⇒ Object (readonly)
: precedence?
36 37 38 |
# File 'lib/ibex/ir/grammar_ir.rb', line 36 def precedence @precedence end |
#reserved ⇒ Object (readonly)
: bool
35 36 37 |
# File 'lib/ibex/ir/grammar_ir.rb', line 35 def reserved @reserved end |
#semantic_type ⇒ Object (readonly)
: String?
39 40 41 |
# File 'lib/ibex/ir/grammar_ir.rb', line 39 def semantic_type @semantic_type end |
Instance Method Details
#nonterminal? ⇒ Boolean
61 |
# File 'lib/ibex/ir/grammar_ir.rb', line 61 def nonterminal? = @kind == :nonterminal |
#terminal? ⇒ Boolean
59 60 |
# File 'lib/ibex/ir/grammar_ir.rb', line 59 def terminal? = @kind == :terminal # @rbs () -> bool |
#to_h ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/ibex/ir/grammar_ir.rb', line 64 def to_h value = { id: @id, name: @name, kind: @kind, reserved: @reserved, prec: @precedence, loc: @location } #: Hash[Symbol, Object?] value[:display_name] = @display_name if @display_name value[:semantic_type] = @semantic_type if @semantic_type value[:doc] = @documentation value end |