class Ascode::Parser::Literal

Attributes

length[R]

Public Class Methods

new(code, literal_begin) click to toggle source
# File lib/ascode/parser/literal.rb, line 8
def initialize(code, literal_begin)
  @code = code
  @begin = literal_begin
end

Public Instance Methods

ast() click to toggle source
# File lib/ascode/parser/literal.rb, line 39
def ast
  @ast = {
    action: "push",
    what: @literal
  }
end
find_end() click to toggle source
# File lib/ascode/parser/literal.rb, line 26
def find_end
  escape = false
  @literal.split("").each_with_index do |char, index|
    if @quoted
      return index if char == '"' && !escape
      escape = char == "\\"
    else
      return index unless char =~ /[0-9.]/
    end
  end
  -1
end
parse() click to toggle source
# File lib/ascode/parser/literal.rb, line 13
def parse
  @quoted = @code[@begin] == '"'
  @begin += 1 if @quoted
  @literal = @code[@begin..-1]

  @end = find_end
  @literal = @literal[0..(@end - 1)]

  @literal = Converter.convert @literal
  @length = @literal.to_s.length + (@quoted ? 1 : -1)
  ast
end