expressir 2.4.14 → 2.4.15

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: ad3043a3dd1ac401e841249e3e081a7b3b6b3c3da99f6a9dbc136a127619ba49
4
- data.tar.gz: '085e25b6e9b97d53fc5207aa651b37b080557626c6971b60029b98749ff4db82'
3
+ metadata.gz: 714b13d808744a329002460e108fdb35f4a8fcf0d3095517cd241d411bce215e
4
+ data.tar.gz: 8cf66567212cc463ab351cd6e0cbb70ee63ec11ae2c0b31036cd3d0aff264384
5
5
  SHA512:
6
- metadata.gz: e92cca737def4e8432f30b98162262f83df7d81c719c7a1dd916173f65ff788c1145843e46131bfe7da5ef97e76c00a155215f7c4893befe7748601711438d93
7
- data.tar.gz: 88d3f1008222838323a843a1b9a7117bf1b09465fa453de4bfd21868137b16439a680165e527555099ae67884cb8a77c8a2068e92b113f34408444c314482583
6
+ metadata.gz: 1c13e1c4cdb0a551e86e2d557c6df01fc2a1b36e1ff536cd4afc6a2255c922d0bcb8252debdc600479514963b38b8482d41de118fb55933472ed173cca77e2aa
7
+ data.tar.gz: 3f4107ac13feea2a5fdc9d5659312e44af1c7288d957132a119fb1799df396f709ed5c9d82c970669ceda5e64238506abe412a4850c310b4e173f347c67cc31d
@@ -1,4 +1,5 @@
1
1
  require "find"
2
+ require "thor"
2
3
 
3
4
  module Expressir
4
5
  module Commands
@@ -42,8 +43,9 @@ module Expressir
42
43
  end
43
44
  end
44
45
  unless missing.empty?
45
- warn "expressir: schema(s) not found: #{missing.uniq.join(', ')}" \
46
- "#{resolver_hint(manifest, stepmod)}"
46
+ raise Thor::Error,
47
+ "expressir: schema(s) not found: #{missing.uniq.join(', ')}" \
48
+ "#{resolver_hint(manifest, stepmod)}"
47
49
  end
48
50
  seen.values.compact.uniq
49
51
  end
@@ -90,14 +92,37 @@ module Expressir
90
92
  return manifest_index(manifest) if manifest
91
93
  return stepmod_index(stepmod) if stepmod
92
94
 
93
- same_dir_index(root_path)
95
+ # Default: the file's own directory plus, when the root sits
96
+ # inside a STEPmod checkout, its enclosing `schemas/` tree —
97
+ # the layout wg12-step modules live in.
98
+ index = same_dir_index(root_path)
99
+ ancestor = ancestor_schemas_dir(root_path)
100
+ index.update(stepmod_index(File.dirname(ancestor))) if ancestor
101
+ index
102
+ end
103
+
104
+ # Nearest ancestor directory NAMED `schemas`, or nil.
105
+ def ancestor_schemas_dir(root_path)
106
+ dir = File.dirname(File.expand_path(root_path))
107
+ until dir == "/"
108
+ return dir if File.basename(dir) == "schemas"
109
+
110
+ dir = File.dirname(dir)
111
+ end
112
+ nil
94
113
  end
95
114
 
96
115
  def same_dir_index(root_path)
97
116
  dir = File.dirname(File.expand_path(root_path))
98
- Dir.glob(File.join(dir, "*.exp")).to_h do |p|
99
- [File.basename(p, ".exp").downcase, p]
117
+ h = {}
118
+ Dir.glob(File.join(dir, "*.exp")).each do |path|
119
+ # index by DECLARED schema name first (a file named arm.exp
120
+ # may declare schema m_arm), basename as fallback
121
+ declared = File.read(path)[/\bSCHEMA\s+(\w+)/i, 1]
122
+ h[declared.downcase] = path if declared
123
+ h[File.basename(path, ".exp").downcase] ||= path
100
124
  end
125
+ h
101
126
  end
102
127
 
103
128
  # Interface names declared by +source+. Remark text is stripped
@@ -290,7 +290,7 @@ module Expressir
290
290
  end
291
291
  end
292
292
 
293
- def each_reference(node, &)
293
+ def each_reference(node, &block)
294
294
  case node
295
295
  when Model::References::SimpleReference then yield node
296
296
  when Model::ModelElement
@@ -299,8 +299,8 @@ module Expressir
299
299
 
300
300
  value = node.public_send(attr)
301
301
  case value
302
- when Array then value.each { |item| each_reference(item, &) }
303
- when Model::ModelElement then each_reference(value, &)
302
+ when Array then value.each { |item| each_reference(item, &block) }
303
+ when Model::ModelElement then each_reference(value, &block)
304
304
  end
305
305
  end
306
306
  end
@@ -407,7 +407,7 @@ module Expressir
407
407
  end
408
408
  end
409
409
 
410
- def each_string(node, &)
410
+ def each_string(node, &block)
411
411
  case node
412
412
  when Model::Literals::String then yield node, node.value
413
413
  when Model::ModelElement
@@ -416,8 +416,8 @@ module Expressir
416
416
 
417
417
  value = node.public_send(attr)
418
418
  case value
419
- when Array then value.each { |item| each_string(item, &) }
420
- when Model::ModelElement then each_string(value, &)
419
+ when Array then value.each { |item| each_string(item, &block) }
420
+ when Model::ModelElement then each_string(value, &block)
421
421
  end
422
422
  end
423
423
  end
@@ -351,13 +351,17 @@ module Expressir
351
351
  end
352
352
  end
353
353
 
354
- # Every identifier a call site names, across the artifact's
355
- # surviving declarations: FunctionCall for functions and
356
- # ProcedureCall statements for procedures. (A zero-argument
357
- # function reference written bare is not represented as a
358
- # FunctionCall by the parser and is counted via any SimpleReference
359
- # miss — accepted v1 blind spot, see tranche notes.)
354
+ # Every identifier a call site or reference names, across the
355
+ # artifact's surviving declarations: FunctionCall for functions,
356
+ # ProcedureCall statements for procedures, and ANY SimpleReference
357
+ # naming a schema function/procedure — a zero-argument function
358
+ # used bare (`v < limit_value`) parses as a plain reference, not
359
+ # a FunctionCall, and dropping it would leave the longform with a
360
+ # dangling call. Over-retaining is safe: prune only decides what
361
+ # may be dropped.
360
362
  def called_ids(schema)
363
+ invocable = (schema.functions.to_a + schema.procedures.to_a)
364
+ .map { |d| d.id.safe_downcase }
361
365
  called = {}
362
366
  each_node(schema) do |node|
363
367
  id = nil
@@ -366,8 +370,10 @@ module Expressir
366
370
  id = node.function.is_a?(String) ? node.function : node.function&.id
367
371
  when Expressir::Model::Statements::ProcedureCall
368
372
  id = node.procedure.is_a?(String) ? node.procedure : node.procedure&.id
373
+ when Model::References::SimpleReference
374
+ id = node.id
369
375
  end
370
- called[id.safe_downcase] = true if id
376
+ called[id.safe_downcase] = true if id && invocable.include?(id.safe_downcase)
371
377
  end
372
378
  called
373
379
  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.14".freeze
6
+ VERSION = "2.4.15".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.14
4
+ version: 2.4.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.