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.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -0
  3. data/docs/demo/20191118-interscript-demo-cast.gif +0 -0
  4. data/exe/codemod-imp-to-isc +5 -0
  5. data/exe/diagnose_parse_failures +47 -0
  6. data/exe/interscript +2 -1
  7. data/exe/verify_isc_deep +211 -0
  8. data/exe/verify_isc_equivalence +128 -0
  9. data/interscript.gemspec +27 -20
  10. data/lib/interscript/command.rb +21 -12
  11. data/lib/interscript/compiler/javascript.rb +34 -35
  12. data/lib/interscript/compiler/json_ir.rb +214 -0
  13. data/lib/interscript/compiler/python.rb +354 -0
  14. data/lib/interscript/compiler/ruby.rb +23 -22
  15. data/lib/interscript/compiler.rb +20 -3
  16. data/lib/interscript/detector.rb +14 -7
  17. data/lib/interscript/dsl/aliases.rb +1 -1
  18. data/lib/interscript/dsl/document.rb +6 -3
  19. data/lib/interscript/dsl/group/parallel.rb +1 -1
  20. data/lib/interscript/dsl/group.rb +18 -9
  21. data/lib/interscript/dsl/items.rb +28 -16
  22. data/lib/interscript/dsl/metadata.rb +19 -18
  23. data/lib/interscript/dsl/stage.rb +1 -1
  24. data/lib/interscript/dsl/symbol_mm.rb +4 -2
  25. data/lib/interscript/dsl/tests.rb +1 -1
  26. data/lib/interscript/dsl.rb +21 -13
  27. data/lib/interscript/interpreter.rb +32 -21
  28. data/lib/interscript/isc/codemod.rb +791 -0
  29. data/lib/interscript/isc/document_builder.rb +354 -0
  30. data/lib/interscript/isc/generator.rb +191 -0
  31. data/lib/interscript/isc/grammar/concerns/aliases.rb +29 -0
  32. data/lib/interscript/isc/grammar/concerns/dependencies.rb +23 -0
  33. data/lib/interscript/isc/grammar/concerns/items.rb +176 -0
  34. data/lib/interscript/isc/grammar/concerns/metadata.rb +142 -0
  35. data/lib/interscript/isc/grammar/concerns/primitives.rb +112 -0
  36. data/lib/interscript/isc/grammar/concerns/stages.rb +129 -0
  37. data/lib/interscript/isc/grammar/concerns/system.rb +37 -0
  38. data/lib/interscript/isc/grammar/concerns/tests.rb +31 -0
  39. data/lib/interscript/isc/grammar/concerns.rb +18 -0
  40. data/lib/interscript/isc/grammar/core.rb +23 -0
  41. data/lib/interscript/isc/grammar/isc.artifact.json +1 -0
  42. data/lib/interscript/isc/grammar/isc.parg +196 -0
  43. data/lib/interscript/isc/grammar.rb +12 -0
  44. data/lib/interscript/isc/items.rb +185 -0
  45. data/lib/interscript/isc/model/alias.rb +20 -0
  46. data/lib/interscript/isc/model/constraint.rb +20 -0
  47. data/lib/interscript/isc/model/dependency.rb +19 -0
  48. data/lib/interscript/isc/model/document.rb +31 -0
  49. data/lib/interscript/isc/model/item.rb +50 -0
  50. data/lib/interscript/isc/model/rule.rb +23 -0
  51. data/lib/interscript/isc/model/stage.rb +20 -0
  52. data/lib/interscript/isc/model/stage_item.rb +33 -0
  53. data/lib/interscript/isc/model/test.rb +21 -0
  54. data/lib/interscript/isc/model.rb +19 -0
  55. data/lib/interscript/isc/node_adapter.rb +310 -0
  56. data/lib/interscript/isc/normalizer.rb +127 -0
  57. data/lib/interscript/isc/parser.rb +78 -0
  58. data/lib/interscript/isc/serializer.rb +248 -0
  59. data/lib/interscript/isc/transform.rb +138 -0
  60. data/lib/interscript/isc/yaml_bridge.rb +236 -0
  61. data/lib/interscript/isc.rb +30 -0
  62. data/lib/interscript/ml/byt5_onnx.rb +102 -0
  63. data/lib/interscript/ml/imf.rb +182 -0
  64. data/lib/interscript/ml/model.rb +52 -0
  65. data/lib/interscript/ml/provisioning.rb +189 -0
  66. data/lib/interscript/ml/translator.rb +38 -0
  67. data/lib/interscript/ml/vocab.rb +48 -0
  68. data/lib/interscript/ml.rb +25 -0
  69. data/lib/interscript/node/alias_def.rb +5 -5
  70. data/lib/interscript/node/dependency.rb +7 -7
  71. data/lib/interscript/node/document.rb +10 -10
  72. data/lib/interscript/node/group.rb +11 -9
  73. data/lib/interscript/node/item/alias.rb +14 -10
  74. data/lib/interscript/node/item/any.rb +14 -7
  75. data/lib/interscript/node/item/capture.rb +14 -9
  76. data/lib/interscript/node/item/group.rb +22 -17
  77. data/lib/interscript/node/item/repeat.rb +3 -3
  78. data/lib/interscript/node/item/stage.rb +4 -5
  79. data/lib/interscript/node/item/string.rb +18 -13
  80. data/lib/interscript/node/item.rb +27 -17
  81. data/lib/interscript/node/metadata.rb +6 -5
  82. data/lib/interscript/node/rule/funcall.rb +4 -5
  83. data/lib/interscript/node/rule/run.rb +4 -5
  84. data/lib/interscript/node/rule/sub.rb +55 -55
  85. data/lib/interscript/node/rule.rb +6 -5
  86. data/lib/interscript/node/stage.rb +11 -14
  87. data/lib/interscript/node/tests.rb +6 -6
  88. data/lib/interscript/node.rb +14 -17
  89. data/lib/interscript/stdlib/functions/rababa_adapter.rb +56 -0
  90. data/lib/interscript/stdlib/functions/secryst_adapter.rb +37 -0
  91. data/lib/interscript/stdlib/functions.rb +49 -0
  92. data/lib/interscript/stdlib.rb +25 -95
  93. data/lib/interscript/utils/helpers.rb +8 -5
  94. data/lib/interscript/utils/regexp_converter.rb +143 -144
  95. data/lib/interscript/version.rb +1 -1
  96. data/lib/interscript/visualize/json.rb +12 -13
  97. data/lib/interscript/visualize/nodes.rb +13 -13
  98. data/lib/interscript/visualize.rb +18 -18
  99. data/lib/interscript.rb +59 -45
  100. metadata +88 -31
  101. data/.github/workflows/assets.yml +0 -91
  102. data/.github/workflows/rake.yml +0 -52
  103. data/.github/workflows/release.yml +0 -68
  104. data/.gitignore +0 -79
  105. data/.rspec +0 -3
  106. data/Gemfile +0 -38
  107. data/Rakefile +0 -139
  108. data/bin/console +0 -10
  109. data/bin/interscript +0 -5
  110. data/bin/maps_analyze_staging +0 -168
  111. data/bin/maps_debug_compilers +0 -58
  112. data/bin/maps_debug_ordering +0 -88
  113. data/bin/maps_debug_ruby_compile +0 -24
  114. data/bin/maps_debug_step_by_step +0 -44
  115. data/bin/maps_optimize_order +0 -112
  116. data/bin/maps_v1_analyze_regexps +0 -45
  117. data/bin/maps_v1_to_v2 +0 -426
  118. data/bin/set_version +0 -16
  119. data/bin/setup +0 -8
  120. data/requirements.txt +0 -1
@@ -15,15 +15,15 @@ class Interscript::Node::Dependency < Interscript::Node
15
15
 
16
16
  def ==(other)
17
17
  super &&
18
- self.full_name == other.full_name &&
19
- self.import == other.import &&
20
- self.name == other.name
18
+ full_name == other.full_name &&
19
+ import == other.import &&
20
+ name == other.name
21
21
  end
22
22
 
23
23
  def to_hash
24
- { :class => self.class.to_s,
25
- :name => @name,
26
- :full_name => @full_name,
27
- :import => @import }
24
+ {class: self.class.to_s,
25
+ name: @name,
26
+ full_name: @full_name,
27
+ import: @import}
28
28
  end
29
29
  end
@@ -62,18 +62,18 @@ class Interscript::Node::Document
62
62
 
63
63
  def ==(other)
64
64
  self.class == other.class &&
65
- self.metadata == other.metadata &&
66
- self.tests == other.tests &&
67
- self.stages == other.stages &&
68
- self.aliases == other.aliases
65
+ metadata == other.metadata &&
66
+ tests == other.tests &&
67
+ stages == other.stages &&
68
+ aliases == other.aliases
69
69
  end
70
70
 
71
71
  def to_hash
72
- { :class => self.class.to_s, :metadata => @metadata&.to_hash,
73
- :tests => @tests&.to_hash,
74
- :dependencies => @dependencies.map{|x| x.to_hash},
75
- :dep_aliases => @dep_aliases.transform_values(&:to_hash),
76
- :aliases => @aliases.transform_values(&:to_hash),
77
- :stages => @stages.transform_values(&:to_hash) }
72
+ {class: self.class.to_s, metadata: @metadata&.to_hash,
73
+ tests: @tests&.to_hash,
74
+ dependencies: @dependencies.map { |x| x.to_hash },
75
+ dep_aliases: @dep_aliases.transform_values(&:to_hash),
76
+ aliases: @aliases.transform_values(&:to_hash),
77
+ stages: @stages.transform_values(&:to_hash)}
78
78
  end
79
79
  end
@@ -6,34 +6,34 @@ class Interscript::Node::Group < Interscript::Node
6
6
  @children = []
7
7
  end
8
8
 
9
- def reorder_children(source,target)
9
+ def reorder_children(source, target)
10
10
  @children[source], @children[target] = @children[target], @children[source]
11
11
  self
12
12
  end
13
13
 
14
14
  def apply_order(order)
15
15
  children_new = [nil] * @children.size
16
- order.each_with_index do |pos,idx|
16
+ order.each_with_index do |pos, idx|
17
17
  children_new[idx] = @children[pos]
18
18
  end
19
19
  @children = children_new
20
- #@children[source], @children[target] = @children[target], @children[source]
20
+ # @children[source], @children[target] = @children[target], @children[source]
21
21
  self
22
22
  end
23
23
 
24
24
  def reverse
25
25
  self.class.new(reverse_run: reverse_run.nil? ? nil : !reverse_run).tap do |r|
26
- r.children = self.children.reverse.map(&:reverse)
26
+ r.children = children.reverse.map(&:reverse)
27
27
  end
28
28
  end
29
29
 
30
30
  def to_hash
31
- { :class => self.class.to_s,
32
- :children => @children.map{|x| x.to_hash} }
31
+ {class: self.class.to_s,
32
+ children: @children.map { |x| x.to_hash }}
33
33
  end
34
34
 
35
35
  def ==(other)
36
- super && self.children == other.children && self.reverse_run == other.reverse_run
36
+ super && children == other.children && reverse_run == other.reverse_run
37
37
  end
38
38
 
39
39
  def inspect
@@ -41,5 +41,7 @@ class Interscript::Node::Group < Interscript::Node
41
41
  end
42
42
  end
43
43
 
44
- require "interscript/node/group/parallel"
45
- require "interscript/node/group/sequential"
44
+ class Interscript::Node::Group
45
+ autoload :Parallel, "interscript/node/group/parallel"
46
+ autoload :Sequential, "interscript/node/group/sequential"
47
+ end
@@ -16,7 +16,7 @@ class Interscript::Node::Item::Alias < Interscript::Node::Item
16
16
 
17
17
  def max_length
18
18
  if stdlib?
19
- ([:none].include? name) ? 0 : 1
19
+ [:none].include?(name) ? 0 : 1
20
20
  else
21
21
  return 1 if name == :unicode_hangul
22
22
  raise NotImplementedError, "can't get a max length of this alias"
@@ -24,31 +24,35 @@ class Interscript::Node::Item::Alias < Interscript::Node::Item
24
24
  end
25
25
 
26
26
  # Not implemented properly
27
- def downcase; self; end
28
- def upcase; self; end
27
+ def downcase
28
+ self
29
+ end
30
+
31
+ def upcase
32
+ self
33
+ end
29
34
 
30
35
  def first_string
31
36
  self
32
37
  end
33
38
 
34
- alias nth_string first_string
39
+ alias_method :nth_string, :first_string
35
40
 
36
41
  def to_hash
