Class: EDN

Inherits:
Object
  • Object
show all
Defined in:
lib/edn-abnf.rb

Constant Summary collapse

@@parser =
EDNGRAMMARParser.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast_) ⇒ EDN

Returns a new instance of EDN.



29
30
31
32
# File 'lib/edn-abnf.rb', line 29

def initialize(ast_)
  @ast = ast_
  @tree = ast.ast
end

Instance Attribute Details

#astObject

Returns the value of attribute ast.



28
29
30
# File 'lib/edn-abnf.rb', line 28

def ast
  @ast
end

#treeObject

Returns the value of attribute tree.



28
29
30
# File 'lib/edn-abnf.rb', line 28

def tree
  @tree
end

Class Method Details

.from_edn(s) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/edn-abnf.rb', line 19

def self.from_edn(s)
  ast = @@parser.parse s
  if !ast
    raise ArgumentError, "Parse Error:\n" << self.reason(@@parser, s)
  end
  ret = EDN.new(ast)
  ret
end

.reason(parser, s) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/edn-abnf.rb', line 7

def self.reason(parser, s)
  reason = [parser.failure_reason]
  parser.failure_reason =~ /^(Expected .+) after ./m
  expected = $1
  if line = s.lines.to_a[parser.failure_line - 1]
    reason << "#{$1.gsub("\n", '<<<NEWLINE>>>')}:" if expected
    reason << line
    reason << "#{'~' * (parser.failure_column - 1)}^"
  end
  reason.join("\n")
end

Instance Method Details

#deep_cloneObject



38
39
40
# File 'lib/edn-abnf.rb', line 38

def deep_clone
  Marshal.load(Marshal.dump(self))
end

#warn_error(s) ⇒ Object



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

def warn_error(s)
  warn s
  @error = true
end