mbt-gen 0.0.14.4 → 0.0.14.5

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mbt-gen.rb +46 -31
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4caff5f0cdde9dd37c43c82f2476248c4ac09f35588653cb81d664eafb1d49bd
4
- data.tar.gz: 3bf76fa6792a1c46ed8042c4264421c4f3156c190399c329928fbcd1fc436369
3
+ metadata.gz: c6f149d7271efc294d8f271bdf128035d2acdd1e9a7e84da5d521d175fa06beb
4
+ data.tar.gz: 72957666141ef8a413d86bf104d80207533affda28475e2ee54a88f2c1a6a288
5
5
  SHA512:
6
- metadata.gz: a3aa357233ece8bea791ee379592f0c2e47f410192c1d6ddd1ba4986986e1cda38842438b215bd16ccf67431e82a061a3751160818e1e6bfda7b17b19c560bf5
7
- data.tar.gz: d104b7b264994a0f4d205d58d7ad156c51807ca612a73ce4114e682a62443a989435dc67afaa7ff397de1edba83b6d44d53946df7a050d252965eea35a097abd
6
+ metadata.gz: 43a624e553b299f6a5ccab4e5abeb2bfea6f783ffeee6acbeab702320080788005ae46a5265e7898b0fd88b621c580dad55a46bbfbed096badc6dcb1e59d0045
7
+ data.tar.gz: d587b0987262a7dc6161b0c961eeebfb176b23860173e73c73d15fba44991831d2deda5432d21f766026249133bf2fa71fa11d50a90d532a6c7b52e949d9f4d4
data/lib/mbt-gen.rb CHANGED
@@ -364,7 +364,9 @@ def translate_structure_to_SMTLIB(progress, solver, struct, hash = {})
364
364
  prefix = hash[:prefix]
365
365
  config = hash[:config]
366
366
  options = hash[:options]
367
+ solver.to_solver(progress, "; --- Structure: ---")
367
368
  translate_substructure_to_SMTLIB(progress, solver, struct, hash)
369
+ solver.to_solver(progress, "; --- Validation Rules: ---")
368
370
  translate_validation_rules_to_SMTLIB(progress, solver, struct, prefix, config, options)
369
371
  if options[:add_SMTLIB] then
370
372
  solver.to_solver(progress, "; --- additional SMTLIB Code: ---")
@@ -377,12 +379,11 @@ def translate_substructure_to_SMTLIB(progress, solver, struct, hash = {})
377
379
  struct_varname = hash[:struct_varname]
378
380
  config = hash[:config]
379
381
  options = hash[:options]
380
- solver.to_solver(progress, "; --- Structure: ---")
381
382
  struct.each do |field, definition|
382
383
  if field == :additional_smtlib then
383
384
  solver.to_solver(progress, "; additional SMTLIB of structure #{prefix}")
384
385
  solver.to_solver(progress, translate_validation_rule_to_SMTLIB(definition, struct, prefix, config, options, "<additional SMTLIB of structure #{prefix}>"))
385
- elsif field == :validation_rules || field == :predicates || field == :parent_links || field == :struct_xpath_prefix
386
+ elsif field == :validation_rules || field == :predicates || field == :parent_links || field == :struct_xpath_prefixes
386
387
  next
387
388
  else
388
389
  solver.to_solver(progress, "; #{field.to_s}")
@@ -496,6 +497,7 @@ def resolve_field_path(path, relative_to_struct, prefix)
496
497
  end
497
498
  end
498
499
  end
500
+ # puts "DEBUG: resolve_field_path(path=#{path.inspect}, relative_to_struct=[#{relative_to_struct[:struct_xpath_prefixes].join(', ')}], prefix=#{prefix.inspect}) = #{result.inspect}"
499
501
  return result
500
502
  end
501
503
 
@@ -542,19 +544,19 @@ def resolve_struct_path(path, relative_to_struct, prefix)
542
544
  result = prefix
543
545
  elsif segment == ".." then
544
546
  if prefix then
545
- next_current = current[:parent_links].find{ |link| prefix.start_with?(link[:struct_xpath_prefix]) }
547
+ next_current = current[:parent_links].find{ |link| link[:struct_xpath_prefixes].any?{ |lprefix| prefix.start_with?(lprefix) } }
546
548
  if next_current then
547
549
  current = next_current
