Sha256: 7a1e02efd915304dfee4b5cfd879bfbce8a63f663e35a3592e9d080b859fa01c

Contents?: true

Size: 847 Bytes

Versions: 4

Compression:

Stored size: 847 Bytes

Contents

require 'pry'

# automatically create a token stream from bare values
def token_stream(*args)
  args.map do |value|
    type = type_for(value)
    Dentaku::Token.new(type, value)
  end
end

# make a (hopefully intelligent) guess about type
def type_for(value)
  case value
  when Numeric
    :numeric
  when String
    :string
  when true, false
    :logical
  when :add, :subtract, :multiply, :divide, :mod, :pow
    :operator
  when :open, :close, :comma
    :grouping
  when :le, :ge, :ne, :ne, :lt, :gt, :eq
    :comparator
  when :and, :or
    :combinator
  when :if, :round, :roundup, :rounddown, :not
    :function
  else
    :identifier
  end
end

def identifier(name)
  Dentaku::AST::Identifier.new(Dentaku::Token.new(:identifier, name))
end

def literal(value)
  Dentaku::AST::Literal.new(Dentaku::Token.new(type_for(value), value))
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dentaku-2.0.11 spec/spec_helper.rb
dentaku-2.0.10 spec/spec_helper.rb
dentaku-2.0.9 spec/spec_helper.rb
dentaku-2.0.8 spec/spec_helper.rb