Sha256: fd38a823af2ef2900b8daa1e07180a9c94ca9839f1c8d64fbcf81e1b965016df

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

module Tcl
  module Ruby
    class Interpreter
      private

      def ___llength(arg)
        raise(CommandError, 'llength list') if arg.size != 1
        parse(arg[0], true).size
      end

      def ___list(arg)
        arg.join(' ').to_s
      end

      def ___lindex(arg)
        if arg[1].nil?
          arg[0]
        elsif arg[1] == ''
          arg[0]
        else
          l = arg[0]
          arg[1..-1].each do |as|
            parse(as, true).each do |a|
              l = parse(l, true)
              a.gsub!(/end/, (l.size - 1).to_s)
              pos = eval(a)
              if (0...l.size).cover?(pos)
                l = l[pos]
              else
                return ''
              end
            end
          end
          l
        end
      end

      def ___join(arg)
        raise(CommandError, 'join list joinString?') unless (1..2).cover? arg.size
        separator = arg[1] || ' '
        parse(arg[0], true).join(separator)
      end

      def ___linsert(arg)
        raise(CommandError, 'linsert list insertposition elements') unless arg.size >= 3
        l = parse(arg[0], true)
        l.insert(arg[1].to_i, *arg[2..-1])
        # "{#{l.join(' ')}}"
        l.to_list
      end

      def ___lrange(arg)
        raise(CommandError, 'lrange list first last') unless arg.size == 3
        first = arg[1].to_i
        first = 0 if first < 0
        last = arg[2].to_i
        l = parse(arg[0], true)
        if first <= last
          l[first..last].to_list
        else
          ''
        end
      end

      def ___lappend(arg)
        l = parse(variables(arg[0]), true)
        l.push(*arg[1..-1])
        @variables[arg[0]] = l.to_list
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tcl-ruby-0.1.0 lib/tcl/ruby/commands/list.rb