interscript 3.7.2 → 3.7.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.
- checksums.yaml +4 -4
- data/lib/interscript/interpreter.rb +73 -4
- data/lib/interscript/isc/node_adapter.rb +55 -0
- data/lib/interscript/ml/imf.rb +1 -1
- data/lib/interscript/node/item.rb +7 -0
- data/lib/interscript/stdlib.rb +8 -3
- data/lib/interscript/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 44bc93ebdbe6a9feb41a595823019d7cd8ee2f012cd7884feef2ebb5ed77def1
|
|
4
|
+
data.tar.gz: aeb1ef704c6fd8019a539823a81ad4de559ca4f7e44bea3b99705e172b454826
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f7af0fdcd5e8c30e661502115900d75a48c787554785a3fd933ad5d7ad2c8eae7912122aca171bbb067d03ac66a7db309915c9087b85fa1f24e96336d88457e7
|
|
7
|
+
data.tar.gz: c88d8a31d191f9a70d8cc3a61be285c7c8baca064fb4eb802915343fa71dc06deb8e46254b6b597982a8f8ff2e15eccc01cb4262ccdf65c6518de59bdd5520f5
|
|
@@ -90,6 +90,35 @@ class Interscript::Interpreter < Interscript::Compiler
|
|
|
90
90
|
language.to_sym
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
+
# Does this replacement item carry a capture-ref template anywhere?
|
|
94
|
+
# (WO18 G1: ref templates fail loud and named in a parallel pass.)
|
|
95
|
+
def self.ref_template?(item)
|
|
96
|
+
case item
|
|
97
|
+
when Interscript::Node::Item::CaptureRef
|
|
98
|
+
true
|
|
99
|
+
when Interscript::Node::Item::Group
|
|
100
|
+
item.children.any? { |c| ref_template?(c) }
|
|
101
|
+
when Interscript::Node::Item::Repeat, Interscript::Node::Item::Maybe,
|
|
102
|
+
Interscript::Node::Item::Some, Interscript::Node::Item::MaybeSome,
|
|
103
|
+
Interscript::Node::Item::CaptureGroup
|
|
104
|
+
ref_template?(item.data)
|
|
105
|
+
else
|
|
106
|
+
false
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Does this rule pattern carry a `\N` backreference to a capture
|
|
111
|
+
# group the pattern itself does not define? Machine-generated rule
|
|
112
|
+
# patterns only: capture groups open with `(` not followed by `?`
|
|
113
|
+
# (lookarounds and `(?:` are not capture groups); backrefs are `\N`.
|
|
114
|
+
# Such a rule can never match (rs match_item fails a ref on an
|
|
115
|
+
# unparticipated group), so a megaregexp pass drops it instead of
|
|
116
|
+
# failing the combined compile (WO20 reverse-golden bgnpcgn-zho).
|
|
117
|
+
def self.backref_without_group?(pattern)
|
|
118
|
+
group_count = pattern.scan(/\((?!\?)/).size
|
|
119
|
+
pattern.scan(/\\(\d+)/).any? { |(n)| n.to_i > group_count }
|
|
120
|
+
end
|
|
121
|
+
|
|
93
122
|
class Stage
|
|
94
123
|
attr_reader :language
|
|
95
124
|
|
|
@@ -173,7 +202,42 @@ class Interscript::Interpreter < Interscript::Compiler
|
|
|
173
202
|
Interscript::Stdlib.deterministic_sort_by_max_length(r.children).each do |i| # rule.from.max_length gives somewhat better test results, why is that
|
|
174
203
|
raise Interscript::SystemConversionError, "Can't parallelize #{i.class}" unless Interscript::Node::Rule::Sub === i
|
|
175
204
|
next if i.reverse_run == true
|
|
176
|
-
|
|
205
|
+
pattern = build_regexp(i)
|
|
206
|
+
# A from-pattern backreference to a group the pattern does
|
|
207
|
+
# not itself define (reversed rules re-reference capture
|
|
208
|
+
# groups their reversal hoisted away — the WO20
|
|
209
|
+
# reverse-golden bgnpcgn-zho family) can never match: rs
|
|
210
|
+
# `match_item` fails the ref on an unparticipated group,
|
|
211
|
+
# and ruby's combined alternation refuses to compile the
|
|
212
|
+
# numbered ref next to the named-group wrappers at all.
|
|
213
|
+
# Drop the rule, mirroring the rs never-matches semantics.
|
|
214
|
+
next if Interscript::Interpreter.backref_without_group?(pattern)
|
|
215
|
+
# WO18 G1 canon: a ref TEMPLATE in a parallel pass fails
|
|
216
|
+
# loud and named (spec/isc/semantics_spec.rb pins it).
|
|
217
|
+
if Interscript::Interpreter.ref_template?(i.to)
|
|
218
|
+
raise Interscript::SystemConversionError,
|
|
219
|
+
"Can't use CaptureRef in parallel mode"
|
|
220
|
+
end
|
|
221
|
+
# The megaregexp replacement carries the STRING build
|
|
222
|
+
# (:str semantics — groups join, captures parenthesize,
|
|
223
|
+
# refs become \N), which is what rs `build_replacement`
|
|
224
|
+
# renders over the nth_string collapse. `build_item(:parstr)`
|
|
225
|
+
# demotes to the :par product build and returns ARRAYS for
|
|
226
|
+
# group `to`s — stringified as Ruby inspect into the
|
|
227
|
+
# output (the WO20 reverse-golden odni-pus family).
|
|
228
|
+
# rs also renders a sub's replacement LAZILY (only when
|
|
229
|
+
# the rule fires): a re-only alias in a reversed `to` —
|
|
230
|
+
# the boundary a word-boundary rule's reversal hoists onto
|
|
231
|
+
# the to side — must not poison the whole pass when the
|
|
232
|
+
# rule never matches (WO20 reverse-golden bgnpcgn-per /
|
|
233
|
+
# un-prs family). Defer the build to match time in that
|
|
234
|
+
# case.
|
|
235
|
+
begin
|
|
236
|
+
replacement = build_item(i.to, :str)
|
|
237
|
+
rescue Interscript::SystemConversionError
|
|
238
|
+
replacement = -> { build_item(i.to, :str) }
|
|
239
|
+
end
|
|
240
|
+
subs_array << [pattern, replacement]
|
|
177
241
|
end
|
|
178
242
|
r.subs_regexp = Interscript::Stdlib.parallel_regexp_compile(subs_array)
|
|
179
243
|
r.subs_replacements = subs_array.map(&:last)
|
|
@@ -296,10 +360,15 @@ class Interscript::Interpreter < Interscript::Compiler
|
|
|
296
360
|
if target == :par
|
|
297
361
|
raise Interscript::SystemConversionError, "Can't use a MaybeSome in a #{target} context"
|
|
298
362
|
end
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
363
|
+
# maps#292 (WO20 fuzz): the optionality suffix must bind to the
|
|
364
|
+
# WHOLE built body, not to its last atom — an unwrapped body like
|
|
365
|
+
# `(?:x|y|z)[1-3]` + `?` made only `[1-3]` optional and the rule
|
|
366
|
+
# silently never matched. Only a single-character string body is
|
|
367
|
+
# its own atomic unit and may skip the group.
|
|
368
|
+
if Interscript::Node::Item::String === i.data && i.data.data.length == 1
|
|
302
369
|
build_item(i.data, target, doc) + resuffix
|
|
370
|
+
else
|
|
371
|
+
"(?:" + build_item(i.data, target, doc) + ")" + resuffix
|
|
303
372
|
end
|
|
304
373
|
when Interscript::Node::Item::CaptureRef
|
|
305
374
|
if target == :par
|
|
@@ -379,6 +379,20 @@ module Interscript
|
|
|
379
379
|
end
|
|
380
380
|
|
|
381
381
|
def build_rule(rule_def)
|
|
382
|
+
# A capture reference whose capture group the from expression
|
|
383
|
+
# never opens is a named parse-time rejection (WO18 G8's
|
|
384
|
+
# fn-literal-in-from convention: a named MapLogicError, never an
|
|
385
|
+
# accidental exception — before the WO20 fix this exact surface
|
|
386
|
+
# crashed with a NameError, interscript-ruby#864). Paired refs
|
|
387
|
+
# stay legal: the geminate idiom `from capture(x) + ref(1)` is
|
|
388
|
+
# pinned by node_adapter_spec, and `to`-position refs (27 corpus
|
|
389
|
+
# maps) are unaffected. Whether unpaired refs should instead be
|
|
390
|
+
# a run-time error like ts/py/rs is the owner-held
|
|
391
|
+
# cross-runtime question from the fuzz triage.
|
|
392
|
+
if (unpaired = unpaired_capture_ref(rule_def[:from]))
|
|
393
|
+
raise Interscript::MapLogicError,
|
|
394
|
+
"ref(#{unpaired}) in from position has no matching capture group"
|
|
395
|
+
end
|
|
382
396
|
from = convert_item(rule_def[:from])
|
|
383
397
|
to = convert_item(rule_def[:to])
|
|
384
398
|
opts = {}
|
|
@@ -494,6 +508,47 @@ module Interscript
|
|
|
494
508
|
parts.reduce { |acc, part| acc + part }
|
|
495
509
|
end
|
|
496
510
|
|
|
511
|
+
# The highest capture-reference index the from expression has no
|
|
512
|
+
# capture group to point at, or nil when every ref is paired.
|
|
513
|
+
# Onigmo accepts any existing group number from any position
|
|
514
|
+
# (forward and nested refs included), so pairing is a count
|
|
515
|
+
# comparison: a ref(N) is valid iff the expression opens >= N
|
|
516
|
+
# capture groups (CaptureGroup is the only capturing wrapper in
|
|
517
|
+
# build_item; plain groups and repeats render non-capturing).
|
|
518
|
+
def unpaired_capture_ref(item)
|
|
519
|
+
refs = max_capture_ref(item)
|
|
520
|
+
return nil if refs.nil? || refs <= count_capture_groups(item)
|
|
521
|
+
refs
|
|
522
|
+
end
|
|
523
|
+
|
|
524
|
+
def max_capture_ref(item)
|
|
525
|
+
case item
|
|
526
|
+
when Items::Capture
|
|
527
|
+
item.index
|
|
528
|
+
when Items::Concat
|
|
529
|
+
item.parts.filter_map { |p| max_capture_ref(p) }.max
|
|
530
|
+
when Items::CaptureGroup, Items::Maybe, Items::Some
|
|
531
|
+
max_capture_ref(item.inner)
|
|
532
|
+
when Items::Set
|
|
533
|
+
item.chars.filter_map { |c| max_capture_ref(c) }.max
|
|
534
|
+
end
|
|
535
|
+
end
|
|
536
|
+
|
|
537
|
+
def count_capture_groups(item)
|
|
538
|
+
case item
|
|
539
|
+
when Items::CaptureGroup
|
|
540
|
+
1 + count_capture_groups(item.inner)
|
|
541
|
+
when Items::Concat
|
|
542
|
+
item.parts.sum { |p| count_capture_groups(p) }
|
|
543
|
+
when Items::Maybe, Items::Some
|
|
544
|
+
count_capture_groups(item.inner)
|
|
545
|
+
when Items::Set
|
|
546
|
+
item.chars.sum { |c| count_capture_groups(c) }
|
|
547
|
+
else
|
|
548
|
+
0
|
|
549
|
+
end
|
|
550
|
+
end
|
|
551
|
+
|
|
497
552
|
def convert_set(set)
|
|
498
553
|
Interscript::Node::Item::Any.new(
|
|
499
554
|
set.chars.map do |c|
|
data/lib/interscript/ml/imf.rb
CHANGED
|
@@ -14,7 +14,7 @@ module Interscript::ML
|
|
|
14
14
|
EOS_ID = 1
|
|
15
15
|
UNK_ID = 2
|
|
16
16
|
|
|
17
|
-
DEFAULT_INDEX_URL = "https://github.com/interscript/interscript-models/releases/download/index-
|
|
17
|
+
DEFAULT_INDEX_URL = "https://github.com/interscript/interscript-models/releases/download/index-v15/models-index.yaml"
|
|
18
18
|
|
|
19
19
|
class FormatError < StandardError; end
|
|
20
20
|
class RegistryError < StandardError; end
|
|
@@ -55,6 +55,13 @@ class Interscript::Node::Item
|
|
|
55
55
|
autoload :Any, "interscript/node/item/any"
|
|
56
56
|
autoload :Stage, "interscript/node/item/stage"
|
|
57
57
|
autoload :CaptureGroup, "interscript/node/item/capture"
|
|
58
|
+
# CaptureRef lives in the same file as CaptureGroup. It MUST have its
|
|
59
|
+
# own autoload entry: a map carrying only a to-position ref(1) (27
|
|
60
|
+
# corpus maps) references the constant without ever touching
|
|
61
|
+
# CaptureGroup, and without the entry it crashed with a NameError
|
|
62
|
+
# whenever no earlier parse had loaded the file by accident
|
|
63
|
+
# (interscript-ruby#864, WO20 fuzz campaign).
|
|
64
|
+
autoload :CaptureRef, "interscript/node/item/capture"
|
|
58
65
|
autoload :Repeat, "interscript/node/item/repeat"
|
|
59
66
|
# Maybe, MaybeSome, Some are subclasses of Repeat defined in
|
|
60
67
|
# the same file. Autoload points to repeat.rb which defines all of them.
|
data/lib/interscript/stdlib.rb
CHANGED
|
@@ -42,7 +42,11 @@ class Interscript::Stdlib
|
|
|
42
42
|
lm = Regexp.last_match
|
|
43
43
|
# Extract the match name
|
|
44
44
|
idx = lm.named_captures.compact.keys.first[1..].to_i
|
|
45
|
-
|
|
45
|
+
# A deferred replacement (a `to` whose parstr build raises
|
|
46
|
+
# eagerly — rs renders replacements only when a rule fires)
|
|
47
|
+
# builds now.
|
|
48
|
+
replacement = subs_hash[idx]
|
|
49
|
+
replacement.is_a?(Proc) ? replacement.call : replacement
|
|
46
50
|
end
|
|
47
51
|
end
|
|
48
52
|
|
|
@@ -63,11 +67,12 @@ class Interscript::Stdlib
|
|
|
63
67
|
# puts matched.inspect
|
|
64
68
|
# puts [lm.begin(matched), lm.end(matched)].inspect
|
|
65
69
|
idx = matched[1..].to_i
|
|
66
|
-
|
|
70
|
+
replacement = subs_array[idx]
|
|
71
|
+
debug_info = {begin: lm.begin(matched), end: lm.end(matched), idx: idx, result: replacement}
|
|
67
72
|
# standard:disable Style/GlobalVars (deliberate $DEBUG / -d-flag debug idiom)
|
|
68
73
|
$subs_matches << debug_info
|
|
69
74
|
# standard:enable Style/GlobalVars
|
|
70
|
-
|
|
75
|
+
replacement.is_a?(Proc) ? replacement.call : replacement
|
|
71
76
|
end
|
|
72
77
|
end
|
|
73
78
|
|
data/lib/interscript/version.rb
CHANGED
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.7.
|
|
4
|
+
version: 3.7.3
|
|
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
|
+
date: 2026-11-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: thor
|