cddl 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cddl +29 -22
- data/cddl.gemspec +2 -1
- data/lib/cddl.rb +23 -6
- data/test-data/wrong1.cddl +17 -0
- data/test-data/wrong1a.cddl +23 -0
- data/test-data/wrong2.cddl +17 -0
- data/test-data/wrong2a.cddl +17 -0
- metadata +19 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1070fa01f476cb900016c1b95c4c484aa8554e6
|
4
|
+
data.tar.gz: 424df46b269ae91a60fcb9cf4276b8f6f55f5f93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 621214556cefefda17498ef05c345755d72cd0bc3264b5c2540c5c2285abf86ea74a6ef99df78fedcc9fe30408f97b4be00506e648dfc02795512ea87086ca30
|
7
|
+
data.tar.gz: f31756c68e80f4ccf514aa85dbc3dca77cdb73b4605c3db6edd2cab3e094e091ea8c3cc1bb62088f31aa156dbed68e27231fac495c1334dabfecaeebe2d5c8b0
|
data/bin/cddl
CHANGED
@@ -19,6 +19,7 @@ def read_arg(arg)
|
|
19
19
|
if arg == "-"
|
20
20
|
STDIN.read
|
21
21
|
else
|
22
|
+
usage unless arg
|
22
23
|
File.read(arg)
|
23
24
|
end
|
24
25
|
end
|
@@ -27,27 +28,33 @@ def parser
|
|
27
28
|
@parser ||= CDDL::Parser.new(read_arg(ARGV[0]))
|
28
29
|
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
31
|
+
begin
|
32
|
+
case ARGV[1]
|
33
|
+
when /\Ar/ # secret
|
34
|
+
$advanced = true
|
35
|
+
pp parser.rules
|
36
|
+
when /\Ag/
|
37
|
+
n = 1
|
38
|
+
n = ARGV[2].to_i if ARGV[2]
|
39
|
+
n.times do
|
40
|
+
g = parser.generate
|
41
|
+
puts g.cbor_diagnostic
|
42
|
+
end
|
43
|
+
when /\Aj/
|
44
|
+
n = 1
|
45
|
+
n = ARGV[2].to_i if ARGV[2]
|
46
|
+
n.times do
|
47
|
+
g = parser.generate
|
48
|
+
puts JSON.pretty_generate(g)
|
49
|
+
end
|
50
|
+
when /\Av/
|
51
|
+
instance = read_arg(ARGV[2])
|
52
|
+
instance = CBOR.decode(instance.b) rescue JSON.load(instance)
|
53
|
+
p parser.validate(instance)
|
54
|
+
else
|
55
|
+
usage
|
46
56
|
end
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
p parser.validate(instance)
|
51
|
-
else
|
52
|
-
usage
|
57
|
+
rescue CDDL::ParseError => e
|
58
|
+
warn e.message
|
59
|
+
exit 1
|
53
60
|
end
|
data/cddl.gemspec
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
spec = Gem::Specification.new do |s|
|
2
2
|
s.name = 'cddl'
|
3
|
-
s.version = '0.2.
|
3
|
+
s.version = '0.2.1'
|
4
4
|
s.summary = "CDDL generator and validator."
|
5
5
|
s.description = %{A parser, generator, and validator for CDDL}
|
6
6
|
s.add_dependency('cbor-diag')
|
7
7
|
s.add_dependency('abnc')
|
8
8
|
s.add_dependency('json')
|
9
9
|
s.add_dependency('regexp-examples')
|
10
|
+
s.add_dependency('colorize')
|
10
11
|
s.files = `git ls-files`.split("\n").grep(/^[a-z]/)
|
11
12
|
s.files = Dir['lib/**/*.rb'] + %w(cddl.gemspec) + Dir['data/**/*.abnf'] + Dir['data/**/*.cddl'] + Dir['test-data/**/*.cddl'] + Dir['test/**/*.rb']
|
12
13
|
s.require_path = 'lib'
|
data/lib/cddl.rb
CHANGED
@@ -3,6 +3,7 @@ require 'pp'
|
|
3
3
|
require 'pathname'
|
4
4
|
require 'cbor-pure'
|
5
5
|
require 'regexp-examples'
|
6
|
+
require 'colorize'
|
6
7
|
|
7
8
|
module CDDL
|
8
9
|
|
@@ -13,6 +14,8 @@ module CDDL
|
|
13
14
|
|
14
15
|
MANY = Float::INFINITY
|
15
16
|
|
17
|
+
class ParseError < ArgumentError; end
|
18
|
+
|
16
19
|
class Parser
|
17
20
|
def initialize(source_text)
|
18
21
|
@abnf = Peggy::ABNF.new
|
@@ -21,12 +24,26 @@ module CDDL
|
|
21
24
|
expected_length = source_text.length + PRELUDE.length
|
22
25
|
if expected_length != presult
|
23
26
|
upto = @abnf.parse_results.keys.max
|
24
|
-
puts "UPTO: #{upto}"
|
25
|
-
pp @abnf.parse_results[upto]
|
26
|
-
pp @abnf.parse_results[presult]
|
27
|
-
|
28
|
-
puts @abnf.ast?
|
29
|
-
|
27
|
+
puts "UPTO: #{upto}" if $advanced
|
28
|
+
pp @abnf.parse_results[upto] if $advanced
|
29
|
+
pp @abnf.parse_results[presult] if $advanced
|
30
|
+
puts "SO FAR: #{presult}" if $advanced
|
31
|
+
puts @abnf.ast? if $advanced
|
32
|
+
presult ||= 0
|
33
|
+
part1 = source_text[[presult - 100, 0].max...presult]
|
34
|
+
part3 = source_text[upto...[upto + 100, source_text.length].min]
|
35
|
+
if upto - presult < 100
|
36
|
+
part2 = source_text[presult...upto]
|
37
|
+
else
|
38
|
+
part2 = source_text[presult, 50] + "......." + source_text[upto-50, 50]
|
39
|
+
end
|
40
|
+
warn "*** Look for syntax problems around the #{
|
41
|
+
"%%%".colorize(background: :light_yellow)} markers:\n#{
|
42
|
+
part1}#{"%%%".colorize(color: :green, background: :light_yellow)}#{
|
43
|
+
part2}#{"%%%".colorize(color: :red, background: :light_yellow)}#{
|
44
|
+
part3}"
|
45
|
+
raise ParseError, "*** Parse error at #{presult} upto #{upto} of #{
|
46
|
+
source_text.length} (#{expected_length})."
|
30
47
|
end
|
31
48
|
puts @abnf.ast? if $debug_ast
|
32
49
|
@ast = @abnf.ast?
|
@@ -0,0 +1,17 @@
|
|
1
|
+
reputation-object = {
|
2
|
+
application: tstr
|
3
|
+
reputons: [* reputon]
|
4
|
+
|
5
|
+
|
6
|
+
reputon = {
|
7
|
+
rater: tstr
|
8
|
+
assertion: tstr
|
9
|
+
rated: tstr
|
10
|
+
rating: float16
|
11
|
+
? confidence: float16
|
12
|
+
? normal-rating: float16
|
13
|
+
? sample-size: uint
|
14
|
+
? generated: uint
|
15
|
+
? expires: uint
|
16
|
+
* any: any
|
17
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
reputation-object = {
|
2
|
+
application: tstr
|
3
|
+
? confidence: float16
|
4
|
+
? normal-rating: float16
|
5
|
+
? sample-size: uint
|
6
|
+
? generated: uint
|
7
|
+
? expires: uint
|
8
|
+
* any: any
|
9
|
+
reputons: [* reputon]
|
10
|
+
|
11
|
+
|
12
|
+
reputon = {
|
13
|
+
rater: tstr
|
14
|
+
assertion: tstr
|
15
|
+
rated: tstr
|
16
|
+
rating: float16
|
17
|
+
? confidence: float16
|
18
|
+
? normal-rating: float16
|
19
|
+
? sample-size: uint
|
20
|
+
? generated: uint
|
21
|
+
? expires: uint
|
22
|
+
* any: any
|
23
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
reputation-object = {
|
2
|
+
application: tstr
|
3
|
+
reputons: [* reputon]
|
4
|
+
}
|
5
|
+
|
6
|
+
reputon =
|
7
|
+
rater: tstr
|
8
|
+
assertion: tstr
|
9
|
+
rated: tstr
|
10
|
+
rating: float16
|
11
|
+
? confidence: float16
|
12
|
+
? normal-rating: float16
|
13
|
+
? sample-size: uint
|
14
|
+
? generated: uint
|
15
|
+
? expires: uint
|
16
|
+
* any: any
|
17
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
reputation-object = {
|
2
|
+
application: tstr
|
3
|
+
reputons: [* reputon]
|
4
|
+
}
|
5
|
+
|
6
|
+
reputon = {
|
7
|
+
rater: tstr
|
8
|
+
assertion: tstr
|
9
|
+
rated: tstr
|
10
|
+
rating: float16
|
11
|
+
? confidence: float16
|
12
|
+
? normal-rating: float16
|
13
|
+
? sample-size: uint
|
14
|
+
? generated: uint
|
15
|
+
? expires: uint
|
16
|
+
* any: any
|
17
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cddl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: colorize
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: A parser, generator, and validator for CDDL
|
70
84
|
email: cabo@tzi.org
|
71
85
|
executables:
|
@@ -86,6 +100,10 @@ files:
|
|
86
100
|
- test-data/reused_named_group.cddl
|
87
101
|
- test-data/structure.cddl
|
88
102
|
- test-data/two_anonymous_groups.cddl
|
103
|
+
- test-data/wrong1.cddl
|
104
|
+
- test-data/wrong1a.cddl
|
105
|
+
- test-data/wrong2.cddl
|
106
|
+
- test-data/wrong2a.cddl
|
89
107
|
- test/test-cddl.rb
|
90
108
|
homepage: http://github.com/cabo/cddl
|
91
109
|
licenses:
|