interscript 0.1.4 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/Gemfile +29 -0
- data/LICENSE.adoc +31 -0
- data/README.md +3 -0
- data/Rakefile +53 -0
- data/bin/console +14 -0
- data/bin/interscript +3 -39
- data/bin/maps_analyze_staging +168 -0
- data/bin/maps_debug_compilers +58 -0
- data/bin/maps_debug_ordering +88 -0
- data/bin/maps_debug_ruby_compile +24 -0
- data/bin/maps_debug_step_by_step +44 -0
- data/bin/maps_optimize_order +112 -0
- data/bin/maps_v1_analyze_regexps +45 -0
- data/bin/maps_v1_to_v2 +426 -0
- data/exe/interscript +6 -0
- data/interscript.gemspec +31 -0
- data/lib/interscript.rb +76 -128
- data/lib/interscript/command.rb +6 -5
- data/lib/interscript/compiler.rb +22 -0
- data/lib/interscript/compiler/javascript.rb +292 -0
- data/lib/interscript/compiler/ruby.rb +262 -0
- data/lib/interscript/dsl.rb +67 -0
- data/lib/interscript/dsl/aliases.rb +23 -0
- data/lib/interscript/dsl/document.rb +46 -0
- data/lib/interscript/dsl/group.rb +45 -0
- data/lib/interscript/dsl/group/parallel.rb +6 -0
- data/lib/interscript/dsl/items.rb +89 -0
- data/lib/interscript/dsl/metadata.rb +26 -0
- data/lib/interscript/dsl/stage.rb +6 -0
- data/lib/interscript/dsl/symbol_mm.rb +11 -0
- data/lib/interscript/dsl/tests.rb +12 -0
- data/lib/interscript/interpreter.rb +251 -0
- data/lib/interscript/node.rb +25 -0
- data/lib/interscript/node/alias_def.rb +15 -0
- data/lib/interscript/node/dependency.rb +13 -0
- data/lib/interscript/node/document.rb +45 -0
- data/lib/interscript/node/group.rb +34 -0
- data/lib/interscript/node/group/parallel.rb +9 -0
- data/lib/interscript/node/group/sequential.rb +2 -0
- data/lib/interscript/node/item.rb +52 -0
- data/lib/interscript/node/item/alias.rb +42 -0
- data/lib/interscript/node/item/any.rb +61 -0
- data/lib/interscript/node/item/capture.rb +50 -0
- data/lib/interscript/node/item/group.rb +51 -0
- data/lib/interscript/node/item/repeat.rb +40 -0
- data/lib/interscript/node/item/stage.rb +23 -0
- data/lib/interscript/node/item/string.rb +51 -0
- data/lib/interscript/node/metadata.rb +18 -0
- data/lib/interscript/node/rule.rb +6 -0
- data/lib/interscript/node/rule/funcall.rb +18 -0
- data/lib/interscript/node/rule/run.rb +15 -0
- data/lib/interscript/node/rule/sub.rb +65 -0
- data/lib/interscript/node/stage.rb +19 -0
- data/lib/interscript/node/tests.rb +15 -0
- data/lib/interscript/stdlib.rb +211 -0
- data/lib/interscript/utils/regexp_converter.rb +283 -0
- data/lib/interscript/version.rb +1 -1
- data/requirements.txt +1 -0
- metadata +73 -223
- data/README.adoc +0 -297
- data/bin/rspec +0 -29
- data/lib/g2pwrapper.py +0 -34
- data/lib/interscript/mapping.rb +0 -125
- data/lib/model-7 +0 -0
- data/lib/tha-pt-b-7 +0 -0
- data/maps/acadsin-zho-Hani-Latn-2002.yaml +0 -38912
- data/maps/alalc-aze-Cyrl-Latn-1997.yaml +0 -141
- data/maps/alalc-bel-cyrl-latn-1997.yaml +0 -125
- data/maps/alalc-ben-Beng-Latn-2017.yaml +0 -130
- data/maps/alalc-bul-Cyrl-Latn-1997.yaml +0 -94
- data/maps/alalc-ell-Grek-Latn-1997.yaml +0 -625
- data/maps/alalc-ell-Grek-Latn-2010.yaml +0 -628
- data/maps/alalc-kat-Geok-Latn-1997.yaml +0 -112
- data/maps/alalc-kat-Geor-Latn-1997.yaml +0 -146
- data/maps/alalc-kor-Hang-Latn-1997.yaml +0 -94
- data/maps/alalc-mkd-Cyrl-Latn-2013.yaml +0 -103
- data/maps/alalc-mkd-cyrl-latn-1997.yaml +0 -114
- data/maps/alalc-rus-Cyrl-Latn-1997.yaml +0 -222
- data/maps/alalc-rus-Cyrl-Latn-2012.yaml +0 -162
- data/maps/alalc-srp-Cyrl-Latn-1997.yaml +0 -114
- data/maps/alalc-srp-cyrl-latn-2013.yaml +0 -135
- data/maps/alalc-ukr-Cyrl-Latn-1997.yaml +0 -141
- data/maps/alalc-ukr-Cyrl-Latn-2011.yaml +0 -16
- data/maps/apcbg-bul-Cyrl-Latn-1995.yaml +0 -283
- data/maps/bas-rus-Cyrl-Latn-2017-bss.yaml +0 -175
- data/maps/bas-rus-Cyrl-Latn-2017-oss.yaml +0 -169
- data/maps/bgn-jpn-Hrkt-Latn-1962.yaml +0 -294
- data/maps/bgn-kor-Hang-Latn-1943.yaml +0 -31
- data/maps/bgn-kor-Kore-Latn-1943.yaml +0 -31
- data/maps/bgna-bul-Cyrl-Latn-2006.yaml +0 -208
- data/maps/bgna-bul-Cyrl-Latn-2009.yaml +0 -208
- data/maps/bgnpcgn-arm-Armn-Latn-1981.yaml +0 -108
- data/maps/bgnpcgn-aze-Cyrl-Latn-1993.yaml +0 -104
- data/maps/bgnpcgn-bak-Cyrl-Latn-2007.yaml +0 -184
- data/maps/bgnpcgn-bel-cyrl-latn-1979.yaml +0 -285
- data/maps/bgnpcgn-bul-Cyrl-Latn-1952.yaml +0 -115
- data/maps/bgnpcgn-bul-Cyrl-Latn-2013.yaml +0 -38
- data/maps/bgnpcgn-chn-Hans-Latn-1979.yaml +0 -7456
- data/maps/bgnpcgn-ell-Grek-Latn-1962.yaml +0 -702
- data/maps/bgnpcgn-ell-Grek-Latn-1996.yaml +0 -20
- data/maps/bgnpcgn-jpn-Hrkt-Latn-1976.yaml +0 -257
- data/maps/bgnpcgn-kat-Geor-Latn-1981.yaml +0 -127
- data/maps/bgnpcgn-kat-Geor-Latn-2009.yaml +0 -43
- data/maps/bgnpcgn-kor-Hang-Latn-kn-1945.yaml +0 -253
- data/maps/bgnpcgn-kor-Hang-Latn-rok-2011.yaml +0 -48
- data/maps/bgnpcgn-kor-Kore-Latn-rok-2011.yaml +0 -48
- data/maps/bgnpcgn-mkd-Cyrl-Latn-1981.yaml +0 -159
- data/maps/bgnpcgn-mkd-Cyrl-Latn-2013.yaml +0 -190
- data/maps/bgnpcgn-per-Arab-Latn-1956.yaml +0 -93
- data/maps/bgnpcgn-rus-Cyrl-Latn-1947.yaml +0 -314
- data/maps/bgnpcgn-srp-Cyrl-Latn-2005.yaml +0 -166
- data/maps/bgnpcgn-ukr-Cyrl-Latn-1965.yaml +0 -163
- data/maps/bgnpcgn-ukr-Cyrl-Latn-2019.yaml +0 -208
- data/maps/by-bel-Cyrl-Latn-1998.yaml +0 -168
- data/maps/by-bel-Cyrl-Latn-2007.yaml +0 -115
- data/maps/elot-ell-Grek-Latn-743-1982-tl.yaml +0 -685
- data/maps/elot-ell-Grek-Latn-743-1982-ts.yaml +0 -681
- data/maps/elot-ell-Grek-Latn-743-2001-tl.yaml +0 -20
- data/maps/elot-ell-Grek-Latn-743-2001-ts.yaml +0 -32
- data/maps/ggg-kat-Geor-Latn-2002.yaml +0 -89
- data/maps/gki-bel-cyrl-latn-1992.yaml +0 -33
- data/maps/gki-bel-cyrl-latn-2000.yaml +0 -201
- data/maps/gost-rus-cyrl-latn-16876-71-1983.yaml +0 -186
- data/maps/hk-yue-Hani-Latn-1888.yaml +0 -38497
- data/maps/icao-bel-Cyrl-Latn-9303.yaml +0 -141
- data/maps/icao-bul-Cyrl-Latn-9303.yaml +0 -122
- data/maps/icao-heb-Hebr-Latn-9303.yaml +0 -151
- data/maps/icao-mkd-Cyrl-Latn-9303.yaml +0 -117
- data/maps/icao-per-Arab-Latn-9303.yaml +0 -104
- data/maps/icao-rus-Cyrl-Latn-9303.yaml +0 -118
- data/maps/icao-srp-Cyrl-Latn-9303.yaml +0 -117
- data/maps/icao-ukr-Cyrl-Latn-9303.yaml +0 -120
- data/maps/iso-ell-Grek-Latn-843-1997-t1.yaml +0 -610
- data/maps/iso-ell-Grek-Latn-843-1997-t2.yaml +0 -41
- data/maps/iso-jpn-Hrkt-Latn-3602-1989.yaml +0 -62
- data/maps/iso-rus-Cyrl-Latn-9-1995.yaml +0 -272
- data/maps/iso-tha-Thai-Latn-11940-1998.yaml +0 -109
- data/maps/kp-kor-Hang-Latn-2002.yaml +0 -901
- data/maps/lshk-yue-Hani-Latn-jyutping-1993.yaml +0 -44820
- data/maps/mext-jpn-Hrkt-Latn-1954.yaml +0 -411
- data/maps/moct-kor-Hang-Latn-2000.yaml +0 -803
- data/maps/mofa-jpn-Hrkt-Latn-1989.yaml +0 -541
- data/maps/mvd-bel-Cyrl-Latn-2008.yaml +0 -225
- data/maps/mvd-bel-Cyrl-Latn-2010.yaml +0 -63
- data/maps/mvd-rus-Cyrl-Latn-2008.yaml +0 -110
- data/maps/mvd-rus-Cyrl-Latn-2010.yaml +0 -37
- data/maps/nil-kor-Hang-Hang-jamo.yaml +0 -11193
- data/maps/odni-bel-Cyrl-Latn-2015.yaml +0 -148
- data/maps/odni-bul-Cyrl-Latn-2015.yaml +0 -96
- data/maps/odni-kat-Geor-Latn-2015.yaml +0 -88
- data/maps/odni-rus-Cyrl-Latn-2015.yaml +0 -77
- data/maps/odni-srp-Cyrl-Latn-2015.yaml +0 -129
- data/maps/odni-ukr-Cyrl-Latn-2015.yaml +0 -157
- data/maps/odni-uzb-Cyrl-Latn-2015.yaml +0 -167
- data/maps/royin-tha-Thai-Latn-1939-generic.yaml +0 -90
- data/maps/royin-tha-Thai-Latn-1968.yaml +0 -179
- data/maps/royin-tha-Thai-Latn-1999-chained.yaml +0 -180
- data/maps/royin-tha-Thai-Latn-1999.yaml +0 -76
- data/maps/sac-zho-Hans-Latn-1979.yaml +0 -24759
- data/maps/stategeocadastre-ukr-Cyrl-Latn-1993.yaml +0 -222
- data/maps/ua-ukr-Cyrl-Latn-1996.yaml +0 -193
- data/maps/un-bel-Cyrl-Latn-2007.yaml +0 -114
- data/maps/un-ben-Beng-Latn-2016.yaml +0 -534
- data/maps/un-ell-Grek-Latn-1987-tl.yaml +0 -32
- data/maps/un-ell-Grek-Latn-1987-ts.yaml +0 -20
- data/maps/un-ell-Grek-Latn-phonetic-1987.yaml +0 -780
- data/maps/un-mon-Mong-Latn-2013.yaml +0 -93
- data/maps/un-rus-Cyrl-Latn-1987.yaml +0 -166
- data/maps/un-ukr-cyrl-latn-1998.yaml +0 -30
- data/maps/var-jpn-Hrkt-Latn-hepburn-1886.yaml +0 -406
- data/maps/var-jpn-Hrkt-Latn-hepburn-1954.yaml +0 -386
- data/maps/var-kor-Hang-Latn-mr-1939.yaml +0 -1054
- data/maps/var-kor-Kore-Hang-2013.yaml +0 -59754
- data/maps/var-kor-Kore-Latn-mr-1939.yaml +0 -37
- data/maps/var-tha-Thai-Thai-phonemic.yaml +0 -59
- data/maps/var-tha-Thai-Zsym-ipa.yaml +0 -301
- data/maps/var-zho-Hani-Latn-1979.yaml +0 -38908
- data/spec/interscript/mapping_spec.rb +0 -42
- data/spec/interscript_spec.rb +0 -26
- data/spec/spec_helper.rb +0 -3
@@ -0,0 +1,13 @@
|
|
1
|
+
class Interscript::Node::Dependency < Interscript::Node
|
2
|
+
attr_accessor :name, :full_name, :import, :document
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_hash
|
8
|
+
{ :class => self.class.to_s,
|
9
|
+
:name => @name,
|
10
|
+
:full_name => @full_name,
|
11
|
+
:import => @import }
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class Interscript::Node::Document
|
2
|
+
attr_accessor :metadata, :tests, :name
|
3
|
+
attr_accessor :dependencies, :aliases, :stages, :dep_aliases
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
puts "Interscript::Node::Document.new " if $DEBUG
|
7
|
+
@metadata = nil
|
8
|
+
@tests = nil
|
9
|
+
@dependencies = []
|
10
|
+
@dep_aliases = {}
|
11
|
+
@aliases = {}
|
12
|
+
@stages = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def imported_aliases
|
16
|
+
aliases = @aliases
|
17
|
+
@dependencies.select(&:import).each do |d|
|
18
|
+
aliases = d.document.aliases.merge(aliases)
|
19
|
+
end
|
20
|
+
aliases
|
21
|
+
end
|
22
|
+
|
23
|
+
def imported_stages
|
24
|
+
stages = @stages
|
25
|
+
@dependencies.select(&:import).each do |d|
|
26
|
+
stages = d.document.stages.merge(stages)
|
27
|
+
end
|
28
|
+
stages
|
29
|
+
end
|
30
|
+
|
31
|
+
def all_dependencies
|
32
|
+
(dependencies + dependencies.map { |i| i.document.dependencies }).flatten.uniq_by do |i|
|
33
|
+
i.full_name
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_hash
|
38
|
+
{ :class => self.class.to_s, :metadata => @metadata&.to_hash,
|
39
|
+
:tests => @tests&.to_hash,
|
40
|
+
:dependencies => @dependencies.map{|x| x.to_hash},
|
41
|
+
:dep_aliases => @dep_aliases.transform_values(&:to_hash),
|
42
|
+
:aliases => @aliases.transform_values(&:to_hash),
|
43
|
+
:stages => @stages.transform_values(&:to_hash) }
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Interscript::Node::Group < Interscript::Node
|
2
|
+
attr_accessor :children
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@children = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def reorder_children(source,target)
|
9
|
+
@children[source], @children[target] = @children[target], @children[source]
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
def apply_order(order)
|
14
|
+
children_new = [nil] * @children.size
|
15
|
+
order.each_with_index do |pos,idx|
|
16
|
+
children_new[idx] = @children[pos]
|
17
|
+
end
|
18
|
+
@children = children_new
|
19
|
+
#@children[source], @children[target] = @children[target], @children[source]
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_hash
|
24
|
+
{ :class => self.class.to_s,
|
25
|
+
:children => @children.map{|x| x.to_hash} }
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
@children.map(&:inspect).join("\n").gsub(/^/, " ")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
require "interscript/node/group/parallel"
|
34
|
+
require "interscript/node/group/sequential"
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class Interscript::Node::Group::Parallel < Interscript::Node::Group
|
2
|
+
# A place for Interpreter to store a compiled form of the tree
|
3
|
+
attr_accessor :cached_tree
|
4
|
+
attr_accessor :subs_regexp, :subs_replacements, :subs_array
|
5
|
+
|
6
|
+
def inspect
|
7
|
+
"parallel {\n#{super}\n}"
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class Interscript::Node::Item < Interscript::Node
|
2
|
+
attr_accessor :item
|
3
|
+
def initialize item
|
4
|
+
raise NotImplementedError, "You can't construct a Node::Item directly"
|
5
|
+
end
|
6
|
+
|
7
|
+
def + other
|
8
|
+
this = self
|
9
|
+
|
10
|
+
this = this.children if Interscript::Node::Item::Group === this
|
11
|
+
other = other.children if Interscript::Node::Item::Group === other
|
12
|
+
|
13
|
+
this = Array(this)
|
14
|
+
other = Array(other)
|
15
|
+
|
16
|
+
this = this.map { |i| Interscript::Node::Item.try_convert(i) }
|
17
|
+
other = other.map { |i| Interscript::Node::Item.try_convert(i) }
|
18
|
+
|
19
|
+
middle = []
|
20
|
+
|
21
|
+
if Interscript::Node::Item::String === this.last &&
|
22
|
+
Interscript::Node::Item::String === other.first
|
23
|
+
|
24
|
+
middle = [this.last + other.first]
|
25
|
+
this = this[0..-2]
|
26
|
+
other = this[1..-1]
|
27
|
+
end
|
28
|
+
|
29
|
+
g = Interscript::Node::Item::Group.new(*this, *middle, *other)
|
30
|
+
g.verify!
|
31
|
+
g
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_hash
|
35
|
+
{ :class => self.class.to_s,
|
36
|
+
:item => self.item }
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.try_convert(i)
|
40
|
+
i = Interscript::Node::Item::String.new(i) if i.class == ::String
|
41
|
+
raise TypeError, "Wrong type #{i.class}, expected I::Node::Item" unless Interscript::Node::Item === i
|
42
|
+
i
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
require "interscript/node/item/alias"
|
47
|
+
require "interscript/node/item/string"
|
48
|
+
require "interscript/node/item/group"
|
49
|
+
require "interscript/node/item/any"
|
50
|
+
require "interscript/node/item/stage"
|
51
|
+
require "interscript/node/item/capture"
|
52
|
+
require "interscript/node/item/repeat"
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class Interscript::Node::Item::Alias < Interscript::Node::Item
|
2
|
+
attr_accessor :name
|
3
|
+
attr_accessor :map
|
4
|
+
def initialize(name, map: nil)
|
5
|
+
self.name = name
|
6
|
+
self.map = map
|
7
|
+
end
|
8
|
+
|
9
|
+
def stdlib?
|
10
|
+
!map && Interscript::Stdlib::ALIASES.has_key?(name)
|
11
|
+
end
|
12
|
+
|
13
|
+
def max_length
|
14
|
+
if stdlib?
|
15
|
+
([:none].include? name) ? 0 : 1
|
16
|
+
else
|
17
|
+
return 1 if name == :unicode_hangul
|
18
|
+
raise NotImplementedError, "can't get a max length of this alias"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def first_string
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
alias nth_string first_string
|
27
|
+
|
28
|
+
def to_hash
|
29
|
+
{ :class => self.class.to_s,
|
30
|
+
:name => name,
|
31
|
+
:map => map,
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def inspect
|
36
|
+
if map
|
37
|
+
"map.#{map}.#{name}"
|
38
|
+
else
|
39
|
+
"#{name}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
class Interscript::Node::Item::Any < Interscript::Node::Item
|
2
|
+
attr_accessor :value
|
3
|
+
def initialize data
|
4
|
+
case data
|
5
|
+
when Array, ::String, Range
|
6
|
+
self.value = data
|
7
|
+
when Interscript::Node::Item::Group # debug alalc-ara-Arab-Latn-1997 line 683
|
8
|
+
self.value = data.children
|
9
|
+
when Interscript::Node::Item::Alias # debug mofa-jpn-Hrkt-Latn-1989 line 116
|
10
|
+
self.value = Interscript::Stdlib::ALIASES[data.name]
|
11
|
+
else
|
12
|
+
puts data.inspect
|
13
|
+
raise TypeError, "Wrong type #{data[0].class}, excepted Array, String or Range"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def data
|
18
|
+
case @value
|
19
|
+
when Array
|
20
|
+
value.map { |i| Interscript::Node::Item.try_convert(i) }
|
21
|
+
when ::String
|
22
|
+
value.split("").map { |i| Interscript::Node::Item.try_convert(i) }
|
23
|
+
when Range
|
24
|
+
value.map { |i| Interscript::Node::Item.try_convert(i) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def first_string
|
29
|
+
case @value
|
30
|
+
when Array
|
31
|
+
Interscript::Node::Item.try_convert(value.first).first_string
|
32
|
+
when ::String
|
33
|
+
value[0]
|
34
|
+
when Range
|
35
|
+
value.begin
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def nth_string
|
40
|
+
return first_string unless $select_nth_string
|
41
|
+
|
42
|
+
d = data
|
43
|
+
Fiber.yield(:prepare)
|
44
|
+
id = Fiber.yield(:select_nth_string, d.count, self.hash)
|
45
|
+
Fiber.yield(:selection)
|
46
|
+
Interscript::Node::Item.try_convert(value[id]).nth_string
|
47
|
+
end
|
48
|
+
|
49
|
+
def max_length
|
50
|
+
self.data.map(&:max_length).max
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_hash
|
54
|
+
{ :class => self.class.to_s,
|
55
|
+
:data => self.data.map { |i| i.to_hash } }
|
56
|
+
end
|
57
|
+
|
58
|
+
def inspect
|
59
|
+
"any(#{value.inspect})"
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# (...)
|
2
|
+
class Interscript::Node::Item::CaptureGroup < Interscript::Node::Item
|
3
|
+
attr_accessor :data
|
4
|
+
|
5
|
+
def initialize(data)
|
6
|
+
data = Interscript::Node::Item.try_convert(data)
|
7
|
+
@data = data
|
8
|
+
end
|
9
|
+
|
10
|
+
def first_string
|
11
|
+
data.first_string
|
12
|
+
end
|
13
|
+
|
14
|
+
def nth_string
|
15
|
+
data.nth_string
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_hash
|
19
|
+
{ :class => self.class.to_s,
|
20
|
+
:data => self.data.to_hash }
|
21
|
+
end
|
22
|
+
|
23
|
+
def inspect
|
24
|
+
"capture(#{@data.inspect})"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# \1
|
29
|
+
class Interscript::Node::Item::CaptureRef < Interscript::Node::Item
|
30
|
+
attr_accessor :id
|
31
|
+
|
32
|
+
def initialize(id)
|
33
|
+
@id = id
|
34
|
+
end
|
35
|
+
|
36
|
+
def first_string
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
alias nth_string first_string
|
41
|
+
|
42
|
+
def to_hash
|
43
|
+
{ :class => self.class.to_s,
|
44
|
+
:id => self.id }
|
45
|
+
end
|
46
|
+
|
47
|
+
def inspect
|
48
|
+
"ref(#{@id.inspect})"
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class Interscript::Node::Item::Group < Interscript::Node::Item
|
2
|
+
attr_accessor :children
|
3
|
+
|
4
|
+
def initialize *children
|
5
|
+
@children = children.flatten.map do |i|
|
6
|
+
Interscript::Node::Item.try_convert(i)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def +(item)
|
11
|
+
item = Interscript::Node::Item.try_convert(item)
|
12
|
+
out = self.dup
|
13
|
+
out.children << item
|
14
|
+
out.verify!
|
15
|
+
out
|
16
|
+
end
|
17
|
+
|
18
|
+
# Verify if a group is valid
|
19
|
+
def verify!
|
20
|
+
wrong = @children.find do |i|
|
21
|
+
Interscript::Node::Item::Stage === i ||
|
22
|
+
! (Interscript::Node::Item === i) ||
|
23
|
+
i.class == Interscript::Node::Item
|
24
|
+
end
|
25
|
+
|
26
|
+
if wrong
|
27
|
+
raise TypeError, "An I::Node::Item::Group can't contain an #{wrong.class} item."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def first_string
|
32
|
+
self.children.map(&:first_string).reduce(&:+)
|
33
|
+
end
|
34
|
+
|
35
|
+
def nth_string
|
36
|
+
self.children.map(&:nth_string).reduce(&:+)
|
37
|
+
end
|
38
|
+
|
39
|
+
def max_length
|
40
|
+
@children.map { |i| i.max_length }.sum
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_hash
|
44
|
+
{ :class => self.class.to_s,
|
45
|
+
:children => self.children.map{|x| x.to_hash} }
|
46
|
+
end
|
47
|
+
|
48
|
+
def inspect
|
49
|
+
@children.map(&:inspect).join("+")
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class Interscript::Node::Item::Repeat < Interscript::Node::Item
|
2
|
+
attr_accessor :data
|
3
|
+
def initialize data
|
4
|
+
data = Interscript::Node::Item.try_convert(data)
|
5
|
+
@data = data
|
6
|
+
end
|
7
|
+
|
8
|
+
def first_string
|
9
|
+
data.first_string
|
10
|
+
end
|
11
|
+
|
12
|
+
def nth_string
|
13
|
+
data.nth_string
|
14
|
+
end
|
15
|
+
|
16
|
+
def max_length
|
17
|
+
data.max_length
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_hash
|
21
|
+
{ :class => self.class.to_s,
|
22
|
+
:data => self.data.to_hash }
|
23
|
+
end
|
24
|
+
|
25
|
+
def inspect
|
26
|
+
str = case self
|
27
|
+
when Interscript::Node::Item::Maybe
|
28
|
+
"maybe"
|
29
|
+
when Interscript::Node::Item::MaybeSome
|
30
|
+
"maybe_some"
|
31
|
+
when Interscript::Node::Item::Some
|
32
|
+
"some"
|
33
|
+
end
|
34
|
+
"#{str}(#{@data.inspect})"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Interscript::Node::Item::Maybe < Interscript::Node::Item::Repeat; end
|
39
|
+
class Interscript::Node::Item::MaybeSome < Interscript::Node::Item::Repeat; end
|
40
|
+
class Interscript::Node::Item::Some < Interscript::Node::Item::Repeat; end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Interscript::Node::Item::Stage < Interscript::Node::Item
|
2
|
+
attr_accessor :name
|
3
|
+
attr_accessor :map
|
4
|
+
def initialize(name, map: nil)
|
5
|
+
self.name = name
|
6
|
+
self.map = map
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_hash
|
10
|
+
{ :class => self.class.to_s,
|
11
|
+
:name => name,
|
12
|
+
:map => map,
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def inspect
|
17
|
+
if map
|
18
|
+
"map.#{@map}.stage.#{@name}"
|
19
|
+
else
|
20
|
+
"stage.#{@name}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class Interscript::Node::Item::String < Interscript::Node::Item
|
2
|
+
attr_accessor :data
|
3
|
+
def initialize data
|
4
|
+
self.data = data
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_hash
|
8
|
+
{ :class => self.class.to_s,
|
9
|
+
:data => self.data }
|
10
|
+
end
|
11
|
+
|
12
|
+
def max_length
|
13
|
+
self.data.length
|
14
|
+
end
|
15
|
+
|
16
|
+
def first_string
|
17
|
+
self.data
|
18
|
+
end
|
19
|
+
|
20
|
+
alias nth_string first_string
|
21
|
+
|
22
|
+
def + other
|
23
|
+
if self.data == ""
|
24
|
+
Interscript::Node::Item.try_convert(other)
|
25
|
+
elsif Interscript::Node::Item::String === self &&
|
26
|
+
(Interscript::Node::Item::String === other || ::String === other)
|
27
|
+
|
28
|
+
other = Interscript::Node::Item.try_convert(other)
|
29
|
+
|
30
|
+
Interscript::Node::Item::String.new(self.data + other.data)
|
31
|
+
else
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def inspect
|
37
|
+
@data.inspect
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# stdext
|
42
|
+
class String
|
43
|
+
alias plus_before_interscript +
|
44
|
+
def + other
|
45
|
+
if Interscript::Node === other
|
46
|
+
Interscript::Node::Item.try_convert(self) + other
|
47
|
+
else
|
48
|
+
self.plus_before_interscript(other)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|