interscript 2.4.5 → 3.0.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 +4 -4
- data/README.md +15 -0
- data/docs/demo/20191118-interscript-demo-cast.gif +0 -0
- data/exe/codemod-imp-to-isc +5 -0
- data/exe/diagnose_parse_failures +47 -0
- data/exe/interscript +2 -1
- data/exe/verify_isc_deep +211 -0
- data/exe/verify_isc_equivalence +128 -0
- data/interscript.gemspec +27 -20
- data/lib/interscript/command.rb +21 -12
- data/lib/interscript/compiler/javascript.rb +34 -35
- data/lib/interscript/compiler/json_ir.rb +214 -0
- data/lib/interscript/compiler/python.rb +354 -0
- data/lib/interscript/compiler/ruby.rb +23 -22
- data/lib/interscript/compiler.rb +20 -3
- data/lib/interscript/detector.rb +14 -7
- data/lib/interscript/dsl/aliases.rb +1 -1
- data/lib/interscript/dsl/document.rb +6 -3
- data/lib/interscript/dsl/group/parallel.rb +1 -1
- data/lib/interscript/dsl/group.rb +18 -9
- data/lib/interscript/dsl/items.rb +28 -16
- data/lib/interscript/dsl/metadata.rb +19 -18
- data/lib/interscript/dsl/stage.rb +1 -1
- data/lib/interscript/dsl/symbol_mm.rb +4 -2
- data/lib/interscript/dsl/tests.rb +1 -1
- data/lib/interscript/dsl.rb +21 -13
- data/lib/interscript/interpreter.rb +32 -21
- data/lib/interscript/isc/codemod.rb +791 -0
- data/lib/interscript/isc/document_builder.rb +354 -0
- data/lib/interscript/isc/generator.rb +191 -0
- data/lib/interscript/isc/grammar/concerns/aliases.rb +29 -0
- data/lib/interscript/isc/grammar/concerns/dependencies.rb +23 -0
- data/lib/interscript/isc/grammar/concerns/items.rb +176 -0
- data/lib/interscript/isc/grammar/concerns/metadata.rb +142 -0
- data/lib/interscript/isc/grammar/concerns/primitives.rb +112 -0
- data/lib/interscript/isc/grammar/concerns/stages.rb +129 -0
- data/lib/interscript/isc/grammar/concerns/system.rb +37 -0
- data/lib/interscript/isc/grammar/concerns/tests.rb +31 -0
- data/lib/interscript/isc/grammar/concerns.rb +18 -0
- data/lib/interscript/isc/grammar/core.rb +23 -0
- data/lib/interscript/isc/grammar/isc.artifact.json +1 -0
- data/lib/interscript/isc/grammar/isc.parg +196 -0
- data/lib/interscript/isc/grammar.rb +12 -0
- data/lib/interscript/isc/items.rb +185 -0
- data/lib/interscript/isc/model/alias.rb +20 -0
- data/lib/interscript/isc/model/constraint.rb +20 -0
- data/lib/interscript/isc/model/dependency.rb +19 -0
- data/lib/interscript/isc/model/document.rb +31 -0
- data/lib/interscript/isc/model/item.rb +50 -0
- data/lib/interscript/isc/model/rule.rb +23 -0
- data/lib/interscript/isc/model/stage.rb +20 -0
- data/lib/interscript/isc/model/stage_item.rb +33 -0
- data/lib/interscript/isc/model/test.rb +21 -0
- data/lib/interscript/isc/model.rb +19 -0
- data/lib/interscript/isc/node_adapter.rb +310 -0
- data/lib/interscript/isc/normalizer.rb +127 -0
- data/lib/interscript/isc/parser.rb +78 -0
- data/lib/interscript/isc/serializer.rb +248 -0
- data/lib/interscript/isc/transform.rb +138 -0
- data/lib/interscript/isc/yaml_bridge.rb +236 -0
- data/lib/interscript/isc.rb +30 -0
- data/lib/interscript/ml/byt5_onnx.rb +102 -0
- data/lib/interscript/ml/imf.rb +182 -0
- data/lib/interscript/ml/model.rb +52 -0
- data/lib/interscript/ml/provisioning.rb +189 -0
- data/lib/interscript/ml/translator.rb +38 -0
- data/lib/interscript/ml/vocab.rb +48 -0
- data/lib/interscript/ml.rb +25 -0
- data/lib/interscript/node/alias_def.rb +5 -5
- data/lib/interscript/node/dependency.rb +7 -7
- data/lib/interscript/node/document.rb +10 -10
- data/lib/interscript/node/group.rb +11 -9
- data/lib/interscript/node/item/alias.rb +14 -10
- data/lib/interscript/node/item/any.rb +14 -7
- data/lib/interscript/node/item/capture.rb +14 -9
- data/lib/interscript/node/item/group.rb +22 -17
- data/lib/interscript/node/item/repeat.rb +3 -3
- data/lib/interscript/node/item/stage.rb +4 -5
- data/lib/interscript/node/item/string.rb +18 -13
- data/lib/interscript/node/item.rb +27 -17
- data/lib/interscript/node/metadata.rb +6 -5
- data/lib/interscript/node/rule/funcall.rb +4 -5
- data/lib/interscript/node/rule/run.rb +4 -5
- data/lib/interscript/node/rule/sub.rb +55 -55
- data/lib/interscript/node/rule.rb +6 -5
- data/lib/interscript/node/stage.rb +11 -14
- data/lib/interscript/node/tests.rb +6 -6
- data/lib/interscript/node.rb +14 -17
- data/lib/interscript/stdlib/functions/rababa_adapter.rb +56 -0
- data/lib/interscript/stdlib/functions/secryst_adapter.rb +37 -0
- data/lib/interscript/stdlib/functions.rb +49 -0
- data/lib/interscript/stdlib.rb +25 -95
- data/lib/interscript/utils/helpers.rb +8 -5
- data/lib/interscript/utils/regexp_converter.rb +143 -144
- data/lib/interscript/version.rb +1 -1
- data/lib/interscript/visualize/json.rb +12 -13
- data/lib/interscript/visualize/nodes.rb +13 -13
- data/lib/interscript/visualize.rb +18 -18
- data/lib/interscript.rb +59 -45
- metadata +88 -31
- data/.github/workflows/assets.yml +0 -91
- data/.github/workflows/rake.yml +0 -52
- data/.github/workflows/release.yml +0 -68
- data/.gitignore +0 -79
- data/.rspec +0 -3
- data/Gemfile +0 -38
- data/Rakefile +0 -139
- data/bin/console +0 -10
- data/bin/interscript +0 -5
- data/bin/maps_analyze_staging +0 -168
- data/bin/maps_debug_compilers +0 -58
- data/bin/maps_debug_ordering +0 -88
- data/bin/maps_debug_ruby_compile +0 -24
- data/bin/maps_debug_step_by_step +0 -44
- data/bin/maps_optimize_order +0 -112
- data/bin/maps_v1_analyze_regexps +0 -45
- data/bin/maps_v1_to_v2 +0 -426
- data/bin/set_version +0 -16
- data/bin/setup +0 -8
- data/requirements.txt +0 -1
|
@@ -1,54 +1,60 @@
|
|
|
1
1
|
module Interscript::DSL::Items
|
|
2
2
|
include Interscript::DSL::SymbolMM
|
|
3
3
|
|
|
4
|
+
# standard:disable Style/MissingRespondToMissing (DSL method_missing catches unknown method names by design)
|
|
4
5
|
def method_missing sym, *args, **kwargs, &block
|
|
6
|
+
# standard:enable Style/MissingRespondToMissing
|
|
5
7
|
super if args.length > 0
|
|
6
8
|
super if kwargs.length > 0
|
|
7
|
-
super if
|
|
8
|
-
super unless
|
|
9
|
+
super if /[?!=]\z/.match?(sym.to_s)
|
|
10
|
+
super unless /\A[\w\d]+\z/.match?(sym.to_s)
|
|
9
11
|
super if block_given?
|
|
10
12
|
|
|
11
13
|
Interscript::Node::Item::Alias.new(sym)
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
def any(*chars)
|
|
15
|
-
puts "any(#{chars.inspect}) from #{
|
|
17
|
+
puts "any(#{chars.inspect}) from #{inspect}" if $DEBUG
|
|
16
18
|
Interscript::Node::Item::Any.new(*chars)
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
# a?
|
|
20
22
|
def maybe(*chars)
|
|
21
|
-
puts "maybe(#{chars.inspect}) from #{
|
|
23
|
+
puts "maybe(#{chars.inspect}) from #{inspect}" if $DEBUG
|
|
22
24
|
Interscript::Node::Item::Maybe.new(*chars)
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
def maybe_some(*chars)
|
|
26
|
-
puts "maybe_some(#{chars.inspect}) from #{
|
|
28
|
+
puts "maybe_some(#{chars.inspect}) from #{inspect}" if $DEBUG
|
|
27
29
|
Interscript::Node::Item::MaybeSome.new(*chars)
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
def some(*chars)
|
|
31
|
-
puts "some(#{chars.inspect}) from #{
|
|
33
|
+
puts "some(#{chars.inspect}) from #{inspect}" if $DEBUG
|
|
32
34
|
Interscript::Node::Item::Some.new(*chars)
|
|
33
35
|
end
|
|
34
36
|
|
|
35
37
|
# (...)
|
|
36
38
|
def capture(expr)
|
|
37
|
-
puts "capture(#{expr.inspect}) from #{
|
|
39
|
+
puts "capture(#{expr.inspect}) from #{inspect}" if $DEBUG
|
|
38
40
|
Interscript::Node::Item::CaptureGroup.new(expr)
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
# \1
|
|
42
44
|
def ref(int)
|
|
43
|
-
puts "ref(#{int.inspect}) from #{
|
|
45
|
+
puts "ref(#{int.inspect}) from #{inspect}" if $DEBUG
|
|
44
46
|
Interscript::Node::Item::CaptureRef.new(int)
|
|
45
47
|
end
|
|
46
48
|
|
|
47
49
|
# Implementation of `map.x`
|
|
48
|
-
def map
|
|
50
|
+
def map
|
|
51
|
+
Interscript::DSL::Items::Maps
|
|
52
|
+
end
|
|
49
53
|
|
|
50
54
|
# Implementation of `stage.x`
|
|
51
|
-
def stage
|
|
55
|
+
def stage
|
|
56
|
+
Stages.new
|
|
57
|
+
end
|
|
52
58
|
|
|
53
59
|
# Implementation of `map.x`
|
|
54
60
|
module Maps
|
|
@@ -58,32 +64,38 @@ module Interscript::DSL::Items
|
|
|
58
64
|
Symbol === map or raise Interscript::MapLogicError, "A map name must be a Symbol, not #{alias_name.class}"
|
|
59
65
|
Map.new(map)
|
|
60
66
|
end
|
|
61
|
-
|
|
67
|
+
alias_method :method_missing, :[]
|
|
62
68
|
end
|
|
63
69
|
end
|
|
64
70
|
|
|
65
71
|
# Implementation of `map.x.aliasname` and `map.x.stage.stagename`
|
|
66
72
|
class Map
|
|
67
|
-
def initialize name
|
|
73
|
+
def initialize name
|
|
74
|
+
@name = name
|
|
75
|
+
end
|
|
68
76
|
|
|
69
77
|
# Implementation of `map.x.aliasname`
|
|
70
78
|
def [] alias_name
|
|
71
79
|
Symbol === alias_name or raise Interscript::MapLogicError, "An alias name must be a Symbol, not #{alias_name.class}"
|
|
72
80
|
Interscript::Node::Item::Alias.new(alias_name, map: @name)
|
|
73
81
|
end
|
|
74
|
-
|
|
82
|
+
alias_method :method_missing, :[]
|
|
75
83
|
|
|
76
84
|
# Implementation of `map.x.stage.stagename`
|
|
77
|
-
def stage
|
|
85
|
+
def stage
|
|
86
|
+
Stages.new(@name)
|
|
87
|
+
end
|
|
78
88
|
end
|
|
79
89
|
|
|
80
90
|
# Implementation of `map.x.stage.stagename` and `stage.stagename`
|
|
81
91
|
class Stages
|
|
82
|
-
def initialize map
|
|
92
|
+
def initialize map = nil
|
|
93
|
+
@map = map
|
|
94
|
+
end
|
|
83
95
|
|
|
84
96
|
def [] stage
|
|
85
97
|
Interscript::Node::Item::Stage.new(stage, map: @map)
|
|
86
98
|
end
|
|
87
|
-
|
|
99
|
+
alias_method :method_missing, :[]
|
|
88
100
|
end
|
|
89
101
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "date"
|
|
2
2
|
|
|
3
3
|
class Interscript::DSL::Metadata
|
|
4
4
|
attr_accessor :node
|
|
@@ -7,27 +7,29 @@ class Interscript::DSL::Metadata
|
|
|
7
7
|
raise Interscript::MapLogicError, "Can't evaluate metadata from Ruby context" unless yaml
|
|
8
8
|
@map_name = map_name
|
|
9
9
|
@node = Interscript::Node::MetaData.new
|
|
10
|
-
|
|
10
|
+
instance_exec(&block)
|
|
11
11
|
@node[:nonstandard] = {}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
unless library
|
|
14
|
+
NECESSARY_KEYS.each do |i|
|
|
15
|
+
unless @node.data.key? i
|
|
16
|
+
warn "[#{@map_name}] Necessary key #{i} wasn't defined. Defaulting to an empty string"
|
|
17
|
+
@node[i] = ""
|
|
18
|
+
end
|
|
17
19
|
end
|
|
18
|
-
end
|
|
20
|
+
end
|
|
19
21
|
end
|
|
20
22
|
|
|
21
|
-
STANDARD_STRING_KEYS = %i
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
STANDARD_STRING_KEYS = %i[authority_id id
|
|
24
|
+
language source_script destination_script
|
|
25
|
+
name creation_date adoption_date description
|
|
26
|
+
character source confirmation_date original_description]
|
|
25
27
|
|
|
26
|
-
STANDARD_ARRAY_KEYS = %i
|
|
28
|
+
STANDARD_ARRAY_KEYS = %i[notes implementation_notes original_notes url]
|
|
27
29
|
|
|
28
|
-
NONSTANDARD_KEYS = %i
|
|
29
|
-
|
|
30
|
-
NECESSARY_KEYS = %i
|
|
30
|
+
NONSTANDARD_KEYS = %i[special_rules]
|
|
31
|
+
|
|
32
|
+
NECESSARY_KEYS = %i[name language source_script destination_script]
|
|
31
33
|
|
|
32
34
|
STANDARD_STRING_KEYS.each do |sym|
|
|
33
35
|
define_method sym do |stuff|
|
|
@@ -35,6 +37,7 @@ class Interscript::DSL::Metadata
|
|
|
35
37
|
when String, Integer, Date
|
|
36
38
|
@node[sym] = stuff.to_s
|
|
37
39
|
when NilClass
|
|
40
|
+
nil # accepted silently
|
|
38
41
|
else
|
|
39
42
|
warn "[#{@map_name}] Metadata key #{sym} expects a String, but #{stuff.class} was given"
|
|
40
43
|
@node[sym] = stuff.inspect
|
|
@@ -44,9 +47,7 @@ class Interscript::DSL::Metadata
|
|
|
44
47
|
|
|
45
48
|
STANDARD_ARRAY_KEYS.each do |sym|
|
|
46
49
|
define_method sym do |stuff|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
stuff.map do |i|
|
|
50
|
+
@node[sym] = Array(stuff).map do |i|
|
|
50
51
|
case i
|
|
51
52
|
when String
|
|
52
53
|
i
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
module Interscript::DSL::SymbolMM
|
|
2
|
+
# standard:disable Style/MissingRespondToMissing (DSL method_missing catches unknown method names by design)
|
|
2
3
|
def method_missing sym, *args, **kwargs, &block
|
|
4
|
+
# standard:enable Style/MissingRespondToMissing
|
|
3
5
|
super if args.length > 0
|
|
4
6
|
super if kwargs.length > 0
|
|
5
|
-
super if
|
|
6
|
-
super unless
|
|
7
|
+
super if /[?!=]\z/.match?(sym.to_s)
|
|
8
|
+
super unless /\A[\w\d]+\z/.match?(sym.to_s)
|
|
7
9
|
super if block_given?
|
|
8
10
|
|
|
9
11
|
sym.to_sym
|
data/lib/interscript/dsl.rb
CHANGED
|
@@ -39,9 +39,15 @@ module Interscript::DSL
|
|
|
39
39
|
raise e
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
|
+
# ISC documents route through the ISC parser, not the .imp DSL.
|
|
43
|
+
# The parse is expensive (the whole grammar over the map) — cache it like
|
|
44
|
+
# the .imp path does, or every transliterate call re-parses the map.
|
|
45
|
+
return @cache[map_name] = Interscript::Compiler.parse_isc(path) if path.end_with?(".isc")
|
|
46
|
+
|
|
42
47
|
library = path.end_with?(".iml")
|
|
43
48
|
|
|
44
|
-
map_name = File.basename(path, ".
|
|
49
|
+
map_name = File.basename(path, ".isc")
|
|
50
|
+
map_name = File.basename(map_name, ".imp")
|
|
45
51
|
map_name = File.basename(map_name, ".iml")
|
|
46
52
|
|
|
47
53
|
ruby = []
|
|
@@ -52,7 +58,7 @@ module Interscript::DSL
|
|
|
52
58
|
|
|
53
59
|
md_reading = false
|
|
54
60
|
md_indent = nil
|
|
55
|
-
|
|
61
|
+
nil
|
|
56
62
|
file.each do |l|
|
|
57
63
|
if md_reading && l =~ /\A#{md_indent}\}\s*\z/
|
|
58
64
|
md_reading = false
|
|
@@ -73,7 +79,7 @@ module Interscript::DSL
|
|
|
73
79
|
obj = Interscript::DSL::Document.new(map_name)
|
|
74
80
|
obj.instance_eval ruby, exc_fname, 1
|
|
75
81
|
|
|
76
|
-
yaml = if
|
|
82
|
+
yaml = if /\A\s*\z/.match?(yaml)
|
|
77
83
|
{}
|
|
78
84
|
else
|
|
79
85
|
unsafe_load = if YAML.respond_to? :unsafe_load
|
|
@@ -85,7 +91,7 @@ module Interscript::DSL
|
|
|
85
91
|
end
|
|
86
92
|
|
|
87
93
|
md = Interscript::DSL::Metadata.new(yaml: true, map_name: map_name, library: library) do
|
|
88
|
-
yaml.each do |k,v|
|
|
94
|
+
yaml.each do |k, v|
|
|
89
95
|
public_send(k.to_sym, v)
|
|
90
96
|
end
|
|
91
97
|
end
|
|
@@ -95,12 +101,14 @@ module Interscript::DSL
|
|
|
95
101
|
end
|
|
96
102
|
end
|
|
97
103
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
module Interscript::DSL
|
|
105
|
+
# Autoload all DSL modules (OCP: new DSL section = one autoload).
|
|
106
|
+
autoload :SymbolMM, "interscript/dsl/symbol_mm"
|
|
107
|
+
autoload :Items, "interscript/dsl/items"
|
|
108
|
+
autoload :Document, "interscript/dsl/document"
|
|
109
|
+
autoload :Group, "interscript/dsl/group"
|
|
110
|
+
autoload :Stage, "interscript/dsl/stage"
|
|
111
|
+
autoload :Metadata, "interscript/dsl/metadata"
|
|
112
|
+
autoload :Tests, "interscript/dsl/tests"
|
|
113
|
+
autoload :Aliases, "interscript/dsl/aliases"
|
|
114
|
+
end
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
class Interscript::Interpreter < Interscript::Compiler
|
|
2
2
|
attr_accessor :map
|
|
3
|
-
def compile(map, _:nil)
|
|
3
|
+
def compile(map, _: nil)
|
|
4
4
|
@map = map
|
|
5
5
|
self
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
-
def call(str, stage
|
|
8
|
+
def call(str, stage = :main, each: false, &block)
|
|
9
9
|
stage = @map.stages[stage]
|
|
10
|
-
s =
|
|
11
10
|
if each
|
|
12
11
|
e = Enumerator.new do |yielder|
|
|
13
12
|
options = []
|
|
@@ -20,9 +19,13 @@ class Interscript::Interpreter < Interscript::Compiler
|
|
|
20
19
|
result = nil
|
|
21
20
|
|
|
22
21
|
f = Fiber.new do
|
|
22
|
+
# standard:disable Style/GlobalVars (deliberate $DEBUG / -d-flag debug idiom)
|
|
23
23
|
$select_nth_string = true
|
|
24
|
+
# standard:enable Style/GlobalVars
|
|
24
25
|
result = Stage.new(@map, str).execute_rule(stage)
|
|
26
|
+
# standard:disable Style/GlobalVars (deliberate $DEBUG / -d-flag debug idiom)
|
|
25
27
|
$select_nth_string = false
|
|
28
|
+
# standard:enable Style/GlobalVars
|
|
26
29
|
Fiber.yield(:end)
|
|
27
30
|
end
|
|
28
31
|
|
|
@@ -35,7 +38,7 @@ class Interscript::Interpreter < Interscript::Compiler
|
|
|
35
38
|
# unsure how it can be handled.
|
|
36
39
|
#
|
|
37
40
|
# This scenario is described in a commented out test.
|
|
38
|
-
|
|
41
|
+
_, value, _ = f.resume
|
|
39
42
|
if options_set
|
|
40
43
|
f.resume(choices[i][iter])
|
|
41
44
|
else
|
|
@@ -49,7 +52,7 @@ class Interscript::Interpreter < Interscript::Compiler
|
|
|
49
52
|
options_set = true
|
|
50
53
|
|
|
51
54
|
opts = options.map { |i| (0...i).to_a }
|
|
52
|
-
choices = opts[0].product(*opts[1
|
|
55
|
+
choices = opts[0].product(*opts[1..])
|
|
53
56
|
end
|
|
54
57
|
|
|
55
58
|
yielder.yield(result)
|
|
@@ -82,10 +85,12 @@ class Interscript::Interpreter < Interscript::Compiler
|
|
|
82
85
|
if r.cached_tree
|
|
83
86
|
@str = Interscript::Stdlib.parallel_replace_tree(@str, r.cached_tree)
|
|
84
87
|
elsif r.subs_regexp && r.subs_replacements
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
# standard:disable Style/GlobalVars (deliberate $DEBUG / -d-flag debug idiom)
|
|
89
|
+
@str = if $DEBUG_RE
|
|
90
|
+
# standard:enable Style/GlobalVars
|
|
91
|
+
Interscript::Stdlib.parallel_regexp_gsub_debug(@str, r.subs_regexp, r.subs_replacements)
|
|
87
92
|
else
|
|
88
|
-
|
|
93
|
+
Interscript::Stdlib.parallel_regexp_gsub(@str, r.subs_regexp, r.subs_replacements)
|
|
89
94
|
end
|
|
90
95
|
else
|
|
91
96
|
begin
|
|
@@ -100,7 +105,7 @@ class Interscript::Interpreter < Interscript::Compiler
|
|
|
100
105
|
next if i.reverse_run == true
|
|
101
106
|
subs_array << [build_item(i.from, :par), build_item(i.to, :parstr)]
|
|
102
107
|
end
|
|
103
|
-
tree = Interscript::Stdlib.parallel_replace_compile_tree(subs_array)
|
|
108
|
+
tree = Interscript::Stdlib.parallel_replace_compile_tree(subs_array) # .sort_by{|k,v| -k.length})
|
|
104
109
|
@str = Interscript::Stdlib.parallel_replace_tree(@str, tree)
|
|
105
110
|
r.cached_tree = tree
|
|
106
111
|
# $using_tree = true
|
|
@@ -115,9 +120,13 @@ class Interscript::Interpreter < Interscript::Compiler
|
|
|
115
120
|
end
|
|
116
121
|
r.subs_regexp = Interscript::Stdlib.parallel_regexp_compile(subs_array)
|
|
117
122
|
r.subs_replacements = subs_array.map(&:last)
|
|
123
|
+
# standard:disable Style/GlobalVars (deliberate $DEBUG / -d-flag debug idiom)
|
|
118
124
|
if $DEBUG_RE
|
|
125
|
+
# standard:enable Style/GlobalVars
|
|
119
126
|
# puts subs_array.inspect
|
|
127
|
+
# standard:disable Style/GlobalVars (deliberate $DEBUG / -d-flag debug idiom)
|
|
120
128
|
$subs_array = subs_array
|
|
129
|
+
# standard:enable Style/GlobalVars
|
|
121
130
|
@str = Interscript::Stdlib.parallel_regexp_gsub_debug(@str, r.subs_regexp, r.subs_replacements)
|
|
122
131
|
else
|
|
123
132
|
@str = Interscript::Stdlib.parallel_regexp_gsub(@str, r.subs_regexp, r.subs_replacements)
|
|
@@ -129,12 +138,12 @@ class Interscript::Interpreter < Interscript::Compiler
|
|
|
129
138
|
execute_rule(t)
|
|
130
139
|
end
|
|
131
140
|
when Interscript::Node::Rule::Sub
|
|
132
|
-
if r.to == :upcase
|
|
133
|
-
@str
|
|
141
|
+
@str = if r.to == :upcase
|
|
142
|
+
@str.gsub(Regexp.new(build_regexp(r)), &:upcase)
|
|
134
143
|
elsif r.to == :downcase
|
|
135
|
-
@str
|
|
144
|
+
@str.gsub(Regexp.new(build_regexp(r)), &:downcase)
|
|
136
145
|
else
|
|
137
|
-
@str
|
|
146
|
+
@str.gsub(Regexp.new(build_regexp(r)), build_item(r.to, :str))
|
|
138
147
|
end
|
|
139
148
|
when Interscript::Node::Rule::Funcall
|
|
140
149
|
@str = Interscript::Stdlib::Functions.public_send(r.name, @str, **r.kwargs)
|
|
@@ -168,12 +177,12 @@ class Interscript::Interpreter < Interscript::Compiler
|
|
|
168
177
|
re
|
|
169
178
|
end
|
|
170
179
|
|
|
171
|
-
def build_item i, target=nil, doc
|
|
180
|
+
def build_item i, target = nil, doc = @map
|
|
172
181
|
i = i.nth_string if %i[str parstr].include? target
|
|
173
182
|
i = Interscript::Node::Item.try_convert(i)
|
|
174
183
|
target = :par if target == :parstr
|
|
175
184
|
|
|
176
|
-
|
|
185
|
+
case i
|
|
177
186
|
when Interscript::Node::Item::Alias
|
|
178
187
|
if i.map
|
|
179
188
|
d = doc.dep_aliases[i.map].document
|
|
@@ -193,14 +202,14 @@ class Interscript::Interpreter < Interscript::Compiler
|
|
|
193
202
|
when Interscript::Node::Item::String
|
|
194
203
|
if [:str, :par].include? target
|
|
195
204
|
i.data
|
|
196
|
-
else#if target == :re
|
|
205
|
+
else # if target == :re
|
|
197
206
|
Regexp.escape(i.data)
|
|
198
207
|
end
|
|
199
208
|
when Interscript::Node::Item::Group
|
|
200
209
|
if target == :par
|
|
201
210
|
i.children.map do |j|
|
|
202
211
|
build_item(j, target, doc)
|
|
203
|
-
end.reduce([""]) do |j,k|
|
|
212
|
+
end.reduce([""]) do |j, k|
|
|
204
213
|
Array(j).product(Array(k)).map(&:join)
|
|
205
214
|
end
|
|
206
215
|
else
|
|
@@ -215,9 +224,9 @@ class Interscript::Interpreter < Interscript::Compiler
|
|
|
215
224
|
Interscript::Node::Item::MaybeSome,
|
|
216
225
|
Interscript::Node::Item::Some
|
|
217
226
|
|
|
218
|
-
resuffix = {
|
|
219
|
-
|
|
220
|
-
|
|
227
|
+
resuffix = {Interscript::Node::Item::Maybe => "?",
|
|
228
|
+
Interscript::Node::Item::Some => "+",
|
|
229
|
+
Interscript::Node::Item::MaybeSome => "*"}[i.class]
|
|
221
230
|
|
|
222
231
|
if target == :par
|
|
223
232
|
raise Interscript::SystemConversionError, "Can't use a MaybeSome in a #{target} context"
|
|
@@ -242,7 +251,7 @@ class Interscript::Interpreter < Interscript::Compiler
|
|
|
242
251
|
case i.value
|
|
243
252
|
when Array
|
|
244
253
|
data = i.data.map { |j| build_item(j, target, doc) }
|
|
245
|
-
"(?:"+data.join("|")+")"
|
|
254
|
+
"(?:" + data.join("|") + ")"
|
|
246
255
|
when String
|
|
247
256
|
"[#{Regexp.escape(i.value)}]"
|
|
248
257
|
when Range
|
|
@@ -252,4 +261,6 @@ class Interscript::Interpreter < Interscript::Compiler
|
|
|
252
261
|
end
|
|
253
262
|
end
|
|
254
263
|
end
|
|
264
|
+
# standard:disable Layout/TrailingEmptyLines (deliberate)
|
|
255
265
|
end
|
|
266
|
+
# standard:enable Layout/TrailingEmptyLines
|