expressir 2.4.6 → 2.4.8

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: ebd25bbedb1fd18428c86909c39a4aacce617d6d359368e175ee8887ecb8c078
4
+ data.tar.gz: 426c5afe759f7387c32cc10f060bfade8438e1133b525122f9948683661f2190
5
5
  SHA512:
6
- metadata.gz: f25c7bf185356ceaea4a9ac257683ef56db6f24923baa6f00e3a566b8e923de2b18500fa8e9b20173b4a83d90a94aa92a2f3fda2dc239fc0eba900bd713ea23d
7
- data.tar.gz: 0d310df7b81ada4f9a0a9c73a1e962c100af3082b9911d7c88430de01016a2566a2ff42e30f1b94b6a256c6bd50a5d05263c52e1ff667e0f3798d0958546ac0e
6
+ metadata.gz: 075a8aa23bc5ffee8d4ef04acbe84dce9da9413c4faaf31e3ec610d929f563a47476e4e09c755201f54ee9ac9191fcee28201772547411d9039433ed31a8fd07
7
+ data.tar.gz: c700a17fe91a024ede2e50857ec7e48698c189fd38ca47d15b196bc676a6c2cd1c337276adc947e49ed2ebf52501cc95009857524e5361d9d3f52f8c6a89f27e
@@ -0,0 +1,125 @@
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
+ # produces (the data layer of the STEP Module Resource Library
7
+ # document set, expressir #276 / TODO.parity-ee 15), built with
8
+ # moxml's node API — no hand-serialized XML strings.
9
+ #
10
+ # Per schema: downcased <schema> id, <schema_version> when
11
+ # present, per-kind count comments, <use_from> per interface
12
+ # (item-list marker), sorted <constant> names, then declarations
13
+ # in eeng's kind order (types, entities, subtype_constraints,
14
+ # functions, rules, procedures), alphabetical inside each kind,
15
+ # schema-qualified names; ARM mode upcases entity names.
16
+ #
17
+ # format — one document with an <smrl> root, one <schema>
18
+ # element per repository schema.
19
+ # format_schema — a standalone document whose root is the schema
20
+ # element (the per-file fragment eeng emits).
21
+ module SmrlXml
22
+ module_function
23
+
24
+ def format(repository, mode: :resource)
25
+ schemas = repository.respond_to?(:schemas) ? repository.schemas : Array(repository)
26
+ ctx = Moxml::Context.new
27
+ doc = ctx.create_document
28
+ root = doc.create_element("smrl")
29
+ doc.add_child(root)
30
+ schemas.each { |schema| root.add_child(schema_element(doc, schema, mode)) }
31
+ doc.to_xml
32
+ end
33
+
34
+ def format_schema(schema, mode: :resource)
35
+ ctx = Moxml::Context.new
36
+ doc = ctx.create_document
37
+ doc.add_child(schema_element(doc, schema, mode))
38
+ doc.to_xml
39
+ end
40
+
41
+ def schema_element(doc, schema, mode)
42
+ element = doc.create_element("schema")
43
+ element.add_child(doc.create_text(schema.id.downcase))
44
+ if schema.version&.value
45
+ version = doc.create_element("schema_version")
46
+ version.add_child(doc.create_text(schema.version.value))
47
+ element.add_child(version)
48
+ end
49
+ counts = declaration_counts(schema)
50
+ %i[type entity function procedure rule subtype_constraint].each do |kind|
51
+ label = kind.to_s.split("_").map(&:upcase).join("_")
52
+ element.add_child(doc.create_comment(Kernel.format("%-19s %4d",
53
+ label, counts[kind])))
54
+ end
55
+ interfaces(schema).each do |iface|
56
+ items = iface.items.to_a.empty? ? "" : "(...)"
57
+ add_text_element(doc, element, "use-from",
58
+ "#{iface.schema.id.downcase}#{items}")
59
+ end
60
+ constants(schema).each do |decl|
61
+ add_text_element(doc, element, "constant", decl.id.downcase)
62
+ end
63
+ declarations(schema).each do |kind, decls|
64
+ tag = kind.to_s.tr("_", "-")
65
+ decls.each do |decl|
66
+ add_text_element(doc, element, tag,
67
+ "#{schema.id}.#{name_for(kind, decl.id, mode)}")
68
+ end
69
+ end
70
+ element
71
+ end
72
+
73
+ def add_text_element(doc, parent, tag, text)
74
+ node = doc.create_element(tag)
75
+ node.add_child(doc.create_text(text))
76
+ parent.add_child(node)
77
+ end
78
+
79
+ # eeng's entity casing: ARM mode upcases entity names; every
80
+ # other kind and mode is downcased.
81
+ def name_for(kind, id, mode)
82
+ kind == :entity && mode == :arm ? id.upcase : id.downcase
83
+ end
84
+
85
+ def declaration_counts(schema)
86
+ {
87
+ type: schema.types.to_a.size,
88
+ entity: schema.entities.to_a.size,
89
+ function: schema.functions.to_a.size,
90
+ procedure: schema.procedures.to_a.size,
91
+ rule: schema.rules.to_a.size,
92
+ subtype_constraint: schema.subtype_constraints.to_a.size,
93
+ }
94
+ end
95
+
96
+ def interfaces(schema)
97
+ Array(schema.interfaces)
98
+ end
99
+
100
+ def constants(schema)
101
+ schema.constants.to_a.sort_by(&:id)
102
+ end
103
+
104
+ # eeng order: types, entities, subtype_constraints, functions,
105
+ # rules, procedures — alphabetical (byte order) inside each.
106
+ COLL_BY_KIND = {
107
+ types: :type,
108
+ entities: :entity,
109
+ subtype_constraints: :subtype_constraint,
110
+ functions: :function,
111
+ rules: :rule,
112
+ procedures: :procedure,
113
+ }.freeze
114
+
115
+ def declarations(schema)
116
+ COLL_BY_KIND.filter_map do |coll, kind|
117
+ decls = schema.public_send(coll).to_a.sort_by(&:id)
118
+ next if decls.empty?
119
+
120
+ [kind, decls]
121
+ end
122
+ end
123
+ end
124
+ end
125
+ 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.8".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.8
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