edn-abnf-ec 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/edn-abnf-ec +109 -0
- data/edn-abnf.gemspec +21 -0
- data/lib/cbor-diagnostic-app/b64.rb +22 -0
- data/lib/cbor-diagnostic-app/b64grammar.rb +677 -0
- data/lib/cbor-diagnostic-app/dt.rb +33 -0
- data/lib/cbor-diagnostic-app/dtgrammar.rb +700 -0
- data/lib/cbor-diagnostic-app/h.rb +13 -0
- data/lib/cbor-diagnostic-app/hgrammar.rb +771 -0
- data/lib/cbor-diagnostic-app/ip.rb +21 -0
- data/lib/cbor-diagnostic-app/ipgrammar.rb +1698 -0
- data/lib/edn-abnf.rb +42 -0
- data/lib/parser/edn-util.rb +24 -0
- data/lib/parser/edngrammar.rb +4708 -0
- metadata +127 -0
data/lib/edn-abnf.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative "parser/edn-util.rb"
|
2
|
+
|
3
|
+
class EDN
|
4
|
+
@@parser = EDNGRAMMARParser.new
|
5
|
+
|
6
|
+
def self.reason(parser, s)
|
7
|
+
reason = [parser.failure_reason]
|
8
|
+
parser.failure_reason =~ /^(Expected .+) after ./m
|
9
|
+
expected = $1
|
10
|
+
if line = s.lines.to_a[parser.failure_line - 1]
|
11
|
+
reason << "#{$1.gsub("\n", '<<<NEWLINE>>>')}:" if expected
|
12
|
+
reason << line
|
13
|
+
reason << "#{'~' * (parser.failure_column - 1)}^"
|
14
|
+
end
|
15
|
+
reason.join("\n")
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.from_edn(s)
|
19
|
+
ast = @@parser.parse s
|
20
|
+
if !ast
|
21
|
+
raise ArgumentError, "Parse Error:\n" << self.reason(@@parser, s)
|
22
|
+
end
|
23
|
+
ret = EDN.new(ast)
|
24
|
+
ret
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_accessor :ast, :tree
|
28
|
+
def initialize(ast_)
|
29
|
+
@ast = ast_
|
30
|
+
@tree = ast.ast
|
31
|
+
end
|
32
|
+
|
33
|
+
def warn_error(s)
|
34
|
+
warn s
|
35
|
+
@error = true
|
36
|
+
end
|
37
|
+
def deep_clone
|
38
|
+
Marshal.load(Marshal.dump(self))
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'cbor-diagnostic'
|
2
|
+
module CBOR_DIAG
|
3
|
+
end
|
4
|
+
|
5
|
+
require 'treetop'
|
6
|
+
require_relative './edngrammar'
|
7
|
+
|
8
|
+
class Treetop::Runtime::SyntaxNode
|
9
|
+
def ast
|
10
|
+
fail "undefined_ast #{inspect}"
|
11
|
+
end
|
12
|
+
def ast1 # devhack
|
13
|
+
"#{inspect[10..20]}--#{text_value[0..15]}"
|
14
|
+
end
|
15
|
+
def hex_value
|
16
|
+
text_value.to_i(16)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
require 'cbor-diagnostic-app/dt'
|
22
|
+
require 'cbor-diagnostic-app/ip'
|
23
|
+
require 'cbor-diagnostic-app/h'
|
24
|
+
require 'cbor-diagnostic-app/b64'
|