mbt-gen 0.0.14.3 → 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 -33
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13d918d0f3a00531a412669c0bcfb9cf0162c80c754b10c2eca6957d31c06c3e
4
- data.tar.gz: 394f97de41ebf357f02568da55c38b69541d01f70358d6a10f12ef02458826b7
3
+ metadata.gz: c6f149d7271efc294d8f271bdf128035d2acdd1e9a7e84da5d521d175fa06beb
4
+ data.tar.gz: 72957666141ef8a413d86bf104d80207533affda28475e2ee54a88f2c1a6a288
5
5
  SHA512:
6
- metadata.gz: bc652237dc0adb070594e90fc44cb5342fff9e1ab2fcbb14f4e07642d88622036b9e2f043b7f7e0582d2d667e04a47afc70e4af0c03ace5bd6ecc793c9798ddd
7
- data.tar.gz: 82859f8923dfe404b79ed80eb36fe4a3011be424dd4086c6d0be369571cb64ca3a39d5caf67867e2a36f399456ba7f49ed5e95650a4db60768f000c2096ae056
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
@@ -574,7 +576,6 @@ def resolve_struct_path(path, relative_to_struct, prefix)
574
576
  end
575
577
  end
576
578
  end
577
- puts "DEBUG: resolve_struct_path(#{path.inspect}, #{relative_to_struct[:struct_xpath_prefix].inspect}, #{prefix.inspect}) returned #{result.inspect}"
578
579
  return result
579
580
  end
580
581
 
@@ -589,21 +590,21 @@ def resolve_struct_def(path, relative_to_struct, prefix, context_desc = "")
589
590
  result = current
590
591
  elsif segment == ".." then
591
592
  if prefix then
592
- current = current[:parent_links].find{|link| prefix.start_with?(link[:struct_xpath_prefix]) }
593
- 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) }
594
595
  else
595
596
  if current[:parent_links].size > 1 then
596
- 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(', ')})")
597
598
  else
598
599
  current = current[:parent_links].first
599
- prefix = current[:struct_xpath_prefix]
600
+ prefix = current[:struct_xpath_prefixes].first
600
601
  end
601
602
  end
602
603
  if prefix then
603
604
  prefix_segs = prefix.split("/")
604
605
  prefix = prefix_segs[0,prefix_segs.size()-1].join("/")
605
606
  else
606
- prefix = current[:struct_xpath_prefix]
607
+ prefix = current[:struct_xpath_prefixes].first
607
608
  end
608
609
  else
609
610
  field_def = current[segment.to_sym]
@@ -621,14 +622,14 @@ def resolve_struct_def(path, relative_to_struct, prefix, context_desc = "")
621
622
  end
622
623
  end
623
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}"
624
626
  return result
625
627
  end
626
628
 
627
629
  def translate_validation_rules_to_SMTLIB(progress, solver, struct, prefix, config, options)
628
- solver.to_solver(progress, "; --- Validation Rules ---")
629
630
  translate_validation_rules_for_structure_to_SMTLIB(progress, solver, struct, prefix, config, options)
630
631
  struct.each_pair do |key, value|
631
- 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
632
633
  if value[:type] == :structure then
633
634
  if prefix then
634
635
  new_prefix = "#{prefix.to_s}/#{key}"
@@ -653,6 +654,15 @@ def translate_validation_rules_to_SMTLIB(progress, solver, struct, prefix, confi
653
654
  end
654
655
  end
655
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
+
656
666
  def translate_validation_rule_to_SMTLIB(rule, context_struct, prefix, config, options, rule_name)
657
667
  date_now = options[:date_now]
658
668
  timestamp_now = options[:timestamp_now]
@@ -728,14 +738,15 @@ def translate_validation_rule_to_SMTLIB(rule, context_struct, prefix, config, op
728
738
  end
729
739
  preds = sdef[:predicates]
730
740
  mdk = preds[key]
741
+ sxpath = pick_combined_path(sdef[:struct_xpath_prefixes], prefix, path)
731
742
  if mdk then
732
743
  if mdk[:smtlib] then
733
- 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}]" )
734
745
  else
735
- 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}")
736
747
  end
737
748
  else
738
- 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}")
739
750
  end
740
751
  end
741
752
  .gsub(/CONFIG\[[^\]]*\]/) do |m|
@@ -812,7 +823,6 @@ end
812
823
  def translate_validation_rules_for_structure_to_SMTLIB(progress, solver, struct, prefix, config, options)
813
824
  return unless struct[:validation_rules]
814
825
 
815
- solver.to_solver(progress, "; --- Validation Rules: ---")
816
826
  negated_rules = options[:negated_validation_rules] || []
817
827
  solver.to_solver(progress, "; negated rules: #{negated_rules.empty? ? "<none>" : negated_rules.join(", ")}")
