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.
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
#column ⇒ Integer (readonly)
Returns the column.
510 511 512 |
# File 'lib/yadriggy/ast.rb', line 510 def column @column end |
#line_no ⇒ Integer (readonly)
Returns the line number.
507 508 509 |
# File 'lib/yadriggy/ast.rb', line 507 def line_no @line_no end |
#value ⇒ String (readonly)
Returns 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.
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 |
.tags ⇒ Object
512 513 514 |
# File 'lib/yadriggy/ast.rb', line 512 def self.() [:@tstring_content, :@CHAR] end |
Instance Method Details
#accept(evaluator) ⇒ void
This method returns an undefined value.
A method for Visitor pattern.
534 535 536 |
# File 'lib/yadriggy/ast.rb', line 534 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 |