mbt-gen 0.0.14.1 → 0.0.14.3

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 +51 -25
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5c54288ab2aa997c537744ff1888959c3b7b44ef923d16af13c09cb96609434
4
- data.tar.gz: f727661444b8763cbb7e60ba4c371af16af49cd64bb9e0f4e399e01d0c077cd3
3
+ metadata.gz: 13d918d0f3a00531a412669c0bcfb9cf0162c80c754b10c2eca6957d31c06c3e
4
+ data.tar.gz: 394f97de41ebf357f02568da55c38b69541d01f70358d6a10f12ef02458826b7
5
5
  SHA512:
6
- metadata.gz: 5eb552c215e7e9b97db03dadb8964454c5720c41be7272da5ddb5a2409aeec593a84716581d27fbdda1921a6675935d5df1e8ee800532dfac290d22c945b9d68
7
- data.tar.gz: 6b169b1aa47ca5ae869bb1985839e77545e50a1f087a78ef0dd00c58d688c324dae41645aca6d573a1b51949ebb6de8c3d076582240a18460955de42bf3eb6de
6
+ metadata.gz: bc652237dc0adb070594e90fc44cb5342fff9e1ab2fcbb14f4e07642d88622036b9e2f043b7f7e0582d2d667e04a47afc70e4af0c03ace5bd6ecc793c9798ddd
7
+ data.tar.gz: 82859f8923dfe404b79ed80eb36fe4a3011be424dd4086c6d0be369571cb64ca3a39d5caf67867e2a36f399456ba7f49ed5e95650a4db60768f000c2096ae056
data/lib/mbt-gen.rb CHANGED
@@ -382,7 +382,7 @@ def translate_substructure_to_SMTLIB(progress, solver, struct, hash = {})
382
382
  if field == :additional_smtlib then
383
383
  solver.to_solver(progress, "; additional SMTLIB of structure #{prefix}")
384
384
  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_link || field == :struct_xpath_prefix
385
+ elsif field == :validation_rules || field == :predicates || field == :parent_links || field == :struct_xpath_prefix
386
386
  next
387
387
  else
388
388
  solver.to_solver(progress, "; #{field.to_s}")
@@ -539,15 +539,25 @@ def resolve_struct_path(path, relative_to_struct, prefix)
539
539
  raise RuntimeError.new("could not resolve field path: #{path.inspect} relative to struct #{relative_to_struct.inspect}")
540
540
  end
541
541
  if segment == "." then
542
- result = current[:struct_xpath_prefix]
542
+ result = prefix
543
543
  elsif segment == ".." then
544
- current = current[:parent_link]
545
544
  if prefix then
546
- prefix_segs = prefix.split("/")
547
- prefix = prefix_segs[0,prefix_segs.size()-1].join("/")
545
+ next_current = current[:parent_links].find{ |link| prefix.start_with?(link[:struct_xpath_prefix]) }
546
+ if next_current then
547
+ current = next_current
548
+ prefix = current[:struct_xpath_prefix]
549
+ 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}")
551
+ end
548
552
  else
549
- prefix = current[:struct_xpath_prefix]
553
+ 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(', ')})")
555
+ else
556
+ current = current[:parent_links].first
557
+ prefix = current[:struct_xpath_prefix]
558
+ end
550
559
  end
560
+ result = prefix
551
561
  else
552
562
  field_def = current[segment.to_sym]
553
563
  unless field_def then
@@ -564,6 +574,7 @@ def resolve_struct_path(path, relative_to_struct, prefix)
564
574
  end
565
575
  end
566
576
  end
577
+ puts "DEBUG: resolve_struct_path(#{path.inspect}, #{relative_to_struct[:struct_xpath_prefix].inspect}, #{prefix.inspect}) returned #{result.inspect}"
567
578
  return result
568
579
  end
569
580
 
@@ -577,7 +588,17 @@ def resolve_struct_def(path, relative_to_struct, prefix, context_desc = "")
577
588
  if segment == "." then
578
589
  result = current
579
590
  elsif segment == ".." then
580
- current = current[:parent_link]
591
+ if prefix then
592
+ current = current[:parent_links].find{|link| prefix.start_with?(link[:struct_xpath_prefix]) }
593
+ prefix = current[:struct_xpath_prefix]
594
+ else
595
+ 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
+ else
598
+ current = current[:parent_links].first
599
+ prefix = current[:struct_xpath_prefix]
600
+ end
601
+ end
581
602
  if prefix then
