expressir 2.4.6 → 2.4.7

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
  SHA256:
3
- metadata.gz: d4cb3a63d16dd31f57a8050366d6b9d9d4e442d65e7df44c01f5edad8f330565
4
- data.tar.gz: f234902848350d1abbca9aef98c0ca2bd562fe19463a51e395ec53688ef4e72b
3
+ metadata.gz: a528340d87e1789ca193347d8da5562b8729d544778d5eda450f4991645244fe
4
+ data.tar.gz: 0b708a242f721723ac2dc22fad6077bdb788efbf16e47c70e0ecaa1741fee60a
5
5
  SHA512:
6
- metadata.gz: f25c7bf185356ceaea4a9ac257683ef56db6f24923baa6f00e3a566b8e923de2b18500fa8e9b20173b4a83d90a94aa92a2f3fda2dc239fc0eba900bd713ea23d
7
- data.tar.gz: 0d310df7b81ada4f9a0a9c73a1e962c100af3082b9911d7c88430de01016a2566a2ff42e30f1b94b6a256c6bd50a5d05263c52e1ff667e0f3798d0958546ac0e
6
+ metadata.gz: cb0061aba1f58ebde3e8fe84cf09b4f4579961504dd85e17fe2b8f60993d276553912a906412b5a129a03f5fc320262144d0dd3bdfcbff633d9aba2432b9550e
7
+ data.tar.gz: 7ad4621bcbe3534b796cfd9f5286491fc55ab97763e8be9e118ff8731ba3c273181a019bc0d96408a3edcc707f6f200c912ff3029313aeeb98453f93eb735650
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Expressir
4
+ module Express
5
+ # SMRL index XML writer — the shape eengine's wo-smrl-xml.lisp
6
+ # emits (the data layer of the STEP Module Resource Library
7
+ # document set, expressir #276 / TODO.parity-ee 15).
8
+ #
9
+ # Per schema, in eeng's exact layout:
10
+ # <schema>downcased_name</schema>
11
+ # <schema_version>...</schema_version> (when present)
12
+ # <!-- TYPE n --> ... count comments
13
+ # <use-from>schema(...)</use-from> (per interface)
14
+ # <constant>name</constant> (sorted)
15
+ # <type>SCHEMA.name</type> ... declarations in kind order
16
+ # (types, entities, subtype_constraints, functions, rules,
17
+ # procedures), alphabetical inside each kind. In ARM mode
18
+ # entity names keep their declared case upcased, matching
19
+ # eeng's ARM rendering.
20
+ module SmrlXml
21
+ module_function
22
+
23
+ # @param repository [Model::Repository, #schemas]
24
+ # @param mode [Symbol] :resource (default), :arm, :mim — the
25
+ # eeng -mode whose case conventions apply to entity names
26
+ # @return [String] the concatenated schema blocks
27
+ def format(repository, mode: :resource)
28
+ schemas = repository.respond_to?(:schemas) ? repository.schemas : Array(repository)
29
+ schemas.map { |schema| format_schema(schema, mode: mode) }.join
30
+ end
31
+
32
+ def format_schema(schema, mode: :resource)
33
+ out = +""
34
+ out << "<schema>#{schema.id.downcase}</schema>\n"
35
+ if schema.version&.value
36
+ out << " <schema_version>#{schema.version.value}</schema_version>\n"
37
+ end
38
+ counts = declaration_counts(schema)
39
+ %i[type entity function procedure rule subtype_constraint].each do |kind|
40
+ label = kind.to_s.split("_").map(&:upcase).join("_")
41
+ out << Kernel.format(" <!-- %-19s %4d -->\n", label, counts[kind])
42
+ end
43
+
44
+ interfaces(schema).each do |iface|
45
+ item_list = iface.items.to_a.empty? ? "" : "(...)"
46
+ out << " <use-from>#{iface.schema.id.downcase}#{item_list}</use-from>\n"
47
+ end
48
+
49
+ constants(schema).each do |decl|
50
+ out << " <constant>#{decl.id.downcase}</constant>\n"
51
+ end
52
+
53
+ declarations(schema).each do |kind, decls|
54
+ tag = kind.to_s.tr("_", "-")
55
+ decls.each do |decl|
56
+ out << " <#{tag}>#{schema.id}.#{name_for(kind, decl.id, mode)}</#{tag}>\n"
57
+ end
58
+ end
59
+ out
60
+ end
61
+
62
+ # eeng's entity casing: ARM mode upcases entity names; every
63
+ # other kind and mode is downcased.
64
+ def name_for(kind, id, mode)
65
+ kind == :entity && mode == :arm ? id.upcase : id.downcase
66
+ end
67
+
68
+ def declaration_counts(schema)
69
+ {
70
+ type: schema.types.to_a.size,
71
+ entity: schema.entities.to_a.size,
72
+ function: schema.functions.to_a.size,
73
+ procedure: schema.procedures.to_a.size,
74
+ rule: schema.rules.to_a.size,
75
+ subtype_constraint: schema.subtype_constraints.to_a.size,
76
+ }
77
+ end
78
+
79
+ def interfaces(schema)
80
+ Array(schema.interfaces)
81
+ end
82
+
83
+ def constants(schema)
84
+ schema.constants.to_a.sort_by(&:id)
85
+ end
86
+
87
+ # eeng order: types, entities, subtype_constraints, functions,
88
+ # rules, procedures — alphabetical (byte order) inside each.
89
+ COLL_BY_KIND = {
90
+ types: :type,
91
+ entities: :entity,
92
+ subtype_constraints: :subtype_constraint,
93
+ functions: :function,
94
+ rules: :rule,
95
+ procedures: :procedure,
96
+ }.freeze
97
+ private_constant :COLL_BY_KIND
98
+
99
+ def declarations(schema)
100
+ COLL_BY_KIND.filter_map do |coll, kind|
101
+ decls = schema.public_send(coll).to_a.sort_by(&:id)
102
+ next if decls.empty?
103
+
104
+ [kind, decls]
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -44,6 +44,7 @@ module Expressir
44
44
  "#{__dir__}/express/schema_plain_source_formatter"
45
45
  autoload :SchemaSourceFormatter, "#{__dir__}/express/schema_source_formatter"
46
46
  autoload :ScopeResolver, "#{__dir__}/express/scope_resolver"
47
+ autoload :SmrlXml, "#{__dir__}/express/smrl_xml"
47
48
  autoload :SourceFormatter, "#{__dir__}/express/source_formatter"
48
49
  autoload :StreamingBuilder, "#{__dir__}/express/streaming_builder"
49
50
  end
@@ -3,6 +3,6 @@ module Expressir
3
3
  # autoload it (Ruby autoload only works for module/class constants, not
4
4
  # for string constants like `Expressir::VERSION`).
5
5
  module Version
6
- VERSION = "2.4.6".freeze
6
+ VERSION = "2.4.7".freeze
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expressir
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.6
4
+ version: 2.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -523,6 +523,7 @@ files:
523
523
  - lib/expressir/express/scope_resolver.rb
524
524
  - lib/expressir/express/self_schema_reference.rb
525
525
  - lib/expressir/express/shtolo.rb
526
+ - lib/expressir/express/smrl_xml.rb
526
527
  - lib/expressir/express/source_formatter.rb
527
528
  - lib/expressir/express/streaming_builder.rb
528
529
  - lib/expressir/liquid.rb