edn-abnf-ec 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ require_relative "ipgrammar.rb"
2
+ require 'ipaddr'
3
+
4
+ class CBOR_DIAG::App_ip
5
+ def self.decode(app_prefix, s)
6
+ parser = IPGRAMMARParser.new
7
+ ast = parser.parse(s)
8
+ if !ast
9
+ raise ArgumentError, "cbor-diagnostic: Parse Error in ip'#{s}':\n" << EDN.reason(parser, s)
10
+ end
11
+ fam, ipv = ast.ast
12
+ case app_prefix
13
+ when 'ip'
14
+ ipv
15
+ when 'IP'
16
+ CBOR::Tagged.new(fam, ipv)
17
+ else
18
+ fail app_prefix
19
+ end
20
+ end
21
+ end