cddl 0.8.13 → 0.8.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/cddl.gemspec +1 -1
  3. data/lib/cddl.rb +55 -9
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbd414d9d4fbc897f8f31c03437fa57155547c0f02978de2da4f75844cf0e1ef
4
- data.tar.gz: 9aa239d57c5e70f8352da90cc8023273a2793577df84ee6e003a1ac0fdc200dc
3
+ metadata.gz: 182b4b76590226a9f1f72dd534266693e566b2dea3188e5f0c073c69474c1f07
4
+ data.tar.gz: 49170c49b5f8153a0fd589d31ffd7d4b10f7b394828a816c8a240e8880487754
5
5
  SHA512:
6
- metadata.gz: 00dac4c95e0b94e0bc3ae775b1bf1ab33a41507bb06774ccaa0838daf6c9fffc0c2d4b3d049199c3ae35858888be853058248c710ea056edd718a0938fd7d8e3
7
- data.tar.gz: 18ea8731c6ab8ec9ae547331be276b9ca1c58c490c6986969824a0a56c7870478ca01418f8ae83a5504d393c14e9fcc5764bfc0cb65c7f2f267cd1757dfbdbac
6
+ metadata.gz: 5b1cced35bb95e5eaded068c3f66f25498ff8f03c0de30a992132aa7d254fb6ce4fc8571dc7d4d7cc32799acc97da8cbe6b43b9c90b8254ad0bf54a645763667
7
+ data.tar.gz: f8a7c15619656ae72b792f9fcac5c408a9180a81f51c825e148b086c21a7ba1fa85ef69f4c329bb0cad019198458c33ebe2e0cfa3a030bd11b46eea324e6645d
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'cddl'
3
- s.version = '0.8.13'
3
+ s.version = '0.8.14'
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')
@@ -441,6 +441,29 @@ module CDDL
441
441
  generate1(target, inmap)
442
442
  when :feature
443
443
  generate1(target, inmap)
444
+ when :cat
445
+ lhs = generate1(target, inmap)
446
+ rhs = generate1(control)
447
+ begin
448
+ lhs + rhs
449
+ rescue Exception => e
450
+ fail "Can't #{lhs.inspect} .cat #{rhs.inspect}: #{e.message}"
451
+ end
452
+ when :plus
453
+ lhs = generate1(target, inmap)
454
+ rhs = generate1(control)
455
+ begin
456
+ case lhs
457
+ when Integer
458
+ lhs + Integer(rhs)
459
+ when Numeric
460
+ lhs + rhs
461
+ else
462
+ fail "#{lhs.inspect}: Not a number"
463
+ end
464
+ rescue Exception => e
465
+ fail "Can't #{lhs.inspect} .plus #{rhs.inspect}: #{e.message}"
466
+ end
444
467
  when :eq
445
468
  content = generate1(control)
446
469
  if validate1(content, where)
@@ -542,9 +565,24 @@ module CDDL
542
565
  [true, t[1], vt]
543
566
  elsif v = SIMPLE_VALUE[t]
544
567
  v
545
- else
546
- [false]
547
- end
568
+ elsif t[0] == :anno
569
+ _, conop, target, control = t
570
+ # warn ["EXV0", conop, target, control].inspect
571
+ if conop == :cat || conop == :plus
572
+ ok1, v1, vt1 = extract_value(target)
573
+ ok2, v2, vt2 = extract_value(control)
574
+ # warn ["EXV", ok1, v1, vt1, ok2, v2, vt2].inspect
575
+ if ok1 && ok2
576
+ if vt1 == Integer
577
+ [true, v1 + Integer(v2), Integer] if vt2 == Integer || vt2 == Float
578
+ elsif vt1 == Float
579
+ [true, v1 + v2, vt1] if vt2 == Integer || vt2 == Float
580
+ else
581
+ [true, v1 + v2, vt1] if vt1 == vt2
582
+ end
583
+ end rescue nil
584
+ end
585
+ end || [false]
548
586
  end
549
587
 
550
588
  def extract_array(t)
@@ -772,10 +810,18 @@ module CDDL
772
810
  when :range
773
811
  [] if where[2] === d && where[1].include?(d)
774
812
  when :anno
775
- target = where[2]
776
- if ann = validate1a(d, target)
777
- control = where[3]
778
- case where[1]
813
+ _, conop, target, control = where
814
+ if conop == :cat || conop == :plus
815
+ ok1, v1, vt1 = extract_value(target)
816
+ ok2, v2, vt2 = extract_value(control)
817
+ # warn ["ANNO0", ok1, v1, vt1, ok2, v2, vt2, d].inspect
818
+ if ok1 && ok2
819
+ v2 = Integer(v2) if vt1 == Integer
820
+ # warn ["ANNO", ok1, v1, vt1, ok2, v2, vt2, d].inspect
821
+ [] if d == v1 + v2 # XXX Focus ArgumentError
822
+ end
823
+ elsif ann = validate1a(d, target)
824
+ case conop
779
825
  when :size
780
826
  case d
781
827
  when Integer
@@ -831,7 +877,7 @@ module CDDL
831
877
  $features[nm][det] = true
832
878
  ann
833
879
  when :lt, :le, :gt, :ge, :eq, :ne
834
- op = OPERATORS[where[1]]
880
+ op = OPERATORS[conop]
835
881
  ok, v, _vt = extract_value(control)
836
882
  if ok
837
883
  ann if d.send(op, v) rescue nil # XXX Focus ArgumentError
@@ -1201,7 +1247,7 @@ module CDDL
1201
1247
  BRACE = {"{" => :map, "[" => :array}
1202
1248
  RANGE_EXCLUDE_END = {".." => false, "..." => true}
1203
1249
  SUPPORTED_ANNOTATIONS = [:bits, :size, :regexp, :cbor, :cborseq, :within, :and,
1204
- :default, :lt, :le, :gt, :ge, :eq, :ne, :feature]
1250
+ :default, :lt, :le, :gt, :ge, :eq, :ne, :feature, :cat, :plus]
1205
1251
 
1206
1252
  def type1(n, canbegroup = false)
1207
1253
  # puts "NVALUE #{n.value.inspect}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cddl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.13
4
+ version: 0.8.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-13 00:00:00.000000000 Z
11
+ date: 2020-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cbor-diag