37
- { :class => self.class.to_s,
38
- :name => name,
39
- :map => map,
40
- }
42
+ {class: self.class.to_s,
43
+ name: name,
44
+ map: map}
41
45
  end
42
46
 
43
47
  def ==(other)
44
- super && self.name == other.name && self.map == other.map
48
+ super && name == other.name && map == other.map
45
49
  end
46
50
 
47
51
  def inspect
48
52
  if map
49
53
  "map.#{map}.#{name}"
50
54
  else
51
- "#{name}"
55
+ name.to_s
52
56
  end
53
57
  end
54
58
  end
@@ -19,14 +19,19 @@ class Interscript::Node::Item::Any < Interscript::Node::Item
19
19
  when Array
20
20
  value.map { |i| Interscript::Node::Item.try_convert(i) }
21
21
  when ::String
22
- value.split("").map { |i| Interscript::Node::Item.try_convert(i) }
22
+ value.chars.map { |i| Interscript::Node::Item.try_convert(i) }
23
23
  when Range
24
24
  value.map { |i| Interscript::Node::Item.try_convert(i) }
25
25
  end
26
26
  end
27
27
 
28
- def downcase; self.class.new(self.data.map(&:downcase)); end
29
- def upcase; self.class.new(self.data.map(&:upcase)); end
28
+ def downcase
29
+ self.class.new(data.map(&:downcase))
30
+ end
31
+
32
+ def upcase
33
+ self.class.new(data.map(&:upcase))
34
+ end
30
35
 
31
36
  def first_string
32
37
  case @value
@@ -40,21 +45,23 @@ class Interscript::Node::Item::Any < Interscript::Node::Item
40
45
  end
41
46
 
42
47
  def nth_string
48
+ # standard:disable Style/GlobalVars (deliberate $DEBUG / -d-flag debug idiom)
43
49
  return first_string unless $select_nth_string
50
+ # standard:enable Style/GlobalVars
44
51
 
45
52
  d = data
46
53
  Fiber.yield(:prepare)
47
- id = Fiber.yield(:select_nth_string, d.count, self.hash)
54
+ id = Fiber.yield(:select_nth_string, d.count, hash)
48
55
  Fiber.yield(:selection)
49
56
  Interscript::Node::Item.try_convert(value[id]).nth_string
50
57
  end
51
58
 
52
59
  def max_length
53
- self.data.map(&:max_length).max
60
+ data.map(&:max_length).max
54
61
  end
55
62
 
56
63
  def to_hash
57
- hash = { :class => self.class.to_s }
64
+ hash = {class: self.class.to_s}
58
65
 
59
66
  case @value
60
67
  when Array
@@ -74,7 +81,7 @@ class Interscript::Node::Item::Any < Interscript::Node::Item
74
81
  end
75
82
 
76
83
  def ==(other)
77
- super && self.data == other.data
84
+ super && data == other.data
78
85
  end
79
86
 
80
87
  def inspect
@@ -15,16 +15,21 @@ class Interscript::Node::Item::CaptureGroup < Interscript::Node::Item
15
15
  data.nth_string
16
16
  end
17
17
 
18
- def downcase; self.dup.tap { |i| i.data = i.data.downcase }; end
19
- def upcase; self.dup.tap { |i| i.data = i.data.upcase }; end
18
+ def downcase
19
+ dup.tap { |i| i.data = i.data.downcase }
20
+ end
21
+
22
+ def upcase
23
+ dup.tap { |i| i.data = i.data.upcase }
24
+ end
20
25
 
21
26
  def to_hash
22
- { :class => self.class.to_s,
23
- :data => self.data.to_hash }
27
+ {class: self.class.to_s,
28
+ data: data.to_hash}
24
29
  end
25
30
 
26
31
  def ==(other)
27
- super && self.data == other.data
32
+ super && data == other.data
28
33
  end
29
34
 
30
35
  def inspect
@@ -44,15 +49,15 @@ class Interscript::Node::Item::CaptureRef < Interscript::Node::Item
44
49
  self
45
50
  end
46
51
 
47
- alias nth_string first_string
52
+ alias_method :nth_string, :first_string
48
53
 
49
54
  def to_hash
50
- { :class => self.class.to_s,
51
- :id => self.id }
55
+ {class: self.class.to_s,
56
+ id: id}
52
57
  end
