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(schema_version: SCHEMA_VERSION) ⇒ 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.
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 ⇒ Object (readonly)
: String?
30 31 32 |
# File 'lib/ibex/ir/grammar_ir.rb', line 30 def display_name @display_name end |
#documentation ⇒ Object (readonly)
: String?
32 33 34 |
# File 'lib/ibex/ir/grammar_ir.rb', line 32 def documentation @documentation end |
#id ⇒ Object (readonly)
: Integer
24 25 26 |
# File 'lib/ibex/ir/grammar_ir.rb', line 24 def id @id end |
#kind ⇒ Object (readonly)
: Symbol
26 27 28 |
# File 'lib/ibex/ir/grammar_ir.rb', line 26 def kind @kind end |
#location ⇒ Object (readonly)
: location?
29 30 31 |
# File 'lib/ibex/ir/grammar_ir.rb', line 29 def location @location end |
#name ⇒ Object (readonly)
: String
25 26 27 |
# File 'lib/ibex/ir/grammar_ir.rb', line 25 def name @name end |
#precedence ⇒ Object (readonly)
: precedence?
28 29 30 |
# File 'lib/ibex/ir/grammar_ir.rb', line 28 def precedence @precedence end |
#reserved ⇒ Object (readonly)
: bool
27 28 29 |
# File 'lib/ibex/ir/grammar_ir.rb', line 27 def reserved @reserved end |
#semantic_type ⇒ Object (readonly)
: String?
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) ⇒ Object
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 |