Class: EDN
- Inherits:
-
Object
- Object
- EDN
- Defined in:
- lib/edn-abnf.rb
Constant Summary collapse
- @@parser =
EDNGRAMMARParser.new
Instance Attribute Summary collapse
-
#ast ⇒ Object
Returns the value of attribute ast.
-
#tree ⇒ Object
Returns the value of attribute tree.
Class Method Summary collapse
Instance Method Summary collapse
- #deep_clone ⇒ Object
-
#initialize(ast_) ⇒ EDN
constructor
A new instance of EDN.
- #warn_error(s) ⇒ Object
Constructor Details
#initialize(ast_) ⇒ EDN
Returns a new instance of EDN.
28 29 30 31 |
# File 'lib/edn-abnf.rb', line 28 def initialize(ast_) @ast = ast_ @tree = ast.ast end |
Instance Attribute Details
#ast ⇒ Object
Returns the value of attribute ast.
27 28 29 |
# File 'lib/edn-abnf.rb', line 27 def ast @ast end |
#tree ⇒ Object
Returns the value of attribute tree.
27 28 29 |
# File 'lib/edn-abnf.rb', line 27 def tree @tree end |
Class Method Details
.from_edn(s) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/edn-abnf.rb', line 18 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
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/edn-abnf.rb', line 6 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_clone ⇒ Object
37 38 39 |
# File 'lib/edn-abnf.rb', line 37 def deep_clone Marshal.load(Marshal.dump(self)) end |
#warn_error(s) ⇒ Object
33 34 35 36 |
# File 'lib/edn-abnf.rb', line 33 def warn_error(s) warn s @error = true end |