cddl 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de407896d680d320c446c027731247c60a315a97
4
- data.tar.gz: eae775c3385f92d9fde90bca5c6daa758f4c1683
3
+ metadata.gz: d1070fa01f476cb900016c1b95c4c484aa8554e6
4
+ data.tar.gz: 424df46b269ae91a60fcb9cf4276b8f6f55f5f93
5
5
  SHA512:
6
- metadata.gz: 45ca44b99561f01a106f615827392d83c509f43fba5cb2384c80aae133e15c611ffa487bd6109db0b18fd90bc0c6a14c233f6e81c3a266fed136234cb7424783
7
- data.tar.gz: 8477bb82d3ec84c50d901c90f5af53f7f5431904fcdfe048f7d7f864835948cc9778ef87b0813815dbaff2d5b49d3f1979d2424b389915b49dccb3d36fd099e3
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
- case ARGV[1]
31
- when /\Ar/ # secret
32
- pp parser.rules
33
- when /\Ag/
34
- n = 1
35
- n = ARGV[2].to_i if ARGV[2]
36
- n.times do
37
- g = parser.generate
38
- puts g.cbor_diagnostic
39
- end
40
- when /\Aj/
41
- n = 1
42
- n = ARGV[2].to_i if ARGV[2]
43
- n.times do
44
- g = parser.generate
45
- puts JSON.pretty_generate(g)
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
- when /\Av/
48
- instance = File.read(ARGV[2])
49
- instance = CBOR.decode(instance.b) rescue JSON.load(instance)
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.0'
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
- p presult
28
- puts @abnf.ast?
29
- raise "parse error at #{presult} upto #{upto} of #{expected_length}"
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.0
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: