Sha256: b9a4aa5a489a78593b2b7f7110281502645853eac4daa995dc9146a91d2d6905

Contents?: true

Size: 700 Bytes

Versions: 1

Compression:

Stored size: 700 Bytes

Contents

module AsciiMath
  class SymbolTableBuilder
    def initialize(allow_symbol_overwrites: true)
      @table = {}
      @allow_symbol_overwrites = allow_symbol_overwrites
    end

    def add(*args)
      raise 'Insufficient arguments' if args.length < 3

      entry = {}
      if args.last.is_a?(Hash)
        entry.merge!(args.pop)
      end
      entry[:type] = args.pop
      entry[:value] = args.pop

      entry.freeze
      args.map(&:freeze).each do |name|
        raise "Symbol overwrites are disallowed, but were attempted for #{name}" if !@allow_symbol_overwrites && !@table[name].nil?

        @table[name] = entry
      end
    end

    def build
      @table.dup.freeze
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
asciimath-2.0.5 lib/asciimath/symbol_table.rb