582
603
  prefix_segs = prefix.split("/")
583
604
  prefix = prefix_segs[0,prefix_segs.size()-1].join("/")
@@ -606,8 +627,8 @@ end
606
627
  def translate_validation_rules_to_SMTLIB(progress, solver, struct, prefix, config, options)
607
628
  solver.to_solver(progress, "; --- Validation Rules ---")
608
629
  translate_validation_rules_for_structure_to_SMTLIB(progress, solver, struct, prefix, config, options)
609
- struct.each_pair do |key, value|
610
- next if key == :validation_rules || key == :predicates || key == :parent_link || key == :struct_xpath_prefix || key == :additional_smtlib
630
+ struct.each_pair do |key, value|
631
+ next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
611
632
  if value[:type] == :structure then
612
633
  if prefix then
613
634
  new_prefix = "#{prefix.to_s}/#{key}"
@@ -885,7 +906,7 @@ end
885
906
 
886
907
  def add_max_struct_to_doc(progress, struct, doc, prefix = nil)
887
908
  struct.each do |key, value|
888
- next if key == :validation_rules || key == :predicates || key == :parent_link || key == :struct_xpath_prefix || key == :additional_smtlib
909
+ next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
889
910
  if prefix then
890
911
  xpath = "#{prefix}/#{key}"
891
912
  else
@@ -944,7 +965,7 @@ end
944
965
  def model_value_to_int(model_value)
945
966
  if model_value.is_a?(Integer) then
946
967
  model_value
947
- else if model_value.is_a?(String) then
968
+ elsif model_value.is_a?(String) then
948
969
  Integer(model_value, 10)
949
970
  else
950
971
  raise RuntimeError.new("Don't know how to cast this model value into an int: #{model_value.inspect}")
@@ -953,7 +974,7 @@ end
953
974
 
954
975
  def add_model_struct_to_doc(progress, struct, doc, model, prefix = nil)
955
976
  struct.each do |key, value|
956
- next if key == :validation_rules || key == :predicates || key == :parent_link || key == :struct_xpath_prefix || key == :additional_smtlib
977
+ next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
957
978
  if prefix then
958
979
  xpath = "#{prefix}/#{key}"
959
980
  else
@@ -974,8 +995,9 @@ def add_model_struct_to_doc(progress, struct, doc, model, prefix = nil)
974
995
  node = node.first
975
996
  end
976
997
  xpath_element = value[:xpath_element]
977
- if model_value_to_int(model_value[:size]) > 0 then
978
- model_value[:value].slice(0, Integer(model_value[:size], 10)).each do |mvalue|
998
+ size = model_value_to_int(model_value[:size])
999
+ if size > 0 then
1000
+ model_value[:value].slice(0, size).each do |mvalue|
979
1001
  node.add_child("<#{xpath_element}>#{solver_value_to_string(mvalue)}</#{xpath_element}>")
980
1002
  end
981
1003
  end
@@ -1015,7 +1037,7 @@ end
1015
1037
  def collect_validation_rule_names(struct)
1016
1038
  result = []
1017
1039
  struct.each do |key, value|
1018
- next if key == :predicates || key == :parent_link || key == :struct_xpath_prefix || key == :additional_smtlib
1040
+ next if key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
1019
1041
  if key == :validation_rules
1020
1042
  value.each do |key, value|
1021
1043
  result << key
@@ -1037,7 +1059,7 @@ end
1037
1059
 
1038
1060
  def each_structure_and_field_in(struct, prefix = nil, &block)
1039
1061
  struct.each do |key, value|
1040
- next if key == :validation_rules || key == :predicates || key == :parent_link || key == :struct_xpath_prefix || key == :additional_smtlib
1062
+ next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
1041
1063
 
1042
1064
  if prefix then
1043
1065
  xpath = "#{prefix}/#{key}"
@@ -1518,7 +1540,7 @@ end
1518
1540
  def collect_key_fields(fkey, struct, prefix = nil)
1519
1541
  result = {}
1520
1542
  struct.each do |key, value|
1521
- next if key == :validation_rules || key == :predicates || key == :parent_link || key == :struct_xpath_prefix || key == :additional_smtlib
1543
+ next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
1522
1544
  if value[:type] == :structure
