Class: Ibex::IR::GrammarSymbol
- Inherits:
-
Object
- Object
- Ibex::IR::GrammarSymbol
- Defined in:
- lib/ibex/ir/grammar_ir.rb,
sig/ibex/ir/grammar_ir.rbs
Overview
An interned terminal or nonterminal.
Instance Attribute Summary collapse
- #display_name ⇒ String? readonly
- #documentation ⇒ String? readonly
- #id ⇒ Integer readonly
- #kind ⇒ Symbol readonly
- #location ⇒ location? readonly
- #name ⇒ String readonly
- #precedence ⇒ precedence? readonly
- #reserved ⇒ Boolean readonly
- #semantic_type ⇒ String? readonly
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 ⇒ Hash[Symbol, 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.
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ibex/ir/grammar_ir.rb', line 41 def initialize(id:, name:, kind:, reserved: false, precedence: nil, location: nil, display_name: nil, semantic_type: nil, documentation: nil) @id = id @name = name.freeze @kind = kind.to_sym @reserved = reserved @precedence = IR.deep_freeze(precedence) @location = IR.deep_freeze(location) @display_name = display_name&.freeze @semantic_type = semantic_type&.freeze @documentation = documentation&.freeze freeze end |
Instance Attribute Details
#display_name ⇒ String? (readonly)
35 36 37 |
# File 'lib/ibex/ir/grammar_ir.rb', line 35 def display_name @display_name end |
#documentation ⇒ String? (readonly)
37 38 39 |
# File 'lib/ibex/ir/grammar_ir.rb', line 37 def documentation @documentation end |
#id ⇒ Integer (readonly)
29 30 31 |
# File 'lib/ibex/ir/grammar_ir.rb', line 29 def id @id end |
#kind ⇒ Symbol (readonly)
31 32 33 |
# File 'lib/ibex/ir/grammar_ir.rb', line 31 def kind @kind end |
#location ⇒ location? (readonly)
34 35 36 |
# File 'lib/ibex/ir/grammar_ir.rb', line 34 def location @location end |
#name ⇒ String (readonly)
30 31 32 |
# File 'lib/ibex/ir/grammar_ir.rb', line 30 def name @name end |
#precedence ⇒ precedence? (readonly)
33 34 35 |
# File 'lib/ibex/ir/grammar_ir.rb', line 33 def precedence @precedence end |
#reserved ⇒ Boolean (readonly)
32 33 34 |
# File 'lib/ibex/ir/grammar_ir.rb', line 32 def reserved @reserved end |
#semantic_type ⇒ String? (readonly)
36 37 38 |
# File 'lib/ibex/ir/grammar_ir.rb', line 36 def semantic_type @semantic_type end |
Instance Method Details
#nonterminal? ⇒ Boolean
58 |
# File 'lib/ibex/ir/grammar_ir.rb', line 58 def nonterminal? = @kind == :nonterminal |
#terminal? ⇒ Boolean
56 57 |
# File 'lib/ibex/ir/grammar_ir.rb', line 56 def terminal? = @kind == :terminal # @rbs () -> bool |
#to_h ⇒ Hash[Symbol, Object?]
61 62 63 64 65 66 67 68 |
# File 'lib/ibex/ir/grammar_ir.rb', line 61 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 |