818
828
 
@@ -839,7 +849,6 @@ def parse_field_value(fielddef, value)
839
849
  when :enum
840
850
  return solver_value_to_string(value)
841
851
  when :date
842
- puts "DEBUG: parsing date #{value.inspect}"
843
852
  return Date.parse(value)
844
853
  when :timestamp
845
854
  return Time.new(value)
@@ -906,7 +915,7 @@ end
906
915
 
907
916
  def add_max_struct_to_doc(progress, struct, doc, prefix = nil)
908
917
  struct.each do |key, value|
909
- 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
910
919
  if prefix then
911
920
  xpath = "#{prefix}/#{key}"
912
921
  else
@@ -974,7 +983,7 @@ end
974
983
 
975
984
  def add_model_struct_to_doc(progress, struct, doc, model, prefix = nil)
976
985
  struct.each do |key, value|
977
- 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
978
987
  if prefix then
979
988
  xpath = "#{prefix}/#{key}"
980
989
  else
@@ -1037,7 +1046,7 @@ end
1037
1046
  def collect_validation_rule_names(struct)
1038
1047
  result = []
1039
1048
  struct.each do |key, value|
1040
- 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
1041
1050
  if key == :validation_rules
1042
1051
  value.each do |key, value|
1043
1052
  result << key
@@ -1059,7 +1068,7 @@ end
1059
1068
 
1060
1069
  def each_structure_and_field_in(struct, prefix = nil, &block)
1061
1070
  struct.each do |key, value|
1062
- 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
1063
1072
 
1064
1073
  if prefix then
1065
1074
  xpath = "#{prefix}/#{key}"
@@ -1540,7 +1549,7 @@ end
1540
1549
  def collect_key_fields(fkey, struct, prefix = nil)
1541
1550
  result = {}
1542
1551
  struct.each do |key, value|
1543
- 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
1544
1553
  if value[:type] == :structure
1545
1554
  if value.has_key?(:keys) and value[:keys].include?(fkey) then
1546
1555
  xpath = key.to_s
@@ -1566,7 +1575,7 @@ def collect_key_fields_and_strctures(fkey, struct, prefix = nil)
1566
1575
  fields = []
1567
1576
  structures = []
1568
1577
  struct.each do |key, value|
1569
- 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
1570
1579
  if value[:type] == :structure
1571
1580
  if value.has_key?(:keys) and value[:keys].include?(fkey) then
1572
1581
  xpath = key.to_s
@@ -1593,7 +1602,7 @@ end
1593
1602
  def collect_keys(struct)
1594
1603
  result = []
1595
1604
  struct.each do |key, value|
1596
- 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
1597
1606
  if value[:type] == :structure
1598
1607
  if value.has_key?(:keys) then
1599
1608
  result += value[:keys]
@@ -1613,7 +1622,7 @@ end
1613
1622
  def collect_validation_rules(struct)
1614
1623
  result = []
1615
1624
  struct.each do |key, value|
1616
- 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
1617
1626
  if key == :validation_rules then
1618
1627
  result += value.keys
1619
1628
  else
@@ -2169,10 +2178,14 @@ def introduce_parent_links(message, parent = nil, prefix = nil)
2169
2178
  end
2170
2179
  end
2171
2180
  if prefix != nil then
2172
- 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
2173
2186
  end
2174
2187
  message.each_pair do |key, value|
2175
- 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
2176
2189
  if value[:type] == :structure then
2177
2190
  if prefix then
2178
2191
  new_prefix = "#{prefix}/#{key}"
@@ -2206,7 +2219,7 @@ def validate_model(message, prefix=nil)
2206
2219
  puts "WARN: Model Problem: structure #{prefix}'s predicate #{mkey} does not have an SMTLIB representation. It will be regarded as always true."
2207
2220
  end
2208
2221
  end
2209
- elsif key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
2222
+ elsif key == :parent_links || key == :struct_xpath_prefixes || key == :additional_smtlib
2210
2223
  next
2211
2224
  else
2212
2225
  if value[:type] == :structure then
@@ -2319,7 +2332,7 @@ end
2319
2332
 
2320
2333
  def validate_schema_against_doc_struct(struct, doc, prefix = nil)
2321
2334
  struct.each do |key, value|
2322
- 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
2323
2336
  if prefix then
2324
2337
  xpath = "#{prefix}/#{key}"
2325
2338
  else
@@ -2394,7 +2407,7 @@ def translate_struct_in_doc_to_SMTLIB(progress, solver, struct, doc, prefix, var
2394
2407
  config = hash[:config]
2395
2408
 
2396
2409
  struct.each do |key, value|
2397
- 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
2398
2411
  if prefix then
2399
2412
  xpath = "#{prefix}/#{key.to_s}"
2400
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.3
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-06 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