interscript 3.4.0 → 3.6.0

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: 4eb31ebccf84ad17a8c5ec38431c2368e8e96bf925aa4b80b2014ceb7f5a5b4c
4
- data.tar.gz: 7922c008dc6d3b4eea5243dcd12b79ed377a80e91096282d1c7cf13cd48a6069
3
+ metadata.gz: cc9a8df80d338a068fc92f722262f2b9d6893926f662dfa521925a8b15b178ad
4
+ data.tar.gz: 42e5b322a91e15cb99c62ddccd744001dcaf6265fe138b523bda2c1f7e89c1ee
5
5
  SHA512:
6
- metadata.gz: 1c0bd6f3b49ba673e7fdc181e815c634464d7bebb6522f0b6ce57dfa87845653495b6a8f5c18ff20890fbed841295688cdd848ecfda7f978962d7f2b1acb0821
7
- data.tar.gz: 54e5bdf832a5fe40c2cde82e7f5b3a915da598f75bae1db8f688e37df6c1c508dfc7ad6909a72dd3b298219521b23e65084387bad7db9afd7ae5a4e94c77aeb2
6
+ metadata.gz: 3b9e9d7e06ba30a84620868d05db1e3c275cdb78ced061fa884b50aead036522c5fcfe7e0de6131e53dcb12debcc356a5d917fca8f8dc7f6de275e93a53e774d
7
+ data.tar.gz: 26277cd1c1dd6328815ab4f5d171ee76052ebc82f03af506734d4ffb0ea31440f6eff90c11f3ad5fafabcb9fcc56a9126840b58253090c482ed5333fdf45a4ee
@@ -35,6 +35,12 @@ class Interscript::DSL::Group
35
35
  end
36
36
 
37
37
  Interscript::Stdlib.available_functions.each do |fun|
38
+ # upcase stays the to-symbol builder (`sub "a", upcase`): the
39
+ # Interpreter special-cases `to == :upcase` on the compiled rule,
40
+ # and dsl_stage_spec pins that path. The ISC surface's upcase
41
+ # directive does not go through this DSL.
42
+ next if fun == :upcase
43
+
38
44
  define_method fun do |**kwargs|
39
45
  puts "funcall(#{fun}, #{kwargs.inspect}) from #{inspect}" if $DEBUG
40
46
 
@@ -6,7 +6,12 @@ class Interscript::Interpreter < Interscript::Compiler
6
6
  end
7
7
 
8
8
  def call(str, stage = :main, each: false, language: nil, &block)
9
+ stage_name = stage
9
10
  stage = @map.stages[stage]
