Class: Yadriggy::SymbolLiteral

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

Overview

Symbol.

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_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) ⇒ SymbolLiteral

Returns a new instance of SymbolLiteral.



331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/yadriggy/ast.rb', line 331

def initialize(sexp)
  if sexp[0] == :dyna_symbol
    sexp2 = if sexp[1][0] == :string_content
              sexp[1][1]
             else
              sexp[1][0]
             end
    init(has_tag?(sexp2, :@tstring_content))
  elsif sexp[0] == :symbol_literal
    init(has_tag?(sexp[1], :symbol)[1])
  else
    init(has_tag?(sexp, :symbol)[1])
  end
end

Instance Attribute Details

#columnInteger (readonly)

Returns the column.

Returns:

  • (Integer)

    the column.



327
328
329
# File 'lib/yadriggy/ast.rb', line 327

def column
  @column
end

#line_noInteger (readonly)

Returns the line number.

Returns:

  • (Integer)

    the line number.



325
326
327
# File 'lib/yadriggy/ast.rb', line 325

def line_no
  @line_no
end

#nameString (readonly)

Returns the symbol name. For example, if the object represents :sym, then "sym" (without a colon) is returned.

Returns:

  • (String)

    the symbol name. For example, if the object represents :sym, then "sym" (without a colon) is returned.



323
324
325
# File 'lib/yadriggy/ast.rb', line 323

def name
  @name
end

Class Method Details

.tagsObject



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

def self.tags() [:symbol, :symbol_literal, :dyna_symbol] 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.



354
355
356
# File 'lib/yadriggy/ast.rb', line 354

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

#const_valueObject



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

def const_value() value end

#to_symSymbol

Returns a symbol the literal represents.

Returns:

  • (Symbol)

    a symbol the literal represents.



347
348
349
# File 'lib/yadriggy/ast.rb', line 347

def to_sym
  name.to_sym
end

#valueObject

Gets the symbol represented by this node.



293
294
295
# File 'lib/yadriggy/ast_value.rb', line 293

def value()
  name.to_sym
end