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.



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

: String?



38
39
40
# File 'lib/ibex/ir/grammar_ir.rb', line 38

def display_name
  @display_name
end

#documentationObject (readonly)

: String?



40
41
42
# File 'lib/ibex/ir/grammar_ir.rb', line 40

def documentation
  @documentation
end

#idObject (readonly)

: Integer



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

def id
  @id
end

#kindObject (readonly)

: Symbol



34
35
36
# File 'lib/ibex/ir/grammar_ir.rb', line 34

def kind
  @kind
end

#locationObject (readonly)

: location?



37
38
39
# File 'lib/ibex/ir/grammar_ir.rb', line 37

def location
  @location
end

#nameObject (readonly)

: String



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

def name
  @name
end

#precedenceObject (readonly)

: precedence?



36
37
38
# File 'lib/ibex/ir/grammar_ir.rb', line 36

def precedence
  @precedence
end

#reservedObject (readonly)

: bool



35
36
37
# File 'lib/ibex/ir/grammar_ir.rb', line 35

def reserved
  @reserved
end

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

Returns:

  • (Boolean)


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

def nonterminal? = @kind == :nonterminal

#terminal?Boolean

Returns:

  • (Boolean)


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

def terminal? = @kind == :terminal
# @rbs () -> bool

#to_hObject



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