Class: Yadriggy::StringLiteral

Inherits:
ASTnode
  • Object
show all
Defined in:
lib/yadriggy/ast.rb,
lib/yadriggy/ast_value.rb

Overview

String literal.

Instance Attribute Summary collapse

Attributes inherited from ASTnode

#parent, #usertype

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ASTnode

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

Constructor Details

#initialize(sexp) ⇒ StringLiteral

Returns a new instance of StringLiteral.



516
517
518
519
520
521
522
523
524
525
526
527
528
529
# File 'lib/yadriggy/ast.rb', line 516

def initialize(sexp)
  @value = case sexp[0]
             when :@CHAR
               eval(sexp[1])
             else # :@tstring_content
               if sexp[1] =~ /\n$/
                 sexp[1]    # maybe here document
               else
                 eval( "<<_YAD_STRING_\n#{sexp[1]}\n_YAD_STRING_\n").chop
               end
           end
  @line_no = sexp[2][0].to_i
  @column = sexp[2][1].to_i
end

Instance Attribute Details

#columnInteger (readonly)

Returns the column.

Returns:

  • (Integer)

    the column.



510
511
512
# File 'lib/yadriggy/ast.rb', line 510

def column
  @column
end

#line_noInteger (readonly)

Returns the line number.

Returns:

  • (Integer)

    the line number.



507
508
509
# File 'lib/yadriggy/ast.rb', line 507

def line_no
  @line_no
end

#valueString (readonly)

Returns the character string.

Returns:

  • (String)

    the character string.



504
505
506
# File 'lib/yadriggy/ast.rb', line 504

def value
  @value
end

Class Method Details

.normalize(node) ⇒ ASTnode

Returns the given AST. If it is a Yadriggy::StringInterpolation with a single element, it is converted into a single Yadriggy::StringLiteral.

Parameters:

Returns:



542
543
544
545
546
547
548
549
# File 'lib/yadriggy/ast.rb', line 542

def self.normalize(node)
  if node.class == StringInterpolation
    if node.contents.length == 1
      return node.contents[0]
    end
  end
  node
end

.tagsObject



512
513
514
# File 'lib/yadriggy/ast.rb', line 512

def self.tags()
  [:@tstring_content, :@CHAR]
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.



534
535
536
# File 'lib/yadriggy/ast.rb', line 534

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

#const_valueObject

This is defined by attr_reader. def value() @value end



288
# File 'lib/yadriggy/ast_value.rb', line 288

def const_value() value end