Class: Yadriggy::StringLiteral
- Defined in:
- lib/yadriggy/ast.rb,
lib/yadriggy/ast_value.rb
Overview
String literal.
Instance Attribute Summary collapse
-
#column ⇒ Integer
readonly
The column.
-
#line_no ⇒ Integer
readonly
The line number.
-
#value ⇒ String
readonly
The character string.
Attributes inherited from ASTnode
Class Method Summary collapse
-
.normalize(node) ⇒ ASTnode
The given AST.
- .tags ⇒ Object
Instance Method Summary collapse
-
#accept(evaluator) ⇒ void
A method for Visitor pattern.
-
#const_value ⇒ Object
This is defined by attr_reader.
-
#initialize(sexp) ⇒ StringLiteral
constructor
A new instance of StringLiteral.
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.
491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/yadriggy/ast.rb', line 491 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
#column ⇒ Integer (readonly)
Returns the column.
485 486 487 |
# File 'lib/yadriggy/ast.rb', line 485 def column @column end |
#line_no ⇒ Integer (readonly)
Returns the line number.
482 483 484 |
# File 'lib/yadriggy/ast.rb', line 482 def line_no @line_no end |
#value ⇒ String (readonly)
Returns the character string.
479 480 481 |
# File 'lib/yadriggy/ast.rb', line 479 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.
517 518 519 520 521 522 523 524 |
# File 'lib/yadriggy/ast.rb', line 517 def self.normalize(node) if node.class == StringInterpolation if node.contents.length == 1 return node.contents[0] end end node end |
.tags ⇒ Object
487 488 489 |
# File 'lib/yadriggy/ast.rb', line 487 def self.() [:@tstring_content, :@CHAR] end |
Instance Method Details
#accept(evaluator) ⇒ void
This method returns an undefined value.
A method for Visitor pattern.
509 510 511 |
# File 'lib/yadriggy/ast.rb', line 509 def accept(evaluator) evaluator.string_literal(self) end |
#const_value ⇒ Object
This is defined by attr_reader. def value() @value end
288 |
# File 'lib/yadriggy/ast_value.rb', line 288 def const_value() value end |