53
58
 
54
59
  def ==(other)
55
- super && self.id == other.id
60
+ super && id == other.id
56
61
  end
57
62
 
58
63
  def inspect
@@ -7,23 +7,23 @@ class Interscript::Node::Item::Group < Interscript::Node::Item
7
7
  end
8
8
  end
9
9
 
10
- def +(item)
11
- item = Interscript::Node::Item.try_convert(item)
12
- out = self.dup
13
- if Interscript::Node::Item::Group === item
14
- out.children += item.children
10
+ def +(other)
11
+ other = Interscript::Node::Item.try_convert(other)
12
+ out = dup
13
+ if Interscript::Node::Item::Group === other
14
+ out.children += other.children
15
15
  else
16
- out.children << item
16
+ out.children << other
17
17
  end
18
18
  out.verify!
19
19
  out
20
20
  end
21
21
 
22
22
  def compact
23
- out = self.dup do |n|
23
+ out = dup do |n|
24
24
  n.children = n.children.reject do |i|
25
25
  (Interscript::Node::Alias === i && i.name == :none) ||
26
- (Interscript::Node::String === i && i.data == "")
26
+ (Interscript::Node::String === i && i.data == "")
27
27
  end
28
28
  end
29
29
 
@@ -36,15 +36,20 @@ class Interscript::Node::Item::Group < Interscript::Node::Item
36
36
  end
37
37
  end
38
38
 
39
- def downcase; self.dup.tap { |i| i.children = i.children.map(&:downcase) }; end
40
- def upcase; self.dup.tap { |i| i.children = i.children.map(&:upcase) }; end
39
+ def downcase
40
+ dup.tap { |i| i.children = i.children.map(&:downcase) }
41
+ end
42
+
43
+ def upcase
44
+ dup.tap { |i| i.children = i.children.map(&:upcase) }
45
+ end
41
46
 
42
47
  # Verify if a group is valid
43
48
  def verify!
44
49
  wrong = @children.find do |i|
45
50
  Interscript::Node::Item::Stage === i ||
46
- ! (Interscript::Node::Item === i) ||
47
- i.class == Interscript::Node::Item
51
+ !(Interscript::Node::Item === i) ||
52
+ i.instance_of?(Interscript::Node::Item)
48
53
  end
49
54
 
50
55
  if wrong
@@ -53,11 +58,11 @@ class Interscript::Node::Item::Group < Interscript::Node::Item
53
58
  end
54
59
 
55
60
  def first_string
56
- self.children.map(&:first_string).reduce(&:+)
61
+ children.map(&:first_string).reduce(&:+)
57
62
  end
58
63
 
59
64
  def nth_string
60
- self.children.map(&:nth_string).reduce(&:+)
65
+ children.map(&:nth_string).reduce(&:+)
61
66
  end
62
67
 
63
68
  def max_length
@@ -65,12 +70,12 @@ class Interscript::Node::Item::Group < Interscript::Node::Item
65
70
  end
66
71
 
67
72
  def to_hash
68
- { :class => self.class.to_s,
69
- :children => self.children.map{|x| x.to_hash} }
73
+ {class: self.class.to_s,
74
+ children: children.map { |x| x.to_hash }}
70
75
  end
71
76
 
72
77
  def ==(other)
73
- super && self.children == other.children
78
+ super && children == other.children
74
79
  end
75
80
 
76
81
  def inspect
@@ -18,12 +18,12 @@ class Interscript::Node::Item::Repeat < Interscript::Node::Item
18
18
  end
19
19
 
20
20
  def to_hash
21
- { :class => self.class.to_s,
22
- :data => self.data.to_hash }
21
+ {class: self.class.to_s,
22
+ data: data.to_hash}
23
23
  end
24
24
 
25
25
  def ==(other)
26
- super && self.data == other.data
26
+ super && data == other.data
27
27
  end
28
28
 
29
29
  def inspect
@@ -7,14 +7,13 @@ class Interscript::Node::Item::Stage < Interscript::Node::Item
7
7
  end
8
8
 
9
9
  def to_hash
10
- { :class => self.class.to_s,
11
- :name => name,
12
- :map => map,
13
- }
10
+ {class: self.class.to_s,
11
+ name: name,
12
+ map: map}
14
13
  end
