Class: Foxtail::Syntax::Parser::AST::NumberLiteral

Inherits:
BaseLiteral show all
Defined in:
lib/foxtail/syntax/parser/ast/number_literal.rb

Overview

Represents numeric literals (integers and floats)

Instance Attribute Summary

Attributes inherited from BaseLiteral

#value

Attributes inherited from SyntaxNode

#span

Attributes inherited from BaseNode

#type

Instance Method Summary collapse

Methods inherited from BaseLiteral

#initialize

Methods inherited from SyntaxNode

#add_span

Methods inherited from BaseNode

#==, #accept, #children, #initialize, #to_h

Constructor Details

This class inherits a constructor from Foxtail::Syntax::Parser::AST::BaseLiteral

Instance Method Details

#parseHash

Parse the number literal value and return as a Hash

Returns:

  • (Hash)

    Hash containing the parsed numeric value



11
12
13
14
15
16
17
18
19
# File 'lib/foxtail/syntax/parser/ast/number_literal.rb', line 11

def parse
  value_str = @value

  if value_str.include?(".")
    {value: Float(value_str)}
  else
    {value: Integer(value_str, 10)}
  end
end