11
+ # WO18 G4 (parity audit): a missing stage used to crash with an
12
+ # accidental NoMethodError (nil flowed into execute_rule). rs's
13
+ # named error is canon.
14
+ raise Interscript::MapLogicError, %(stage "#{stage_name}" not found in #{@map.name}) unless stage
10
15
  if each
11
16
  e = Enumerator.new do |yielder|
12
17
  options = []
@@ -203,12 +208,17 @@ class Interscript::Interpreter < Interscript::Compiler
203
208
  when Interscript::Node::Rule::Funcall
204
209
  @str = Interscript::Stdlib::Functions.public_send(r.name, @str, **r.kwargs)
205
210
  when Interscript::Node::Rule::Run
211
+ # WO18 G4 (parity audit): a missing run-target stage used to
212
+ # crash with `NoMethodError undefined method 'reverse_run' for
213
+ # nil`; raise the named error instead (rs canon).
206
214
  if r.stage.map
207
215
  doc = @map.dep_aliases[r.stage.map].document
208
216
  stage = doc.imported_stages[r.stage.name]
217
+ raise Interscript::MapLogicError, %(stage "#{r.stage.name}" not found in #{doc.name}) unless stage
209
218
  @str = Stage.new(doc, @str, language: @language).execute_rule(stage)
210
219
  else
211
220
  stage = @map.imported_stages[r.stage.name]
221
+ raise Interscript::MapLogicError, %(stage "#{r.stage.name}" not found in #{@map.name}) unless stage
212
222
  @str = Stage.new(@map, @str, language: @language).execute_rule(stage)
213
223
  end
214
224
  end
@@ -52,7 +52,15 @@ module Interscript
52
52
  languages_arr.concat(Array(item[:languages]).map { |l| ident(l) })
53
53
  elsif item[:ruleset]
54
54
  # ISC-WF-1 W1: named ruleset declaration.
55
- rulesets_arr << extract_ruleset(item)
55
+ rs = extract_ruleset(item)
56
+ # WO18 G7 (py canon): a duplicate declaration is a load
57
+ # error - keep-first hides map bugs and makes the executed
58
+ # body declaration-order dependent (rs #19, ts #138).
59
+ if rulesets_arr.any? { |existing| existing[:name] == rs[:name] }
60
+ raise Interscript::MapLogicError,
61
+ %(ruleset "#{rs[:name]}" declared more than once in #{@filename})
62
+ end
63
+ rulesets_arr << rs
56
64
  elsif item[:stage]
57
65
  stages_arr << extract_stage(item)
58
66
  elsif item[:target]
@@ -279,9 +287,9 @@ module Interscript
279
287
  def extract_stage_items(n)
280
288
  return [] unless n.is_a?(Hash)
281
289
  if n[:sequence]
282
- [{kind: :sequence, rules: filter_noop(Array(n[:sequence]).map { |r| extract_rule(r) })}]
290
+ [{kind: :sequence, rules: filter_noop(Array(n[:sequence]).map { |r| extract_stage_row(r) })}]
283
291
  elsif n[:parallel]
284
- [{kind: :parallel, rules: filter_noop(Array(n[:parallel]).map { |r| extract_rule(r) })}]
292
+ [{kind: :parallel, rules: filter_noop(Array(n[:parallel]).map { |r| extract_stage_row(r) })}]
285
293
  elsif n[:separate]
286
294
  [{kind: :separate, separator: n[:separator] ? materialize(n[:separator]) : nil}]
287
295
  elsif n[:compose]
@@ -314,15 +322,26 @@ module Interscript
314
322
  end
315
323
  end
316
324
 
325
+ # WO18 G5: one rule-line entry of a parallel/sequence block — a
326
+ # rule def, or (since §3.2) a `use` directive splicing into the
327
+ # block's rule list.
328
+ def extract_stage_row(r)
329
+ return extract_use(r[:use]) if r.is_a?(Hash) && r.key?(:use)
330
+ extract_rule(r)
331
+ end
332
+
317
333
  # `use <name>` (same-map ruleset) or `use <dep>.<name>` (dependency-
318
334
  # declared ruleset), plus the optional override rows (W2).
319
335
  def extract_use(u)
320
336
  dep = u[:qualified_name] ? ident(u[:use_alias]) : nil
321
337
  name = ident(u[:qualified_name] || u[:use_alias])
322
338
  item = {kind: :use, ruleset: name, dependency: dep}
339
+ # WO18 G5: override rows are rule_line items, so they may
340
+ # themselves be `use` directives — carried as nested use defs and
341
+ # flattened at expansion time (rs extract_rule_list recursion).
323
342
  overrides = Array(u[:use_overrides])
324
- .select { |r| r.is_a?(Hash) && r.key?(:from) }
325
- .map { |r| extract_rule(r) }
343
+ .select { |r| r.is_a?(Hash) && (r.key?(:from) || r.key?(:use)) }
344
+ .map { |r| r.key?(:use) ? extract_use(r[:use]) : extract_rule(r) }
326
345
  item[:overrides] = overrides if overrides.any?
327
346
  item
328
347
  end
@@ -121,7 +121,10 @@ module Interscript
121
121
  end
122
122
 
123
123
  rule(:rule_line) do
124
- whitespace? >> (rule | comment_item) >> whitespace?
124
+ # ISC-WF-1 #3.2: a `use` directive is a rule-line item - items
125
+ # inside a parallel/sequence block participate in that block's
126
+ # single pass (mirrors rs grammar/isc.parg rule_line).
127
+ whitespace? >> (rule | use_directive | comment_item) >> whitespace?
125
128
  end
126
129
 
127
130
  # A rule is either compact form (single line) or block form
@@ -153,7 +153,11 @@ grammar InterscriptIsc version "0.1.0" {
153
153
  rule = block_rule / compact_rule
154
154
 
155
155
  comment_item = (("#" *(!%x0A chr)) as comment) / ((!(keyword) identifier) as noop)
156
- rule_line = [ws] (rule / comment_item) [ws]
156
+ # ISC-WF-1 §3.2: a `use` directive is a rule-line item — items inside a
157
+ # parallel/sequence block participate in that block's single pass, and
158
+ # the expansion flattens the referenced ruleset's rules at this
159
+ # position (mirrors interscript-rs grammar/isc.parg rule_line).
160
+ rule_line = [ws] (rule / use_directive / comment_item) [ws]
157
161
  rule_items = *(rule_line)
158
162
  sequence_block = "sequence" [ws] "{" [ws] (rule_items as sequence) [ws] "}"
159
163
  parallel_block = "parallel" [ws] "{" [ws] (rule_items as parallel) [ws] "}"
@@ -163,10 +163,10 @@ module Interscript
163
163
  case item[:kind]
164
164
  when :parallel
165
165
  group = Interscript::Node::Group::Parallel.new
166
- item[:rules].each { |r| group.children << build_rule(r) }
166
+ item[:rules].each { |r| group.children.push(*build_stage_row(r)) }
167
167
  [group]
168
168
  when :sequence
169
- item[:rules].map { |r| build_rule(r) }
169
+ item[:rules].flat_map { |r| build_stage_row(r) }
170
170
  when :bare_rule
171
171
  [build_rule(item[:rule])]
172
172
  when :run
@@ -213,6 +213,61 @@ module Interscript
213
213
  apply_overrides(deep_copy_children(rs.children), item[:overrides])
214
214
  end
215
215
 
216
+ # WO18 G5 — `use` inside a parallel/sequence block (spec §3.2):
217
+ # the expansion inherits the enclosing pass structure — the target's
218
+ # rule content flattens into the enclosing collection. Non-rule
219
+ # items (funcalls, stage runs) cannot join a pass — named error
220
+ # (interscript-rs resolve_use_rules).
221
+ def expand_use_flat(item)
222
+ rs = resolve_ruleset(item[:dependency], item[:ruleset])
223
+ rules = flatten_rules(rs.children)
224
+ if item[:overrides]
225
+ o_rules = item[:overrides].flat_map { |r| build_override_row(r) }
226
+ rules = merge_override_rules(rules, o_rules)
227
+ end
228
+ rules
229
+ end
230
+
231
+ # One flattened row of a parallel/sequence block (§3.2): `use` rows
232
+ # splice the referenced ruleset's rules; rule rows build directly.
233
+ # Both builders return ARRAYS: a use row expands to possibly
234
+ # several flattened rules (spec §3.2), a rule row to itself.
235
+ def build_stage_row(row)
236
+ (row.is_a?(Hash) && row[:kind] == :use) ? expand_use_flat(row) : [build_rule(row)]
237
+ end
238
+
239
+ def build_override_row(row)
240
+ (row.is_a?(Hash) && row[:kind] == :use) ? expand_use_flat(row) : [build_rule(row)]
241
+ end
242
+
243
+ def flatten_rules(children)
244
+ children.flat_map do |node|
245
+ case node
246
+ when Interscript::Node::Group
247
+ node.children
248
+ when Interscript::Node::Rule::Sub
249
+ node
250
+ else
251
+ raise(Interscript::MapLogicError,
252
+ "use inside a parallel/sequence block: the referenced ruleset carries " \
253
+ "non-rule items (funcalls/stage runs) that cannot join the pass")
254
+ end
255
+ end
256
+ end
257
+
258
+ # §4.2 merge over a FLAT rule list (the block-position use):
259
+ # matching rules drop wherever they sit (child-wins on exact
260
+ # from-equality); the override rules land at the expansion tail.
261
+ # No trailing-parallel join here — the caller re-wraps the list
262
+ # into the enclosing block's structure.
263
+ def merge_override_rules(rules, o_rules)
264
+ o_keys = o_rules.map { |r| from_key(r) }
265
+ kept = rules.reject do |r|
266
+ r.is_a?(Interscript::Node::Rule::Sub) && o_keys.include?(from_key(r))
267
+ end
268
+ kept + o_rules
269
+ end
270
+
216
271
  # The fully-expanded Node::Ruleset for a reference, memoized.
217
272
  # Same-map rulesets build here; dependency rulesets arrive already
218
273
  # built through the recursive adapter of the dependency document.
@@ -293,7 +348,9 @@ module Interscript
293
348
  def apply_overrides(children, overrides)
294
349
  return children if overrides.nil? || overrides.empty?
295
350
 
296
- o_rules = overrides.map { |r| build_rule(r) }
351
+ # WO18 G5: an override row may itself be a `use` directive; its
352
+ # content flattens into the override list (rs extract_rule_list).
353
+ o_rules = overrides.flat_map { |r| build_override_row(r) }
297
354
  o_keys = o_rules.map { |r| from_key(r) }
298
355
 
299
356
  kept = children.filter_map do |node|
@@ -66,12 +66,28 @@ module Interscript
66
66
  class ParseError < StandardError
67
67
  attr_reader :filename, :source
68
68
 
69
+ # Parsanol's expected-set dumps can run to hundreds of characters
70
+ # (WO18 G9); the message keeps the position and the first few
71
+ # alternatives — rs/ts/py give compact line:col pointers.
72
+ MAX_EXPECTED = 6
73
+
69
74
  def initialize(message, filename:, source:, cause: nil)
70
75
  @filename = filename
71
76
  @source = source
72
77
  @cause = cause
73
78
  loc = filename ? "#{filename}: " : ""
74
- super("#{loc}#{message}")
79
+ super("#{loc}#{self.class.trim_expected(message)}")
80
+ end
81
+
82
+ def self.trim_expected(message)
83
+ message.sub(/expected one of \[([^\]]*)\]/) do
84
+ items = Regexp.last_match(1).split(", ")
85
+ if items.length > MAX_EXPECTED
86
+ "expected one of [#{items.first(MAX_EXPECTED).join(", ")} …(+#{items.length - MAX_EXPECTED} more)]"
87
+ else
88
+ Regexp.last_match(0)
89
+ end
90
+ end
75
91
  end
76
92
  end
77
93
  end
@@ -14,12 +14,15 @@ class Interscript::Node::Item::Alias < Interscript::Node::Item
14
14
  Interscript::Stdlib.boundary_like_alias?(name)
15
15
  end
16
16
 
17
+ # rs parity (WO17): the deterministic parallel sort counts every
18
+ # alias as 1 (0 for none) — rs Item::max_length treats Prim/Alias
19
+ # uniformly, and resolving the expansion here would need document
20
+ # context the sort site does not carry.
17
21
  def max_length
18
22
  if stdlib?
19
23
  [:none].include?(name) ? 0 : 1
20
24
  else
21
- return 1 if name == :unicode_hangul
22
- raise NotImplementedError, "can't get a max length of this alias"
25
+ 1
23
26
  end
24
27
  end
25
28
 
@@ -7,6 +7,13 @@ class Interscript::Node::Item::CaptureGroup < Interscript::Node::Item
7
7
  @data = data
8
8
  end
9
9
 
10
+ # rs parity (WO18 G1): the deterministic parallel sort needs a
11
+ # max_length on every Item. A capture's length is its innards'
12
+ # length (ts maxLengthOfItem: capture_group -> inner).
13
+ def max_length
14
+ data.max_length
15
+ end
16
+
10
17
  def first_string
11
18
  data.first_string
12
19
  end
@@ -45,6 +52,11 @@ class Interscript::Node::Item::CaptureRef < Interscript::Node::Item
45
52
  @id = id
46
53
  end
47
54
 
55
+ # rs parity (WO18 G1): a backreference matches one captured run.
56
+ def max_length
57
+ 1
58
+ end
59
+
48
60
  def first_string
49
61
  self
50
62
  end
@@ -18,6 +18,27 @@ class Interscript::Stdlib
18
18
  end
19
19
  end
20
20
 
21
+ # WO18 G8 (parity audit): the ISC surface's fn literals. upcase
22
+ # mirrors the ts/py/rs directive semantics (String#upcase); the ISC
23
+ # grammars carry reverse/strip/swapcase as fn literals too, so the
24
+ # Funcall dispatcher needs them (plain String semantics — no other
25
+ # runtime executes them yet).
26
+ def self.upcase(output, _: nil)
27
+ output.upcase
28
+ end
29
+
30
+ def self.reverse(output, _: nil)
31
+ output.reverse
32
+ end
33
+
34
+ def self.strip(output, _: nil)
35
+ output.strip
36
+ end
37
+
38
+ def self.swapcase(output, _: nil)
39
+ output.swapcase
40
+ end
41
+
21
42
  def self.compose(output, _: nil)
22
43
  output.unicode_normalize(:nfc)
23
44
  end
@@ -38,7 +59,12 @@ class Interscript::Stdlib
38
59
  SecrystAdapter.call(output, model: model)
39
60
  end
40
61
 
41
- def self.rababa(output, config:)
62
+ # A bare `rababa` directive (no config:) is a map-logic error — the
63
+ # grammar's kwargs are optional, and a Ruby ArgumentError here is
64
+ # accidental (WO18 G11; ts/py raise their named errors, rs rejects
65
+ # at load).
66
+ def self.rababa(output, config: nil)
67
+ raise Interscript::MapLogicError, "rababa requires config:" unless config
42
68
  RababaAdapter.call(output, config: config)
43
69
  end
44
70
 
@@ -176,7 +176,10 @@ class Interscript::Stdlib
176
176
  end
177
177
 
178
178
  def self.available_functions
179
- %i[title_case downcase compose decompose separate unseparate secryst rababa rababa_reverse]
179
+ # WO18 G8 (parity audit): the ISC fn literals upcase/reverse/strip/
180
+ # swapcase are part of the grammar surface; declare them alongside
181
+ # the classic set (Stdlib::Functions implements all four).
182
+ %i[title_case downcase upcase compose decompose separate unseparate reverse strip swapcase secryst rababa rababa_reverse]
180
183
  end
181
184
 
182
185
  def self.reverse_function
@@ -1,3 +1,3 @@
1
1
  module Interscript
2
- VERSION = "3.4.0"
2
+ VERSION = "3.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interscript
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-11 00:00:00.000000000 Z
11
+ date: 2026-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor