Class: Lrama::Grammar::Code

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/lrama/grammar/code.rb,
lib/lrama/grammar/code/rule_action.rb,
lib/lrama/grammar/code/printer_code.rb,
lib/lrama/grammar/code/destructor_code.rb,
lib/lrama/grammar/code/no_reference_code.rb,
lib/lrama/grammar/code/initial_action_code.rb

Defined Under Namespace

Classes: DestructorCode, InitialActionCode, NoReferenceCode, PrinterCode, RuleAction

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, token_code:) ⇒ Code

Returns a new instance of Code.



19
20
21
22
# File 'lib/lrama/grammar/code.rb', line 19

def initialize(type:, token_code:)
  @type = type
  @token_code = token_code
end

Instance Attribute Details

#token_codeObject (readonly)

Returns the value of attribute token_code.



17
18
19
# File 'lib/lrama/grammar/code.rb', line 17

def token_code
  @token_code
end

#typeObject (readonly)

Returns the value of attribute type.



17
18
19
# File 'lib/lrama/grammar/code.rb', line 17

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



24
25
26
27
28
# File 'lib/lrama/grammar/code.rb', line 24

def ==(other)
  self.class == other.class &&
  self.type == other.type &&
  self.token_code == other.token_code
end

#translated_codeObject

$$, $n, @$, @n are translated to C code



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lrama/grammar/code.rb', line 31

def translated_code
  t_code = s_value.dup

  references.reverse_each do |ref|
    first_column = ref.first_column
    last_column = ref.last_column

    str = reference_to_c(ref)

    t_code[first_column...last_column] = str
  end

  return t_code
end