Class: Yadriggy::StringInterpolation

Inherits:
ASTnode
  • Object
show all
Includes:
AstHelper
Defined in:
lib/yadriggy/ast.rb

Overview

String interpolation.

Instance Attribute Summary collapse

Attributes inherited from ASTnode

#parent, #usertype

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AstHelper

#has_tag?, #to_node, #to_nodes

Methods inherited from ASTnode

#add_child, #add_children, #const_value, #const_value_in_class, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string, #value, #value_in_class

Constructor Details

#initialize(sexp) ⇒ StringInterpolation

Returns a new instance of StringInterpolation.



476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
# File 'lib/yadriggy/ast.rb', line 476

def initialize(sexp)
  s = has_tag?(sexp[1], :string_content)
  elements = s[1..s.length]
  @contents = elements.map do |e|
    case e[0]
    when :string_embexpr
      Exprs.make(e[1])
    when :@tstring_content
      StringLiteral.new(e)
    else
      raise "unknown string contents #{e[0]}"
    end
  end
  add_children(@contents)
end

Instance Attribute Details

#contentsArray<ASTnode> (readonly)

Returns the strings and the embedded expressions.

Returns:

  • (Array<ASTnode>)

    the strings and the embedded expressions.



472
473
474
# File 'lib/yadriggy/ast.rb', line 472

def contents
  @contents
end

Class Method Details

.tagObject



474
# File 'lib/yadriggy/ast.rb', line 474

def self.tag() :string_literal end

Instance Method Details

#accept(evaluator) ⇒ void

This method returns an undefined value.

A method for Visitor pattern.

Parameters:

  • evaluator (Eval)

    the visitor of Visitor pattern.



495
496
497
# File 'lib/yadriggy/ast.rb', line 495

def accept(evaluator)
  evaluator.string_interpolation(self)
end