template-ruby 0.5.6 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -4
  3. data/Gemfile.lock +15 -22
  4. data/lib/template/version.rb +1 -1
  5. data/lib/template-ruby.rb +2 -3
  6. data/lib/template.rb +18 -22
  7. data/spec/spec_helper.rb +0 -5
  8. data/spec/template_spec.rb +13 -0
  9. data/template-ruby.gemspec +2 -1
  10. metadata +34 -222
  11. data/.cherry.js +0 -21
  12. data/.editorconfig +0 -9
  13. data/.github/workflows/rspec.yml +0 -14
  14. data/.gitignore +0 -2
  15. data/.prettierrc +0 -3
  16. data/.tool-versions +0 -1
  17. data/CHANGELOG.md +0 -55
  18. data/LICENSE +0 -7
  19. data/README.md +0 -103
  20. data/TODO +0 -17
  21. data/bin/code +0 -76
  22. data/bin/format +0 -3
  23. data/bin/publish +0 -19
  24. data/bin/template +0 -85
  25. data/bin/test +0 -17
  26. data/code-ruby.gemspec +0 -17
  27. data/docs/class.code +0 -9
  28. data/docs/euler/1.template +0 -10
  29. data/docs/euler/2.template +0 -16
  30. data/docs/euler/3.template +0 -16
  31. data/docs/euler/4.template +0 -10
  32. data/docs/euler/5.template +0 -13
  33. data/docs/fibonnaci.template +0 -14
  34. data/docs/meetup.code +0 -12
  35. data/docs/precedence.template +0 -36
  36. data/docs/rain.code +0 -22
  37. data/docs/slack.code +0 -17
  38. data/docs/stripe.code +0 -7
  39. data/docs/twitter.code +0 -9
  40. data/language-ruby.gemspec +0 -17
  41. data/lib/code/error.rb +0 -18
  42. data/lib/code/node/base_10.rb +0 -29
  43. data/lib/code/node/base_16.rb +0 -13
  44. data/lib/code/node/base_2.rb +0 -13
  45. data/lib/code/node/base_8.rb +0 -13
  46. data/lib/code/node/boolean.rb +0 -22
  47. data/lib/code/node/call.rb +0 -47
  48. data/lib/code/node/call_argument.rb +0 -21
  49. data/lib/code/node/chained_call.rb +0 -23
  50. data/lib/code/node/code.rb +0 -20
  51. data/lib/code/node/decimal.rb +0 -26
  52. data/lib/code/node/dictionnary.rb +0 -33
  53. data/lib/code/node/equal.rb +0 -34
  54. data/lib/code/node/function.rb +0 -20
  55. data/lib/code/node/function_parameter.rb +0 -31
  56. data/lib/code/node/if.rb +0 -59
  57. data/lib/code/node/if_modifier.rb +0 -47
  58. data/lib/code/node/list.rb +0 -16
  59. data/lib/code/node/negation.rb +0 -15
  60. data/lib/code/node/not.rb +0 -15
  61. data/lib/code/node/nothing.rb +0 -12
  62. data/lib/code/node/number.rb +0 -25
  63. data/lib/code/node/operation.rb +0 -38
  64. data/lib/code/node/power.rb +0 -20
  65. data/lib/code/node/rescue.rb +0 -17
  66. data/lib/code/node/splat.rb +0 -15
  67. data/lib/code/node/statement.rb +0 -59
  68. data/lib/code/node/string.rb +0 -53
  69. data/lib/code/node/ternary.rb +0 -24
  70. data/lib/code/node/unary_minus.rb +0 -15
  71. data/lib/code/node/while.rb +0 -35
  72. data/lib/code/node.rb +0 -13
  73. data/lib/code/object/argument.rb +0 -32
  74. data/lib/code/object/boolean.rb +0 -27
  75. data/lib/code/object/decimal.rb +0 -162
  76. data/lib/code/object/dictionnary.rb +0 -96
  77. data/lib/code/object/function.rb +0 -64
  78. data/lib/code/object/global.rb +0 -42
  79. data/lib/code/object/integer.rb +0 -221
  80. data/lib/code/object/list.rb +0 -207
  81. data/lib/code/object/nothing.rb +0 -23
  82. data/lib/code/object/number.rb +0 -6
  83. data/lib/code/object/range.rb +0 -146
  84. data/lib/code/object/ruby_function.rb +0 -31
  85. data/lib/code/object/string.rb +0 -102
  86. data/lib/code/object.rb +0 -197
  87. data/lib/code/parser/addition.rb +0 -21
  88. data/lib/code/parser/and_operator.rb +0 -17
  89. data/lib/code/parser/bitwise_and.rb +0 -17
  90. data/lib/code/parser/bitwise_or.rb +0 -21
  91. data/lib/code/parser/boolean.rb +0 -17
  92. data/lib/code/parser/call.rb +0 -122
  93. data/lib/code/parser/chained_call.rb +0 -47
  94. data/lib/code/parser/class.rb +0 -45
  95. data/lib/code/parser/code.rb +0 -25
  96. data/lib/code/parser/dictionnary.rb +0 -67
  97. data/lib/code/parser/equal.rb +0 -94
  98. data/lib/code/parser/equality.rb +0 -35
  99. data/lib/code/parser/equality_lower.rb +0 -9
  100. data/lib/code/parser/function.rb +0 -85
  101. data/lib/code/parser/greater.rb +0 -25
  102. data/lib/code/parser/group.rb +0 -22
  103. data/lib/code/parser/if.rb +0 -63
  104. data/lib/code/parser/if_modifier.rb +0 -55
  105. data/lib/code/parser/list.rb +0 -42
  106. data/lib/code/parser/multiplication.rb +0 -25
  107. data/lib/code/parser/name.rb +0 -107
  108. data/lib/code/parser/negation.rb +0 -30
  109. data/lib/code/parser/not_keyword.rb +0 -23
  110. data/lib/code/parser/nothing.rb +0 -22
  111. data/lib/code/parser/number.rb +0 -154
  112. data/lib/code/parser/operation.rb +0 -35
  113. data/lib/code/parser/or_keyword.rb +0 -21
  114. data/lib/code/parser/or_operator.rb +0 -17
  115. data/lib/code/parser/power.rb +0 -43
  116. data/lib/code/parser/range.rb +0 -17
  117. data/lib/code/parser/rescue.rb +0 -39
  118. data/lib/code/parser/shift.rb +0 -21
  119. data/lib/code/parser/splat.rb +0 -31
  120. data/lib/code/parser/statement.rb +0 -9
  121. data/lib/code/parser/string.rb +0 -78
  122. data/lib/code/parser/ternary.rb +0 -46
  123. data/lib/code/parser/unary_minus.rb +0 -31
  124. data/lib/code/parser/while.rb +0 -36
  125. data/lib/code/parser/whitespace.rb +0 -49
  126. data/lib/code/parser.rb +0 -19
  127. data/lib/code/ruby.rb +0 -174
  128. data/lib/code-ruby.rb +0 -10
  129. data/lib/code.rb +0 -47
  130. data/lib/language/atom.rb +0 -342
  131. data/lib/language/output.rb +0 -130
  132. data/lib/language/parser/absent/present.rb +0 -8
  133. data/lib/language/parser/absent.rb +0 -6
  134. data/lib/language/parser/end_of_input.rb +0 -6
  135. data/lib/language/parser/interuption.rb +0 -38
  136. data/lib/language/parser/not_end_of_input.rb +0 -6
  137. data/lib/language/parser/str/not_found.rb +0 -16
  138. data/lib/language/parser/str.rb +0 -6
  139. data/lib/language/parser.rb +0 -53
  140. data/lib/language-ruby.rb +0 -10
  141. data/lib/language.rb +0 -80
  142. data/spec/code/addition_spec.rb +0 -13
  143. data/spec/code/and_operator_spec.rb +0 -13
  144. data/spec/code/bitwise_and_spec.rb +0 -13
  145. data/spec/code/bitwise_or_spec.rb +0 -13
  146. data/spec/code/boolean_spec.rb +0 -13
  147. data/spec/code/call_spec.rb +0 -21
  148. data/spec/code/chained_call_spec.rb +0 -16
  149. data/spec/code/code_spec.rb +0 -29
  150. data/spec/code/dictionnary_spec.rb +0 -17
  151. data/spec/code/equal_spec.rb +0 -26
  152. data/spec/code/equality_spec.rb +0 -13
  153. data/spec/code/function_spec.rb +0 -18
  154. data/spec/code/greater_spec.rb +0 -18
  155. data/spec/code/group_spec.rb +0 -12
  156. data/spec/code/if_modifier_spec.rb +0 -20
  157. data/spec/code/if_spec.rb +0 -25
  158. data/spec/code/list_spec.rb +0 -19
  159. data/spec/code/multiplication_spec.rb +0 -18
  160. data/spec/code/negation_spec.rb +0 -20
  161. data/spec/code/not_keyword_spec.rb +0 -13
  162. data/spec/code/nothing_spec.rb +0 -17
  163. data/spec/code/number_spec.rb +0 -22
  164. data/spec/code/or_keyword_spec.rb +0 -17
  165. data/spec/code/or_operator_spec.rb +0 -16
  166. data/spec/code/parser/boolean_spec.rb +0 -16
  167. data/spec/code/parser/call_spec.rb +0 -26
  168. data/spec/code/parser/chained_call.rb +0 -17
  169. data/spec/code/parser/dictionnary_spec.rb +0 -18
  170. data/spec/code/parser/function_spec.rb +0 -16
  171. data/spec/code/parser/group_spec.rb +0 -18
  172. data/spec/code/parser/list_spec.rb +0 -18
  173. data/spec/code/parser/number_spec.rb +0 -12
  174. data/spec/code/parser/string_spec.rb +0 -21
  175. data/spec/code/parser_spec.rb +0 -23
  176. data/spec/code/power_spec.rb +0 -13
  177. data/spec/code/range_spec.rb +0 -16
  178. data/spec/code/rescue_spec.rb +0 -13
  179. data/spec/code/shift_spec.rb +0 -13
  180. data/spec/code/splat_spec.rb +0 -13
  181. data/spec/code/string_spec.rb +0 -27
  182. data/spec/code/ternary_spec.rb +0 -18
  183. data/spec/code/unary_minus_spec.rb +0 -13
  184. data/spec/code/while_spec.rb +0 -18
@@ -1,47 +0,0 @@
1
- class Code
2
- class Node
3
- class Call < Node
4
- class Block < Node
5
- def initialize(parsed)
6
- @parameters =
7
- parsed
8
- .delete(:parameters) { [] }
9
- .map { |parameter| Node::FunctionParameter.new(parameter) }
10
-
11
- @body = Node::Code.new(parsed.delete(:body))
12
-
13
- super(parsed)
14
- end
15
-
16
- def evaluate(**args)
17
- ::Code::Object::Argument.new(
18
- ::Code::Object::Function.new(parameters: @parameters, body: @body)
19
- )
20
- end
21
- end
22
-
23
- def initialize(parsed)
24
- @name = parsed.delete(:name)
25
- @arguments =
26
- parsed
27
- .delete(:arguments) { [] }
28
- .map { |argument| Node::CallArgument.new(argument) }
29
-
30
- if parsed.key?(:block)
31
- @block = Node::Call::Block.new(parsed.delete(:block))
32
- end
33
-
34
- super(parsed)
35
- end
36
-
37
- def evaluate(**args)
38
- arguments = @arguments.map { |argument| argument.evaluate(**args) }
39
- arguments << @block.evaluate(**args) if @block
40
-
41
- name = ::Code::Object::String.new(@name)
42
-
43
- args.fetch(:object).call(operator: name, arguments: arguments, **args)
44
- end
45
- end
46
- end
47
- end
@@ -1,21 +0,0 @@
1
- class Code
2
- class Node
3
- class CallArgument < Node
4
- def initialize(parsed)
5
- @value = Node::Code.new(parsed.delete(:value))
6
- @name = parsed.delete(:name)
7
- end
8
-
9
- def evaluate(**args)
10
- if @name
11
- ::Code::Object::Argument.new(
12
- @value.evaluate(**args),
13
- name: ::Code::Object::String.new(@name)
14
- )
15
- else
16
- ::Code::Object::Argument.new(@value.evaluate(**args))
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,23 +0,0 @@
1
- class Code
2
- class Node
3
- class ChainedCall < Node
4
- def initialize(parsed)
5
- @first = Node::Statement.new(parsed.delete(:first))
6
- @others =
7
- parsed
8
- .delete(:others)
9
- .map { |operator| Node::Statement.new(operator) }
10
-
11
- super(parsed)
12
- end
13
-
14
- def evaluate(**args)
15
- first = @first.evaluate(**args)
16
-
17
- @others.reduce(first) do |acc, element|
18
- element.evaluate(**args.merge(object: acc))
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,20 +0,0 @@
1
- class Code
2
- class Node
3
- class Code < Node
4
- def initialize(parsed)
5
- @statements = parsed.map { |statement| Node::Statement.new(statement) }
6
- end
7
-
8
- def evaluate(**args)
9
- last = ::Code::Object::Nothing.new
10
-
11
- @statements.each do |statement|
12
- last =
13
- statement.evaluate(**args.merge(object: ::Code::Object::Global.new))
14
- end
15
-
16
- last
17
- end
18
- end
19
- end
20
- end
@@ -1,26 +0,0 @@
1
- class Code
2
- class Node
3
- class Decimal < Node
4
- def initialize(parsed)
5
- @decimal = parsed.delete(:decimal)
6
-
7
- if parsed.key?(:exponent)
8
- @exponent = Node::Statement.new(parsed.delete(:exponent))
9
- end
10
-
11
- super(parsed)
12
- end
13
-
14
- def evaluate(**args)
15
- if @exponent
16
- ::Code::Object::Decimal.new(
17
- @decimal,
18
- exponent: @exponent.evaluate(**args)
19
- )
20
- else
21
- ::Code::Object::Decimal.new(@decimal)
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,33 +0,0 @@
1
- class Code
2
- class Node
3
- class Dictionnary < Node
4
- class KeyValue < Node
5
- def initialize(parsed)
6
- if parsed.key?(:statement)
7
- @key = Node::Statement.new(parsed.delete(:statement))
8
- elsif parsed.key?(:name)
9
- @key = Node::String.new([{ text: parsed.delete(:name) }])
10
- end
11
-
12
- @value = Node::Code.new(parsed.delete(:value))
13
- end
14
-
15
- def evaluate(**args)
16
- [@key.evaluate(**args), @value.evaluate(**args)]
17
- end
18
- end
19
-
20
- def initialize(parsed)
21
- parsed = [] if parsed == ""
22
- @key_values =
23
- parsed.map { |key_value| Node::Dictionnary::KeyValue.new(key_value) }
24
- end
25
-
26
- def evaluate(**args)
27
- ::Code::Object::Dictionnary.new(
28
- @key_values.map { |key_value| key_value.evaluate(**args) }.to_h
29
- )
30
- end
31
- end
32
- end
33
- end
@@ -1,34 +0,0 @@
1
- class Code
2
- class Node
3
- class Equal < Node
4
- def initialize(parsed)
5
- @operator = parsed.delete(:operator)
6
- @left = parsed.delete(:left)
7
- @right = Node::Statement.new(parsed.delete(:right))
8
- super(parsed)
9
- end
10
-
11
- def evaluate(**args)
12
- right = @right.evaluate(**args)
13
- left = ::Code::Object::String.new(@left)
14
- context = args.fetch(:context)
15
-
16
- if @operator == ""
17
- context[left] = right
18
- else
19
- if context[left].nil?
20
- raise ::Code::Error::Undefined.new("#{left} is not defined")
21
- end
22
-
23
- context[left] = context.fetch(left).call(
24
- operator: @operator,
25
- arguments: [::Code::Object::Argument.new(right)],
26
- **args
27
- )
28
- end
29
-
30
- args[:context][left]
31
- end
32
- end
33
- end
34
- end
@@ -1,20 +0,0 @@
1
- class Code
2
- class Node
3
- class Function < Node
4
- def initialize(parsed)
5
- @parameters =
6
- parsed
7
- .delete(:parameters) { [] }
8
- .map { |parameter| Node::FunctionParameter.new(parameter) }
9
-
10
- @body = Node::Code.new(parsed.delete(:body))
11
-
12
- super(parsed)
13
- end
14
-
15
- def evaluate(**args)
16
- ::Code::Object::Function.new(parameters: @parameters, body: @body)
17
- end
18
- end
19
- end
20
- end
@@ -1,31 +0,0 @@
1
- class Code
2
- class Node
3
- class FunctionParameter < Node
4
- def initialize(parsed)
5
- @name = parsed.delete(:name)
6
- @keyword = !!parsed.delete(:keyword)
7
- super(parsed)
8
- end
9
-
10
- def name
11
- ::Code::Object::String.new(@name)
12
- end
13
-
14
- def regular?
15
- !@keyword
16
- end
17
-
18
- def keyword?
19
- !!@keyword
20
- end
21
-
22
- def regular_splat?
23
- false
24
- end
25
-
26
- def keyword_splat?
27
- false
28
- end
29
- end
30
- end
31
- end
data/lib/code/node/if.rb DELETED
@@ -1,59 +0,0 @@
1
- class Code
2
- class Node
3
- class If < Node
4
- IF_KEYWORD = "if"
5
- UNLESS_KEYWORD = "unless"
6
- ELSIF_KEYWORD = "elsif"
7
- ELSE_KEYWORD = "else"
8
-
9
- class Else < Node
10
- attr_reader :operator, :statement, :body
11
-
12
- def initialize(parsed)
13
- @operator = parsed.delete(:operator)
14
- @body = Node::Code.new(parsed.delete(:body))
15
-
16
- if parsed.key?(:statement)
17
- @statement = Node::Statement.new(parsed.delete(:statement))
18
- end
19
- end
20
- end
21
-
22
- def initialize(parsed)
23
- @first_operator = parsed.delete(:first_operator)
24
- @first_statement = Node::Statement.new(parsed.delete(:first_statement))
25
- @first_body = Node::Code.new(parsed.delete(:first_body))
26
- @elses =
27
- parsed.delete(:elses) { [] }.map { |elses| Node::If::Else.new(elses) }
28
- super(parsed)
29
- end
30
-
31
- def evaluate(**args)
32
- if @first_operator == IF_KEYWORD &&
33
- @first_statement.evaluate(**args).truthy?
34
- @first_body.evaluate(**args)
35
- elsif @first_operator == UNLESS_KEYWORD &&
36
- @first_statement.evaluate(**args).falsy?
37
- @first_body.evaluate(**args)
38
- else
39
- @elses.each do |elses|
40
- if elses.operator == ELSIF_KEYWORD &&
41
- elses.statement.evaluate(**args).truthy?
42
- return elses.body.evaluate(**args)
43
- elsif elses.operator == IF_KEYWORD &&
44
- elses.statement.evaluate(**args).truthy?
45
- return elses.body.evaluate(**args)
46
- elsif elses.operator == UNLESS_KEYWORD &&
47
- elses.statement.evaluate(**args).falsy?
48
- return elses.body.evaluate(**args)
49
- elsif elses.operator == ELSE_KEYWORD
50
- return elses.body.evaluate(**args)
51
- end
52
- end
53
-
54
- ::Code::Object::Nothing.new
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,47 +0,0 @@
1
- class Code
2
- class Node
3
- class IfModifier < Node
4
- IF_KEYWORD = "if"
5
- UNLESS_KEYWORD = "unless"
6
- WHILE_KEYWORD = "while"
7
- UNTIL_KEYWORD = "until"
8
-
9
- def initialize(parsed)
10
- @operator = parsed.delete(:operator)
11
- @left = Node::Statement.new(parsed.delete(:left))
12
- @right = Node::Statement.new(parsed.delete(:right))
13
- super(parsed)
14
- end
15
-
16
- def evaluate(**args)
17
- if @operator == IF_KEYWORD
18
- if @right.evaluate(**args).truthy?
19
- @left.evaluate(**args)
20
- else
21
- ::Code::Object::Nothing.new
22
- end
23
- elsif @operator == UNLESS_KEYWORD
24
- if @right.evaluate(**args).falsy?
25
- @left.evaluate(**args)
26
- else
27
- ::Code::Object::Nothing.new
28
- end
29
- elsif @operator == WHILE_KEYWORD
30
- last = ::Code::Object::Nothing.new
31
-
32
- last = @left.evaluate(**args) while @right.evaluate(**args).truthy?
33
-
34
- last
35
- elsif @operator == UNTIL_KEYWORD
36
- last = ::Code::Object::Nothing.new
37
-
38
- last = @left.evaluate(**args) while @right.evaluate(**args).falsy?
39
-
40
- last
41
- else
42
- raise NotImplementedError.new(@operator)
43
- end
44
- end
45
- end
46
- end
47
- end
@@ -1,16 +0,0 @@
1
- class Code
2
- class Node
3
- class List < Node
4
- def initialize(parsed)
5
- parsed = [] if parsed == ""
6
- @elements = parsed.map { |element| Node::Code.new(element) }
7
- end
8
-
9
- def evaluate(**args)
10
- ::Code::Object::List.new(
11
- @elements.map { |element| element.evaluate(**args) }
12
- )
13
- end
14
- end
15
- end
16
- end
@@ -1,15 +0,0 @@
1
- class Code
2
- class Node
3
- class Negation < Node
4
- def initialize(parsed)
5
- @operator = parsed.delete(:operator)
6
- @right = Node::Statement.new(parsed.delete(:right))
7
- super(parsed)
8
- end
9
-
10
- def evaluate(**args)
11
- @right.evaluate(**args).call(operator: @operator, arguments: [], **args)
12
- end
13
- end
14
- end
15
- end
data/lib/code/node/not.rb DELETED
@@ -1,15 +0,0 @@
1
- class Code
2
- class Node
3
- class Not < Node
4
- def initialize(parsed)
5
- @operator = parsed.delete(:operator)
6
- @right = Node::Statement.new(parsed.delete(:right))
7
- super(parsed)
8
- end
9
-
10
- def evaluate(**args)
11
- @right.evaluate(**args).call(operator: @operator, arguments: [], **args)
12
- end
13
- end
14
- end
15
- end
@@ -1,12 +0,0 @@
1
- class Code
2
- class Node
3
- class Nothing < Node
4
- def initialize(parsed)
5
- end
6
-
7
- def evaluate(**args)
8
- ::Code::Object::Nothing.new
9
- end
10
- end
11
- end
12
- end
@@ -1,25 +0,0 @@
1
- class Code
2
- class Node
3
- class Number < Node
4
- def initialize(parsed)
5
- if parsed.key?(:decimal)
6
- @statement = Node::Decimal.new(parsed.delete(:decimal))
7
- elsif parsed.key?(:base_16)
8
- @statement = Node::Base16.new(parsed.delete(:base_16))
9
- elsif parsed.key?(:base_10)
10
- @statement = Node::Base10.new(parsed.delete(:base_10))
11
- elsif parsed.key?(:base_8)
12
- @statement = Node::Base8.new(parsed.delete(:base_8))
13
- elsif parsed.key?(:base_2)
14
- @statement = Node::Base2.new(parsed.delete(:base_2))
15
- end
16
-
17
- super(parsed)
18
- end
19
-
20
- def evaluate(**args)
21
- @statement.evaluate(**args)
22
- end
23
- end
24
- end
25
- end
@@ -1,38 +0,0 @@
1
- class Code
2
- class Node
3
- class Operation < Node
4
- class Operator < Node
5
- attr_reader :operator, :statement
6
-
7
- def initialize(parsed)
8
- @operator = parsed.delete(:operator)
9
- @statement = Node::Statement.new(parsed.delete(:statement))
10
- end
11
- end
12
-
13
- def initialize(parsed)
14
- @first = Node::Statement.new(parsed.delete(:first))
15
- @others =
16
- parsed
17
- .delete(:others)
18
- .map { |operator| Node::Operation::Operator.new(operator) }
19
-
20
- super(parsed)
21
- end
22
-
23
- def evaluate(**args)
24
- first = @first.evaluate(**args)
25
-
26
- @others.reduce(first) do |left, right|
27
- statement = right.statement.evaluate(**args)
28
-
29
- left.call(
30
- operator: right.operator,
31
- arguments: [::Code::Object::Argument.new(statement)],
32
- **args
33
- )
34
- end
35
- end
36
- end
37
- end
38
- end
@@ -1,20 +0,0 @@
1
- class Code
2
- class Node
3
- class Power < Node
4
- def initialize(parsed)
5
- @operator = parsed.delete(:operator)
6
- @left = Node::Statement.new(parsed.delete(:left))
7
- @right = Node::Statement.new(parsed.delete(:right))
8
- super(parsed)
9
- end
10
-
11
- def evaluate(**args)
12
- @left.evaluate(**args).call(
13
- operator: @operator,
14
- arguments: [::Code::Object::Argument.new(@right.evaluate(**args))],
15
- **args
16
- )
17
- end
18
- end
19
- end
20
- end
@@ -1,17 +0,0 @@
1
- class Code
2
- class Node
3
- class Rescue < Node
4
- def initialize(parsed)
5
- @left = Node::Statement.new(parsed.delete(:left))
6
- @right = Node::Statement.new(parsed.delete(:right))
7
- super(parsed)
8
- end
9
-
10
- def evaluate(**args)
11
- @left.evaluate(**args)
12
- rescue ::Code::Error
13
- @right.evaluate(**args)
14
- end
15
- end
16
- end
17
- end
@@ -1,15 +0,0 @@
1
- class Code
2
- class Node
3
- class Splat < Node
4
- def initialize(parsed)
5
- @operator = parsed.delete(:operator)
6
- @right = Node::Statement.new(parsed.delete(:right))
7
- super(parsed)
8
- end
9
-
10
- def evaluate(**args)
11
- @right.evaluate(**args).call(operator: @operator, arguments: [], **args)
12
- end
13
- end
14
- end
15
- end
@@ -1,59 +0,0 @@
1
- class Code
2
- class Node
3
- class Statement < Node
4
- def initialize(parsed)
5
- if parsed.key?(:nothing)
6
- @statement = Node::Nothing.new(parsed.delete(:nothing))
7
- elsif parsed.key?(:boolean)
8
- @statement = Node::Boolean.new(parsed.delete(:boolean))
9
- elsif parsed.key?(:group)
10
- @statement = Node::Code.new(parsed.delete(:group))
11
- elsif parsed.key?(:call)
12
- @statement = Node::Call.new(parsed.delete(:call))
13
- elsif parsed.key?(:number)
14
- @statement = Node::Number.new(parsed.delete(:number))
15
- elsif parsed.key?(:string)
16
- @statement = Node::String.new(parsed.delete(:string))
17
- elsif parsed.key?(:list)
18
- @statement = Node::List.new(parsed.delete(:list))
19
- elsif parsed.key?(:dictionnary)
20
- @statement = Node::Dictionnary.new(parsed.delete(:dictionnary))
21
- elsif parsed.key?(:chained_call)
22
- @statement = Node::ChainedCall.new(parsed.delete(:chained_call))
23
- elsif parsed.key?(:operation)
24
- @statement = Node::Operation.new(parsed.delete(:operation))
25
- elsif parsed.key?(:equal)
26
- @statement = Node::Equal.new(parsed.delete(:equal))
27
- elsif parsed.key?(:function)
28
- @statement = Node::Function.new(parsed.delete(:function))
29
- elsif parsed.key?(:negation)
30
- @statement = Node::Negation.new(parsed.delete(:negation))
31
- elsif parsed.key?(:power)
32
- @statement = Node::Power.new(parsed.delete(:power))
33
- elsif parsed.key?(:unary_minus)
34
- @statement = Node::UnaryMinus.new(parsed.delete(:unary_minus))
35
- elsif parsed.key?(:ternary)
36
- @statement = Node::Ternary.new(parsed.delete(:ternary))
37
- elsif parsed.key?(:rescue)
38
- @statement = Node::Rescue.new(parsed.delete(:rescue))
39
- elsif parsed.key?(:not)
40
- @statement = Node::Not.new(parsed.delete(:not))
41
- elsif parsed.key?(:if_modifier)
42
- @statement = Node::IfModifier.new(parsed.delete(:if_modifier))
43
- elsif parsed.key?(:if)
44
- @statement = Node::If.new(parsed.delete(:if))
45
- elsif parsed.key?(:while)
46
- @statement = Node::While.new(parsed.delete(:while))
47
- elsif parsed.key?(:splat)
48
- @statement = Node::Splat.new(parsed.delete(:splat))
49
- end
50
-
51
- super(parsed)
52
- end
53
-
54
- def evaluate(**args)
55
- @statement.evaluate(**args)
56
- end
57
- end
58
- end
59
- end
@@ -1,53 +0,0 @@
1
- class Code
2
- class Node
3
- class String < Node
4
- class Part < Node
5
- class Code < Node
6
- def initialize(parsed)
7
- @code = Node::Code.new(parsed)
8
- end
9
-
10
- def evaluate(**args)
11
- @code.evaluate(**args)
12
- end
13
- end
14
-
15
- class Text < Node
16
- def initialize(parsed)
17
- @text = parsed
18
- end
19
-
20
- def evaluate(**args)
21
- ::Code::Object::String.new(@text)
22
- end
23
- end
24
-
25
- def initialize(parsed)
26
- if parsed.key?(:text)
27
- @part = Node::String::Part::Text.new(parsed.delete(:text))
28
- elsif parsed.key?(:code)
29
- @part = Node::String::Part::Code.new(parsed.delete(:code))
30
- end
31
-
32
- super(parsed)
33
- end
34
-
35
- def evaluate(**args)
36
- @part.evaluate(**args)
37
- end
38
- end
39
-
40
- def initialize(parsed)
41
- parsed = [] if parsed == ""
42
-
43
- @parts = parsed.map { |part| Node::String::Part.new(part) }
44
- end
45
-
46
- def evaluate(**args)
47
- ::Code::Object::String.new(
48
- @parts.map { |part| part.evaluate(**args) }.map(&:to_s).join
49
- )
50
- end
51
- end
52
- end
53
- end