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.



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

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

Instance Attribute Details

#astObject

Returns the value of attribute ast.



26
27
28
# File 'lib/edn-abnf.rb', line 26

def ast
  @ast
end

#treeObject

Returns the value of attribute tree.



26
27
28
# File 'lib/edn-abnf.rb', line 26

def tree
  @tree
end

Class Method Details

.from_edn(s) ⇒ Object



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

def self.from_edn(s)
  ast = @@parser.parse s
  if !ast
    fail self.reason(@@parser, s)
  end
  ret = EDN.new(ast)
  ret
end

.reason(parser, s) ⇒ Object



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

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

Instance Method Details

#deep_cloneObject



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

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

#warn_error(s) ⇒ Object



32
33
34
35
# File 'lib/edn-abnf.rb', line 32

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