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.
27 28 29 30 |
# File 'lib/edn-abnf.rb', line 27 def initialize(ast_) @ast = ast_ @tree = ast.ast end |
Instance Attribute Details
#ast ⇒ Object
Returns the value of attribute ast.
26 27 28 |
# File 'lib/edn-abnf.rb', line 26 def ast @ast end |
#tree ⇒ Object
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_clone ⇒ Object
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 |