1523
1545
  if value.has_key?(:keys) and value[:keys].include?(fkey) then
1524
1546
  xpath = key.to_s
@@ -1544,7 +1566,7 @@ def collect_key_fields_and_strctures(fkey, struct, prefix = nil)
1544
1566
  fields = []
1545
1567
  structures = []
1546
1568
  struct.each do |key, value|
1547
- next if key == :validation_rules || key == :predicates || key == :parent_link || key == :struct_xpath_prefix || key == :additional_smtlib
1569
+ next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
1548
1570
  if value[:type] == :structure
1549
1571
  if value.has_key?(:keys) and value[:keys].include?(fkey) then
1550
1572
  xpath = key.to_s
@@ -1571,7 +1593,7 @@ end
1571
1593
  def collect_keys(struct)
1572
1594
  result = []
1573
1595
  struct.each do |key, value|
1574
- next if key == :validation_rules || key == :predicates || key == :parent_link || key == :struct_xpath_prefix || key == :additional_smtlib
1596
+ next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
1575
1597
  if value[:type] == :structure
1576
1598
  if value.has_key?(:keys) then
1577
1599
  result += value[:keys]
@@ -1591,7 +1613,7 @@ end
1591
1613
  def collect_validation_rules(struct)
1592
1614
  result = []
1593
1615
  struct.each do |key, value|
1594
- next if key == :predicates || key == :parent_link || key == :struct_xpath_prefix || key == :additional_smtlib
1616
+ next if key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
1595
1617
  if key == :validation_rules then
1596
1618
  result += value.keys
1597
1619
  else
@@ -2140,13 +2162,17 @@ end
2140
2162
 
2141
2163
  def introduce_parent_links(message, parent = nil, prefix = nil)
2142
2164
  if parent != nil then
2143
- message[:parent_link] = parent
2165
+ if message.has_key?(:parent_links) then
2166
+ message[:parent_links] << parent
2167
+ else
2168
+ message[:parent_links] = [parent]
2169
+ end
2144
2170
  end
2145
2171
  if prefix != nil then
2146
2172
  message[:struct_xpath_prefix] = prefix
2147
2173
  end
2148
2174
  message.each_pair do |key, value|
2149
- next if key == :validation_rules || key == :predicates || key == :parent_link || key == :struct_xpath_prefix || key == :additional_smtlib
2175
+ next if key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
2150
2176
  if value[:type] == :structure then
2151
2177
  if prefix then
2152
2178
  new_prefix = "#{prefix}/#{key}"
@@ -2180,7 +2206,7 @@ def validate_model(message, prefix=nil)
2180
2206
  puts "WARN: Model Problem: structure #{prefix}'s predicate #{mkey} does not have an SMTLIB representation. It will be regarded as always true."
2181
2207
  end
2182
2208
  end
2183
- elsif key == :parent_link || key == :struct_xpath_prefix || key == :additional_smtlib
2209
+ elsif key == :parent_links || key == :struct_xpath_prefix || key == :additional_smtlib
2184
2210
  next
2185
2211
  else
2186
2212
  if value[:type] == :structure then
@@ -2293,7 +2319,7 @@ end
2293
2319
 
2294
2320
  def validate_schema_against_doc_struct(struct, doc, prefix = nil)
2295
2321
  struct.each do |key, value|
2296
- next if key == :additional_smtlib || key == :validation_rules || key == :predicates || key == :parent_link || key == :struct_xpath_prefix
2322
+ next if key == :additional_smtlib || key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix
2297
2323
  if prefix then
2298
2324
  xpath = "#{prefix}/#{key}"
2299
2325
  else
@@ -2368,7 +2394,7 @@ def translate_struct_in_doc_to_SMTLIB(progress, solver, struct, doc, prefix, var
2368
2394
  config = hash[:config]
2369
2395
 
2370
2396
  struct.each do |key, value|
2371
- next if key == :additional_smtlib || key == :validation_rules || key == :predicates || key == :parent_link || key == :struct_xpath_prefix
2397
+ next if key == :additional_smtlib || key == :validation_rules || key == :predicates || key == :parent_links || key == :struct_xpath_prefix
2372
2398
  if prefix then
2373
2399
  xpath = "#{prefix}/#{key.to_s}"
2374
2400
  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.1
4
+ version: 0.0.14.3
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-05 00:00:00.000000000 Z
11
+ date: 2026-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri