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(schema_version: SCHEMA_VERSION) ⇒ Hash[Symbol, untyped]
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.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ibex/ir/grammar_ir.rb', line 36 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)
30 31 32 |
# File 'lib/ibex/ir/grammar_ir.rb', line 30 def display_name @display_name end |
#documentation ⇒ String? (readonly)
32 33 34 |
# File 'lib/ibex/ir/grammar_ir.rb', line 32 def documentation @documentation end |
#id ⇒ Integer (readonly)
24 25 26 |
# File 'lib/ibex/ir/grammar_ir.rb', line 24 def id @id end |
#kind ⇒ Symbol (readonly)
26 27 28 |
# File 'lib/ibex/ir/grammar_ir.rb', line 26 def kind @kind end |
#location ⇒ location? (readonly)
29 30 31 |
# File 'lib/ibex/ir/grammar_ir.rb', line 29 def location @location end |
#name ⇒ String (readonly)
25 26 27 |
# File 'lib/ibex/ir/grammar_ir.rb', line 25 def name @name end |
#precedence ⇒ precedence? (readonly)
28 29 30 |
# File 'lib/ibex/ir/grammar_ir.rb', line 28 def precedence @precedence end |
#reserved ⇒ Boolean (readonly)
27 28 29 |
# File 'lib/ibex/ir/grammar_ir.rb', line 27 def reserved @reserved end |
#semantic_type ⇒ String? (readonly)
31 32 33 |
# File 'lib/ibex/ir/grammar_ir.rb', line 31 def semantic_type @semantic_type end |
Instance Method Details
#nonterminal? ⇒ Boolean
53 |
# File 'lib/ibex/ir/grammar_ir.rb', line 53 def nonterminal? = @kind == :nonterminal |
#terminal? ⇒ Boolean
51 52 |
# File 'lib/ibex/ir/grammar_ir.rb', line 51 def terminal? = @kind == :terminal # @rbs () -> bool |
#to_h(schema_version: SCHEMA_VERSION) ⇒ Hash[Symbol, untyped]
56 57 58 59 60 61 62 63 |
# File 'lib/ibex/ir/grammar_ir.rb', line 56 def to_h(schema_version: SCHEMA_VERSION) value = { id: @id, name: @name, kind: @kind, reserved: @reserved, prec: @precedence, loc: @location } #: Hash[Symbol, untyped] value[:display_name] = @display_name if @display_name value[:semantic_type] = @semantic_type if @semantic_type value[:doc] = @documentation if schema_version >= 2 value end |