15
14
 
16
15
  def ==(other)
17
- super && self.name == other.name && self.map == other.map
16
+ super && name == other.name && map == other.map
18
17
  end
19
18
 
20
19
  def inspect
@@ -5,39 +5,44 @@ class Interscript::Node::Item::String < Interscript::Node::Item
5
5
  end
6
6
 
7
7
  def to_hash
8
- { :class => self.class.to_s,
9
- :data => self.data }
8
+ {class: self.class.to_s,
9
+ data: data}
10
10
  end
11
11
 
12
12
  def max_length
13
- self.data.length
13
+ data.length
14
14
  end
15
15
 
16
16
  def first_string
17
- self.data
17
+ data
18
18
  end
19
19
 
20
- def downcase; self.dup.tap { |i| i.data = i.data.downcase }; end
21
- def upcase; self.dup.tap { |i| i.data = i.data.upcase }; end
20
+ def downcase
21
+ dup.tap { |i| i.data = i.data.downcase }
22
+ end
23
+
24
+ def upcase
25
+ dup.tap { |i| i.data = i.data.upcase }
26
+ end
22
27
 
23
- alias nth_string first_string
28
+ alias_method :nth_string, :first_string
24
29
 
25
30
  def + other
26
- if self.data == ""
31
+ if data == ""
27
32
  Interscript::Node::Item.try_convert(other)
28
33
  elsif Interscript::Node::Item::String === self &&
29
- (Interscript::Node::Item::String === other || ::String === other)
34
+ (Interscript::Node::Item::String === other || ::String === other)
30
35
 
31
36
  other = Interscript::Node::Item.try_convert(other)
32
37
 
33
- Interscript::Node::Item::String.new(self.data + other.data)
38
+ Interscript::Node::Item::String.new(data + other.data)
34
39
  else
35
40
  super
36
41
  end
37
42
  end
38
43
 
39
44
  def ==(other)
40
- super && self.data == other.data
45
+ super && data == other.data
41
46
  end
42
47
 
43
48
  def inspect
@@ -47,12 +52,12 @@ end
47
52
 
48
53
  # stdext
49
54
  class String
50
- alias plus_before_interscript +
55
+ alias_method :plus_before_interscript, :+
51
56
  def + other
52
57
  if Interscript::Node === other
53
58
  Interscript::Node::Item.try_convert(self) + other
54
59
  else
55
- self.plus_before_interscript(other)
60
+ plus_before_interscript(other)
56
61
  end
57
62
  end
58
63
  end
@@ -7,23 +7,23 @@ class Interscript::Node::Item < Interscript::Node
7
7
  def + other
8
8
  this = self
9
9
 
10
- this = this.children if Interscript::Node::Item::Group === this
10
+ this = this.children if Interscript::Node::Item::Group === this
11
11
  other = other.children if Interscript::Node::Item::Group === other
12
12
 
13
- this = Array(this)
13
+ this = Array(this)
14
14
  other = Array(other)
15
15
 
16
- this = this.map { |i| Interscript::Node::Item.try_convert(i) }
16
+ this = this.map { |i| Interscript::Node::Item.try_convert(i) }
17
17
  other = other.map { |i| Interscript::Node::Item.try_convert(i) }
18
18
 
19
19
  middle = []
20
20
 
21
21
  if Interscript::Node::Item::String === this.last &&
22
- Interscript::Node::Item::String === other.first
22
+ Interscript::Node::Item::String === other.first
23
23
 
24
- middle = [this.last + other.first]
25
- this = this[0..-2]
26
- other = this[1..-1]
24
+ middle = [this.last + other.first]
25
+ this = this[0..-2]
26
+ other = this[1..]
27
27
  end
28
28
 
29
29
  g = Interscript::Node::Item::Group.new(*this, *middle, *other)
@@ -32,8 +32,8 @@ class Interscript::Node::Item < Interscript::Node
32
32
  end
33
33
 
34
34
  def to_hash
35
- { :class => self.class.to_s,
36
- :item => self.item }
35
+ {class: self.class.to_s,
36
+ item: item}
37
37
  end
38
38
 
39
39
  def ==(other)
@@ -41,16 +41,26 @@ class Interscript::Node::Item < Interscript::Node
41
41
  end
42
42
 
43
43
  def self.try_convert(i)