548
- prefix = current[:struct_xpath_prefix]
550
+ prefix = current[:struct_xpath_prefixes].find{ |cprefix| prefix.start_with?(cprefix) }
549
551
  else
550
- raise RuntimeError.new("failure to resolve segment '..' of path #{path.inspect}: none of the parent-links (#{current[:parent_links].map{|p| p[:struct_xpath_prefix]}.join(', ')}) of struct #{current[:struct_xpath_prefix]} matched the prefix #{prefix.inspect}")
552
+ raise RuntimeError.new("failure to resolve segment '..' of path #{path.inspect}: none of the parent-links (#{current[:parent_links].map{|p| "[#{p[:struct_xpath_prefixes].join(', ')}]"}.join(', ')}) of struct [#{current[:struct_xpath_prefixes].join(', ')}] matched the prefix #{prefix.inspect}")
551
553
  end
552
554
  else
553
555
  if current[:parent_links].size > 1 then
554
- raise RuntimeError.new("could not resolve segment '..' in path #{path.inspect} as it is ambiguous: structure #{current[:struct_xpath_prefix]} has multiple parent-links (#{current[:parent_links].map{|p| p[:struct_xpath_prefix]}.join(', ')})")
556
+ raise RuntimeError.new("could not resolve segment '..' in path #{path.inspect} as it is ambiguous: structure [#{current[:struct_xpath_prefixes].join(', ')}] has multiple parent-links (#{current[:parent_links].map{|p| "#{p[:struct_xpath_prefixes]}" }.join(', ')})")
555
557
  else
556
558
  current = current[:parent_links].first
557
- prefix = current[:struct_xpath_prefix]
559
+ prefix = current[:struct_xpath_prefixes].find{ |cprefix| prefix.start_with?(cprefix) }
558
560
  end
559
561
  end
560
562
  result = prefix
@@ -588,21 +590,21 @@ def resolve_struct_def(path, relative_to_struct, prefix, context_desc = "")
588
590
  result = current
589
591
  elsif segment == ".." then
590
592
  if prefix then
591
- current = current[:parent_links].find{|link| prefix.start_with?(link[:struct_xpath_prefix]) }
592
- prefix = current[:struct_xpath_prefix]
593
+ current = current[:parent_links].find{|link| link[:struct_xpath_prefixes].any?{ |lprefix| prefix.start_with?(lprefix) } }
594
+ prefix = current[:struct_xpath_prefixes].find{ |p| prefix.start_with?(p) }
593
595
  else
594
596
  if current[:parent_links].size > 1 then
595
- raise RuntimeError.new("could not resolve segment '..' in path #{path.inspect} as it is ambiguous: structure #{current[:struct_xpath_prefix]} has multiple parent-links (#{current[:parent_links].map{|p| p[:struct_xpath_prefix]}.join(', ')})")
597
+ raise RuntimeError.new("could not resolve segment '..' in path #{path.inspect} as it is ambiguous: structure [#{current[:struct_xpath_prefixes].join(', ')}] has multiple parent-links (#{current[:parent_links].map{|p| "[#{p[:struct_xpath_prefixes].join(', ')}]"}.join(', ')})")
596
598
  else
597
599
  current = current[:parent_links].first
598
- prefix = current[:struct_xpath_prefix]
600
+ prefix = current[:struct_xpath_prefixes].first
599
601
  end
600
602
  end
601
603
  if prefix then
602
604
  prefix_segs = prefix.split("/")
603
605
  prefix = prefix_segs[0,prefix_segs.size()-1].join("/")
604
606
  else
605
- prefix = current[:struct_xpath_prefix]
607
+ prefix = current[:struct_xpath_prefixes].first
606
608
  end
607
609
  else
608
610
  field_def = current[segment.to_sym]
@@ -620,14 +622,14 @@ def resolve_struct_def(path, relative_to_struct, prefix, context_desc = "")
620
622
  end
621
623
  end
622
624
  end
625
+ # puts "DEBUG: resolve_struct_def(path=#{path.inspect}, relative_to_struct=[#{relative_to_struct[:struct_xpath_prefixes].join(', ')}], prefix=#{prefix.inspect}) = #{result.inspect}"
623
626
  return result
624
627
  end
625
628
 
626
629
  def translate_validation_rules_to_SMTLIB(progress, solver, struct, prefix, config, options)
627
- solver.to_solver(progress, "; --- Validation Rules ---")
628
630
  translate_validation_rules_for_structure_to_SMTLIB(progress, solver, struct, prefix, config, options)
629
631
  struct.each_pair do |key, value|
630
- next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
632
+ next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefixes || key == :additional_smtlib
631
633
  if value[:type] == :structure then
632
634
  if prefix then
633
635
  new_prefix = "#{prefix.to_s}/#{key}"
@@ -652,6 +654,15 @@ def translate_validation_rules_to_SMTLIB(progress, solver, struct, prefix, confi
652
654
  end
653
655
  end
654
656
 
657
+ def pick_combined_path(list, base_path, path)
658
+ res = Pathname.new(base_path) + Pathname.new(path)
659
+ if list.include?(res.to_path) then
660
+ res.to_path
661
+ else
662
+ nil
663
+ end
664
+ end
665
+
655
666
  def translate_validation_rule_to_SMTLIB(rule, context_struct, prefix, config, options, rule_name)
656
667
  date_now = options[:date_now]
657
668
  timestamp_now = options[:timestamp_now]
@@ -727,14 +738,15 @@ def translate_validation_rule_to_SMTLIB(rule, context_struct, prefix, config, op
727
738
  end
728
739
  preds = sdef[:predicates]
729
740
  mdk = preds[key]
741
+ sxpath = pick_combined_path(sdef[:struct_xpath_prefixes], prefix, path)
730
742
  if mdk then
731
743
  if mdk[:smtlib] then
732
- translate_validation_rule_to_SMTLIB(mdk[:smtlib], sdef, sdef[:struct_xpath_prefix], config, options, "#{rule_name}.predicate.#{key}[#{sdef[:struct_xpath_prefix]}]" )
744
+ translate_validation_rule_to_SMTLIB(mdk[:smtlib], sdef, sxpath, config, options, "#{rule_name}.predicate.#{key}[#{sxpath}]" )
733
745
  else
734
- raise RuntimeError.new("Predicate #{key} for structure #{sdef[:struct_xpath_prefix]} does not have an SMTLIB definition, but is referenced in validation rule #{rule_name}")
746
+ raise RuntimeError.new("Predicate #{key} for structure #{sxpath} does not have an SMTLIB definition, but is referenced in validation rule #{rule_name}")
735
747
  end
736
748
  else
737
- raise RuntimeError.new("No predicate #{key.inspect} defined for structure #{sdef[:struct_xpath_prefix]}, but one referenced in validation rule #{rule_name}")
749
+ raise RuntimeError.new("No predicate #{key.inspect} defined for structure #{sxpath}, but one referenced in validation rule #{rule_name}")
738
750
  end
739
751
  end
740
752
  .gsub(/CONFIG\[[^\]]*\]/) do |m|
@@ -811,7 +823,6 @@ end
811
823
  def translate_validation_rules_for_structure_to_SMTLIB(progress, solver, struct, prefix, config, options)
812
824
  return unless struct[:validation_rules]
813
825
 
814
- solver.to_solver(progress, "; --- Validation Rules: ---")
815
826
  negated_rules = options[:negated_validation_rules] || []
816
827
  solver.to_solver(progress, "; negated rules: #{negated_rules.empty? ? "<none>" : negated_rules.join(", ")}")
817
828
 
@@ -904,7 +915,7 @@ end
904
915
 
905
916
  def add_max_struct_to_doc(progress, struct, doc, prefix = nil)
906
917
  struct.each do |key, value|
907
- next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
918
+ next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefixes || key == :additional_smtlib
908
919
  if prefix then
909
920
  xpath = "#{prefix}/#{key}"
910
921
  else
@@ -972,7 +983,7 @@ end
972
983
 
973
984
  def add_model_struct_to_doc(progress, struct, doc, model, prefix = nil)
974
985
  struct.each do |key, value|
975
- next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
986
+ next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefixes || key == :additional_smtlib
976
987
  if prefix then
977
988
  xpath = "#{prefix}/#{key}"
978
989
  else
@@ -1035,7 +1046,7 @@ end
1035
1046
  def collect_validation_rule_names(struct)
1036
1047
  result = []
1037
1048
  struct.each do |key, value|
1038
- next if key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
1049
+ next if key == :predicates || key == :parent_links || key == :struct_xpath_prefixes || key == :additional_smtlib
1039
1050
  if key == :validation_rules
1040
1051
  value.each do |key, value|
1041
1052
  result << key
@@ -1057,7 +1068,7 @@ end
1057
1068
 
1058
1069
  def each_structure_and_field_in(struct, prefix = nil, &block)
1059
1070
  struct.each do |key, value|
1060
- next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
1071
+ next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefixes || key == :additional_smtlib
1061
1072
 
1062
1073
  if prefix then
1063
1074
  xpath = "#{prefix}/#{key}"
@@ -1538,7 +1549,7 @@ end
1538
1549
  def collect_key_fields(fkey, struct, prefix = nil)
1539
1550
  result = {}
1540
1551
  struct.each do |key, value|
1541
- next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
1552
+ next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefixes || key == :additional_smtlib
1542
1553
  if value[:type] == :structure
1543
1554
  if value.has_key?(:keys) and value[:keys].include?(fkey) then
1544
1555
  xpath = key.to_s
@@ -1564,7 +1575,7 @@ def collect_key_fields_and_strctures(fkey, struct, prefix = nil)
1564
1575
  fields = []
1565
1576
  structures = []
1566
1577
  struct.each do |key, value|
1567
- next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
1578
+ next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefixes || key == :additional_smtlib
1568
1579
  if value[:type] == :structure
1569
1580
  if value.has_key?(:keys) and value[:keys].include?(fkey) then
1570
1581
  xpath = key.to_s
@@ -1591,7 +1602,7 @@ end
1591
1602
  def collect_keys(struct)
1592
1603
  result = []
1593
1604
  struct.each do |key, value|
1594
- next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
1605
+ next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefixes || key == :additional_smtlib
1595
1606
  if value[:type] == :structure
1596
1607
  if value.has_key?(:keys) then
1597
1608
  result += value[:keys]
@@ -1611,7 +1622,7 @@ end
1611
1622
  def collect_validation_rules(struct)
1612
1623
  result = []
1613
1624
  struct.each do |key, value|
1614
- next if key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
1625
+ next if key == :predicates || key == :parent_links || key == :struct_xpath_prefixes || key == :additional_smtlib
1615
1626
  if key == :validation_rules then
1616
1627
  result += value.keys
1617
1628
  else
@@ -2167,10 +2178,14 @@ def introduce_parent_links(message, parent = nil, prefix = nil)
2167
2178
  end
2168
2179
  end
2169
2180
  if prefix != nil then
2170
- message[:struct_xpath_prefix] = prefix
2181
+ if message.has_key?(:struct_xpath_prefixes) then
2182
+ message[:struct_xpath_prefixes] << prefix
2183
+ else
2184
+ message[:struct_xpath_prefixes] = [prefix]
2185
+ end
2171
2186
  end
2172
2187
  message.each_pair do |key, value|
2173
- next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
2188
+ next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefixes || key == :additional_smtlib
2174
2189
  if value[:type] == :structure then
2175
2190
  if prefix then
2176
2191
  new_prefix = "#{prefix}/#{key}"
@@ -2204,7 +2219,7 @@ def validate_model(message, prefix=nil)
2204
2219
  puts "WARN: Model Problem: structure #{prefix}'s predicate #{mkey} does not have an SMTLIB representation. It will be regarded as always true."
2205
2220
  end
2206
2221
  end
2207
- elsif key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
2222
+ elsif key == :parent_links || key == :struct_xpath_prefixes || key == :additional_smtlib
2208
2223
  next
2209
2224
  else
2210
2225
  if value[:type] == :structure then
@@ -2317,7 +2332,7 @@ end
2317
2332
 
2318
2333
  def validate_schema_against_doc_struct(struct, doc, prefix = nil)
2319
2334
  struct.each do |key, value|
2320
- next if key == :additional_smtlib || key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix
2335
+ next if key == :additional_smtlib || key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefixes
2321
2336
  if prefix then
2322
2337
  xpath = "#{prefix}/#{key}"
2323
2338
  else
@@ -2392,7 +2407,7 @@ def translate_struct_in_doc_to_SMTLIB(progress, solver, struct, doc, prefix, var
2392
2407
  config = hash[:config]
2393
2408
 
2394
2409
  struct.each do |key, value|
2395
- next if key == :additional_smtlib || key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix
2410
+ next if key == :additional_smtlib || key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefixes
2396
2411
  if prefix then
2397
2412
  xpath = "#{prefix}/#{key.to_s}"
2398
2413
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mbt-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14.4
4
+ version: 0.0.14.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - FM-enthusiast
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-09 00:00:00.000000000 Z
11
+ date: 2026-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri