Class: Lrama::Grammar::Code
- Inherits:
-
Object
- Object
- Lrama::Grammar::Code
- 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
Direct Known Subclasses
DestructorCode, InitialActionCode, NoReferenceCode, PrinterCode, RuleAction
Defined Under Namespace
Classes: DestructorCode, InitialActionCode, NoReferenceCode, PrinterCode, RuleAction
Instance Attribute Summary collapse
-
#token_code ⇒ Object
readonly
: Lexer::Token::UserCode.
-
#type ⇒ Object
readonly
: ::Symbol.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(type:, token_code:) ⇒ Code
constructor
A new instance of Code.
-
#translated_code ⇒ Object
$$, $n, @$, @n are translated to C code.
Constructor Details
#initialize(type:, token_code:) ⇒ Code
Returns a new instance of Code.
30 31 32 33 |
# File 'lib/lrama/grammar/code.rb', line 30 def initialize(type:, token_code:) @type = type @token_code = token_code end |
Instance Attribute Details
#token_code ⇒ Object (readonly)
: Lexer::Token::UserCode
27 28 29 |
# File 'lib/lrama/grammar/code.rb', line 27 def token_code @token_code end |
#type ⇒ Object (readonly)
: ::Symbol
26 27 28 |
# File 'lib/lrama/grammar/code.rb', line 26 def type @type end |
Instance Method Details
#==(other) ⇒ Object
36 37 38 39 40 |
# File 'lib/lrama/grammar/code.rb', line 36 def ==(other) self.class == other.class && self.type == other.type && self.token_code == other.token_code end |
#translated_code ⇒ Object
$$, $n, @$, @n are translated to C code
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lrama/grammar/code.rb', line 45 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 |