44
- i = Interscript::Node::Item::String.new(i) if i.class == ::String
44
+ i = Interscript::Node::Item::String.new(i) if i.instance_of?(::String)
45
45
  raise Interscript::MapLogicError, "Wrong type #{i.class}, expected I::Node::Item" unless Interscript::Node::Item === i
46
46
  i
47
47
  end
48
48
  end
49
49
 
50
- require "interscript/node/item/alias"
51
- require "interscript/node/item/string"
52
- require "interscript/node/item/group"
53
- require "interscript/node/item/any"
54
- require "interscript/node/item/stage"
55
- require "interscript/node/item/capture"
56
- require "interscript/node/item/repeat"
50
+ class Interscript::Node::Item
51
+ # Autoload all item types (OCP: new item type = one autoload).
52
+ autoload :Alias, "interscript/node/item/alias"
53
+ autoload :String, "interscript/node/item/string"
54
+ autoload :Group, "interscript/node/item/group"
55
+ autoload :Any, "interscript/node/item/any"
56
+ autoload :Stage, "interscript/node/item/stage"
57
+ autoload :CaptureGroup, "interscript/node/item/capture"
58
+ autoload :Repeat, "interscript/node/item/repeat"
59
+ # Maybe, MaybeSome, Some are subclasses of Repeat defined in
60
+ # the same file. Autoload points to repeat.rb which defines all of them.
61
+ autoload :Maybe, "interscript/node/item/repeat"
62
+ autoload :MaybeSome, "interscript/node/item/repeat"
63
+ autoload :Some, "interscript/node/item/repeat"
64
+ # standard:disable Layout/TrailingEmptyLines (deliberate)
65
+ end
66
+ # standard:enable Layout/TrailingEmptyLines
@@ -1,12 +1,13 @@
1
1
  class Interscript::Node::MetaData < Interscript::Node
2
2
  attr_accessor :data
3
- def initialize data={}
3
+ def initialize data = {}
4
4
  @data = data
5
5
  end
6
6
 
7
- def []=(k,v)
7
+ def []=(k, v)
8
8
  @data[k] = v
9
9
  end
10
+
10
11
  def [](k)
11
12
  @data[k]
12
13
  end
@@ -18,11 +19,11 @@ class Interscript::Node::MetaData < Interscript::Node
18
19
  end
19
20
 
20
21
  def ==(other)
21
- super && self.data == other.data
22
+ super && data == other.data
22
23
  end
23
24
 
24
25
  def to_hash
25
- {:class => self.class.to_s,
26
- :data => @data}
26
+ {class: self.class.to_s,
27
+ data: @data}
27
28
  end
28
29
  end
@@ -7,10 +7,9 @@ class Interscript::Node::Rule::Funcall < Interscript::Node::Rule
7
7
  end
8
8
 
9
9
  def to_hash
10
- { :class => self.class.to_s,
11
- :name => self.name,
12
- :kwargs => self.kwargs
13
- }
10
+ {class: self.class.to_s,
11
+ name: name,
12
+ kwargs: kwargs}
14
13
  end
15
14
 
16
15
  def reverse
@@ -19,7 +18,7 @@ class Interscript::Node::Rule::Funcall < Interscript::Node::Rule
19
18
  end
20
19
 
21
20
  def ==
22
- super && self.name == other.name && self.kwargs == other.kwargs
21
+ super && name == other.name && kwargs == other.kwargs
23
22
  end
24
23
 
25
24
  def inspect
@@ -6,18 +6,17 @@ class Interscript::Node::Rule::Run < Interscript::Node::Rule
6
6
  end
7
7
 
8
8
  def to_hash
9
- { :class => self.class.to_s,
10
- :stage => self.stage.to_hash }
9
+ {class: self.class.to_s,
10
+ stage: stage.to_hash}
11
11
  end
12
12
 
13
13
  def reverse
14
14
  Interscript::Node::Rule::Run.new(stage,
15
- reverse_run: reverse_run.nil? ? nil : !reverse_run
16
- )
15
+ reverse_run: reverse_run.nil? ? nil : !reverse_run)
17
16
  end
18
17
 
19
18
  def ==(other)
20
- super && self.stage == other.stage
19
+ super && stage == other.stage
21
20
  end
22
21
 
23
22
  def inspect