Module: EDN

Defined in:
lib/edn.rb,
lib/edn/parser.rb,
lib/edn/reader.rb,
lib/edn/version.rb,
lib/edn/core_ext.rb,
lib/edn/metadata.rb,
lib/edn/type/list.rb,
lib/edn/type/uuid.rb,
lib/edn/char_stream.rb,
lib/edn/type/symbol.rb,
lib/edn/type/unknown.rb,
lib/edn/ruby_edn_parser.rb

Defined Under Namespace

Modules: CoreExt, Metadata, Type Classes: CharStream, Reader, RubyEdnParser

Constant Summary collapse

Parser =
RubyEdnParser
NOTHING =

Object returned when there is nothing to return

Object.new
EOF =

Object to return when we hit end of file. Cant be nil or :eof because either of those could be something in the EDN data.

Object.new
READERS =

Reader table

{}
SYMBOL_INTERIOR_CHARS =
Set.new(%w{. # * ! - _ + ? $ % & = < > :} + ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a)
DIGITS =
Set.new(('0'..'9').to_a)
TAGS =
{}
VERSION =
"1.1.1"

Class Method Summary collapse

Class Method Details

.big_decimal(str) ⇒ Object


64
65
66
# File 'lib/edn.rb', line 64

def self.big_decimal(str)
  BigDecimal.new(str)
end

.list(values) ⇒ Object


56
57
58
# File 'lib/edn.rb', line 56

def self.list(values)
  EDN::Type::List.new(*values)
end

.new_parser(*args) ⇒ Object


13
14
15
# File 'lib/edn/parser.rb', line 13

def self.new_parser(*args)
  @parser_class.new(*args)
end

.parser=(p) ⇒ Object


9
10
11
# File 'lib/edn/parser.rb', line 9

def self.parser=(p)
  @parser_class = p
end

.read(edn, eof_value = NOTHING) ⇒ Object


15
16
17
# File 'lib/edn.rb', line 15

def self.read(edn, eof_value=NOTHING)
  EDN::Reader.new(edn).read(eof_value)
end

.register(tag, func = nil, &block) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/edn.rb', line 19

def self.register(tag, func = nil, &block)
  if block_given?
    func = block
  end

  if func.nil?
    func = lambda { |x| x }
  end

  if func.is_a?(Class)
    @tags[tag] = lambda { |*args| func.new(*args) }
  else
    @tags[tag] = func
  end
end

.register_reader(ch, handler = nil, &block) ⇒ Object


54
55
56
57
58
59
60
# File 'lib/edn/parser.rb', line 54

def self.register_reader(ch, handler=nil, &block)
  if handler
    READERS[ch] = handler
  else
    READERS[ch] = block
  end
end

.set(*elems) ⇒ Object


60
61
62
# File 'lib/edn.rb', line 60

def self.set(*elems)
  Set.new(*elems)
end

.symbol(text) ⇒ Object


52
53
54
# File 'lib/edn.rb', line 52

def self.symbol(text)
  EDN::Type::Symbol.new(text)
end

.tagged_element(tag, element) ⇒ Object


39
40
41
42
43
44
45
46
# File 'lib/edn.rb', line 39

def self.tagged_element(tag, element)
  func = @tags[tag]
  if func
    func.call(element)
  else
    EDN::Type::Unknown.new(tag, element)
  end
end

.tagout(tag, element) ⇒ Object


48
49
50
# File 'lib/edn.rb', line 48

def self.tagout(tag, element)
  ["##{tag}", element.to_edn].join(" ")
end

.unregister(tag) ⇒ Object


35
36
37
# File 'lib/edn.rb', line 35

def self.unregister(tag)
  @tags[tag] = nil
end