Class: Ibex::IR::GrammarSymbol

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/ir/grammar_ir.rb

Overview

An interned terminal or nonterminal.

Instance Attribute Summary collapse

Instance Method Summary collapse

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_nameObject (readonly)

: String?



30
31
32
# File 'lib/ibex/ir/grammar_ir.rb', line 30

def display_name
  @display_name
end

#documentationObject (readonly)

: String?



32
33
34
# File 'lib/ibex/ir/grammar_ir.rb', line 32

def documentation
  @documentation
end

#idObject (readonly)

: Integer



24
25
26
# File 'lib/ibex/ir/grammar_ir.rb', line 24

def id
  @id
end

#kindObject (readonly)

: Symbol



26
27
28
# File 'lib/ibex/ir/grammar_ir.rb', line 26

def kind
  @kind
end

#locationObject (readonly)

: location?



29
30
31
# File 'lib/ibex/ir/grammar_ir.rb', line 29

def location
  @location
end

#nameObject (readonly)

: String



25
26
27
# File 'lib/ibex/ir/grammar_ir.rb', line 25

def name
  @name
end

#precedenceObject (readonly)

: precedence?



28
29
30
# File 'lib/ibex/ir/grammar_ir.rb', line 28

def precedence
  @precedence
end

#reservedObject (readonly)

: bool



27
28
29
# File 'lib/ibex/ir/grammar_ir.rb', line 27

def reserved
  @reserved
end

#semantic_typeObject (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

Returns:

  • (Boolean)


53
# File 'lib/ibex/ir/grammar_ir.rb', line 53

def nonterminal? = @kind == :nonterminal

#terminal?Boolean

Returns:

  • (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