interscript 2.1.0 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -0
- data/Rakefile +9 -1
- data/bin/console +4 -8
- data/interscript.gemspec +2 -1
- data/lib/interscript.rb +78 -0
- data/lib/interscript/compiler/javascript.rb +6 -1
- data/lib/interscript/compiler/ruby.rb +5 -0
- data/lib/interscript/detector.rb +62 -0
- data/lib/interscript/dsl.rb +35 -2
- data/lib/interscript/dsl/document.rb +2 -1
- data/lib/interscript/dsl/group.rb +7 -6
- data/lib/interscript/dsl/group/parallel.rb +2 -2
- data/lib/interscript/dsl/tests.rb +2 -2
- data/lib/interscript/interpreter.rb +5 -1
- data/lib/interscript/node.rb +4 -0
- data/lib/interscript/node/alias_def.rb +6 -0
- data/lib/interscript/node/dependency.rb +16 -0
- data/lib/interscript/node/document.rb +34 -0
- data/lib/interscript/node/group.rb +13 -2
- data/lib/interscript/node/item.rb +4 -0
- data/lib/interscript/node/item/alias.rb +12 -0
- data/lib/interscript/node/item/any.rb +7 -0
- data/lib/interscript/node/item/capture.rb +11 -0
- data/lib/interscript/node/item/group.rb +29 -1
- data/lib/interscript/node/item/repeat.rb +4 -0
- data/lib/interscript/node/item/stage.rb +4 -0
- data/lib/interscript/node/item/string.rb +7 -0
- data/lib/interscript/node/metadata.rb +10 -0
- data/lib/interscript/node/rule.rb +3 -0
- data/lib/interscript/node/rule/funcall.rb +12 -2
- data/lib/interscript/node/rule/run.rb +16 -3
- data/lib/interscript/node/rule/sub.rb +165 -4
- data/lib/interscript/node/stage.rb +30 -4
- data/lib/interscript/node/tests.rb +10 -0
- data/lib/interscript/stdlib.rb +45 -3
- data/lib/interscript/utils/helpers.rb +39 -0
- data/lib/interscript/version.rb +1 -1
- data/lib/interscript/visualize/json.rb +12 -4
- metadata +17 -1
@@ -1,9 +1,11 @@
|
|
1
1
|
class Interscript::Node::Stage < Interscript::Node::Group::Sequential
|
2
|
-
attr_accessor :name, :doc_name
|
2
|
+
attr_accessor :name, :doc_name, :dont_reverse
|
3
3
|
|
4
|
-
def initialize
|
4
|
+
def initialize(name = :main, reverse_run: nil, doc_name: nil, dont_reverse: false)
|
5
5
|
@name = name
|
6
|
-
|
6
|
+
@doc_name = doc_name
|
7
|
+
@dont_reverse = dont_reverse
|
8
|
+
super(reverse_run: reverse_run)
|
7
9
|
end
|
8
10
|
|
9
11
|
def to_hash
|
@@ -12,8 +14,32 @@ class Interscript::Node::Stage < Interscript::Node::Group::Sequential
|
|
12
14
|
:children => @children.map{|x| x.to_hash} }
|
13
15
|
end
|
14
16
|
|
17
|
+
def reverse
|
18
|
+
return self if dont_reverse
|
19
|
+
|
20
|
+
@reverse ||= begin
|
21
|
+
self.class.new(name,
|
22
|
+
doc_name: Interscript::Node::Document.reverse_name(doc_name),
|
23
|
+
reverse_run: reverse_run.nil? ? nil : !reverse_run
|
24
|
+
).tap do |r|
|
25
|
+
r.children = self.children.reverse.map(&:reverse)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def ==(other)
|
31
|
+
super &&
|
32
|
+
self.name == other.name &&
|
33
|
+
self.reverse_run == other.reverse_run &&
|
34
|
+
self.dont_reverse == other.dont_reverse
|
35
|
+
end
|
36
|
+
|
15
37
|
def inspect
|
16
|
-
|
38
|
+
args = []
|
39
|
+
args << "#{@name}" if @name != :main
|
40
|
+
args << "dont_reverse: true" if dont_reverse
|
41
|
+
name = ""
|
42
|
+
name = "(#{args.join(", ")})" unless args.empty?
|
17
43
|
"stage#{name} {\n#{super}\n}"
|
18
44
|
end
|
19
45
|
end
|
@@ -8,6 +8,16 @@ class Interscript::Node::Tests < Interscript::Node
|
|
8
8
|
@data << pair
|
9
9
|
end
|
10
10
|
|
11
|
+
def reverse
|
12
|
+
self.class.new(data.map do |from,to,reverse_run|
|
13
|
+
[to, from, reverse_run == nil ? nil : !reverse_run]
|
14
|
+
end)
|
15
|
+
end
|
16
|
+
|
17
|
+
def ==(other)
|
18
|
+
super && self.data == other.data
|
19
|
+
end
|
20
|
+
|
11
21
|
def to_hash
|
12
22
|
{ :class => self.class.to_s,
|
13
23
|
:data => @data }
|
data/lib/interscript/stdlib.rb
CHANGED
@@ -22,6 +22,10 @@ class Interscript::Stdlib
|
|
22
22
|
! %i[none space].include?(a)
|
23
23
|
end
|
24
24
|
|
25
|
+
def self.boundary_like_alias?(a)
|
26
|
+
%i[line_start line_end string_start string_end boundary non_word_boundary].include?(a)
|
27
|
+
end
|
28
|
+
|
25
29
|
@treecache = {}
|
26
30
|
|
27
31
|
def self.parallel_regexp_compile(subs_hash)
|
@@ -167,7 +171,20 @@ class Interscript::Stdlib
|
|
167
171
|
end
|
168
172
|
|
169
173
|
def self.available_functions
|
170
|
-
%i[title_case downcase compose decompose separate secryst]
|
174
|
+
%i[title_case downcase compose decompose separate unseparate secryst rababa]
|
175
|
+
end
|
176
|
+
|
177
|
+
def self.reverse_function
|
178
|
+
{
|
179
|
+
title_case: :downcase, # Those two are best-effort,
|
180
|
+
downcase: :title_case, # but probably wrong.
|
181
|
+
|
182
|
+
compose: :decompose,
|
183
|
+
decompose: :compose,
|
184
|
+
|
185
|
+
separate: :unseparate,
|
186
|
+
unseparate: :separate
|
187
|
+
}
|
171
188
|
end
|
172
189
|
|
173
190
|
module Functions
|
@@ -177,8 +194,13 @@ class Interscript::Stdlib
|
|
177
194
|
output
|
178
195
|
end
|
179
196
|
|
180
|
-
def self.downcase(output,
|
181
|
-
|
197
|
+
def self.downcase(output, word_separator: nil)
|
198
|
+
if word_separator
|
199
|
+
output = output.gsub(/^(.)/, &:downcase)
|
200
|
+
output = output.gsub(/#{word_separator}(.)/, &:downcase) unless word_separator == ''
|
201
|
+
else
|
202
|
+
output.downcase
|
203
|
+
end
|
182
204
|
end
|
183
205
|
|
184
206
|
def self.compose(output, _:nil)
|
@@ -193,6 +215,10 @@ class Interscript::Stdlib
|
|
193
215
|
output.split("").join(separator)
|
194
216
|
end
|
195
217
|
|
218
|
+
def self.unseparate(output, separator: " ")
|
219
|
+
output.split(separator).join("")
|
220
|
+
end
|
221
|
+
|
196
222
|
@secryst_models = {}
|
197
223
|
def self.secryst(output, model:)
|
198
224
|
require "secryst" rescue nil # Try to load secryst, but don't fail hard if not possible.
|
@@ -207,5 +233,21 @@ class Interscript::Stdlib
|
|
207
233
|
@secryst_models[model].translate(i)
|
208
234
|
end.join("\n")
|
209
235
|
end
|
236
|
+
|
237
|
+
def self.rababa(output, config:)
|
238
|
+
require "rababa" rescue nil # Try to load rababa, but don't fail hard if not possible.
|
239
|
+
unless defined? Rababa
|
240
|
+
raise StandardError, "Rababa is not loaded. Please read docs/Usage_with_Rababa.adoc"
|
241
|
+
end
|
242
|
+
|
243
|
+
config_value = Interscript.rababa_configs[config]
|
244
|
+
model_uri = config_value['model']
|
245
|
+
rababa_config = config_value['config']
|
246
|
+
model_path = Interscript.rababa_provision(config, model_uri)
|
247
|
+
|
248
|
+
@rababa_diacritizer ||= Rababa::Diacritizer.new(model_path, rababa_config)
|
249
|
+
|
250
|
+
@rababa_diacritizer.diacritize_text(output)
|
251
|
+
end
|
210
252
|
end
|
211
253
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Interscript::Utils
|
2
|
+
module Helpers
|
3
|
+
def document name=nil, &block
|
4
|
+
$example_id ||= 0
|
5
|
+
$example_id += 1
|
6
|
+
name ||= "example-#{$example_id}"
|
7
|
+
|
8
|
+
Interscript::DSL::Document.new(name, &block).node.tap do |i|
|
9
|
+
$documents ||= {}
|
10
|
+
$documents[name] = i
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def stage &block
|
15
|
+
document {
|
16
|
+
stage(&block)
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Interscript::Node::Document
|
23
|
+
def call(str, stage=:main, compiler=$compiler || Interscript::Interpreter, **kwargs)
|
24
|
+
compiler.(self).(str, stage, **kwargs)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module Interscript::DSL
|
29
|
+
class << self
|
30
|
+
alias original_parse parse
|
31
|
+
def parse(map_name, **kwargs)
|
32
|
+
if $documents && $documents[map_name]
|
33
|
+
$documents[map_name]
|
34
|
+
else
|
35
|
+
original_parse(map_name, **kwargs)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/interscript/version.rb
CHANGED
@@ -10,6 +10,7 @@ class Interscript::Node::Group
|
|
10
10
|
more << "after: #{rule.after.to_html(map)}" if rule.after
|
11
11
|
more << "<nobr>not before:</nobr> #{rule.not_before.to_html(map)}" if rule.not_before
|
12
12
|
more << "<nobr>not after:</nobr> #{rule.not_after.to_html(map)}" if rule.not_after
|
13
|
+
more << "<nobr>reverse run:</nobr> #{rule.reverse_run}" unless rule.reverse_run.nil?
|
13
14
|
more = more.join(", ")
|
14
15
|
|
15
16
|
out << {
|
@@ -24,11 +25,14 @@ class Interscript::Node::Group
|
|
24
25
|
children: rule.to_visualization_array(map)
|
25
26
|
}
|
26
27
|
when Interscript::Node::Rule::Funcall
|
28
|
+
more = rule.kwargs.map do |k,v|
|
29
|
+
"#{k.to_s.gsub("_", " ")}: #{v}"
|
30
|
+
end
|
31
|
+
more << "<nobr>reverse run:</nobr> #{rule.reverse_run}" unless rule.reverse_run.nil?
|
32
|
+
|
27
33
|
out << {
|
28
34
|
type: rule.name.to_s.gsub("_", " ").gsub(/^(.)/, &:upcase),
|
29
|
-
more:
|
30
|
-
"#{k.to_s.gsub("_", " ")}: #{v}"
|
31
|
-
end.join(", ")
|
35
|
+
more: more.join(", ")
|
32
36
|
}
|
33
37
|
when Interscript::Node::Rule::Run
|
34
38
|
if rule.stage.map
|
@@ -39,10 +43,14 @@ class Interscript::Node::Group
|
|
39
43
|
stage = rule.stage.name
|
40
44
|
end
|
41
45
|
|
46
|
+
more = []
|
47
|
+
more << "<nobr>reverse run:</nobr> #{rule.reverse_run}" unless rule.reverse_run.nil?
|
48
|
+
|
42
49
|
out << {
|
43
50
|
type: "Run",
|
44
51
|
doc: doc.name,
|
45
|
-
stage: stage
|
52
|
+
stage: stage,
|
53
|
+
more: more.join(", "),
|
46
54
|
}
|
47
55
|
else
|
48
56
|
out << {
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: interscript
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
@@ -26,6 +26,20 @@ dependencies:
|
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: interscript-maps
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.3.0a
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.3.0a
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: text
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
@@ -70,6 +84,7 @@ files:
|
|
70
84
|
- lib/interscript/compiler.rb
|
71
85
|
- lib/interscript/compiler/javascript.rb
|
72
86
|
- lib/interscript/compiler/ruby.rb
|
87
|
+
- lib/interscript/detector.rb
|
73
88
|
- lib/interscript/dsl.rb
|
74
89
|
- lib/interscript/dsl/aliases.rb
|
75
90
|
- lib/interscript/dsl/document.rb
|
@@ -104,6 +119,7 @@ files:
|
|
104
119
|
- lib/interscript/node/stage.rb
|
105
120
|
- lib/interscript/node/tests.rb
|
106
121
|
- lib/interscript/stdlib.rb
|
122
|
+
- lib/interscript/utils/helpers.rb
|
107
123
|
- lib/interscript/utils/regexp_converter.rb
|
108
124
|
- lib/interscript/version.rb
|
109
125
|
- lib/interscript/visualize.rb
|