code-ruby 0.5.5 → 0.6.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 (218) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -4
  3. data/Gemfile.lock +10 -22
  4. data/code-ruby.gemspec +4 -3
  5. data/lib/code/error.rb +16 -5
  6. data/lib/code/node/base_10.rb +4 -2
  7. data/lib/code/node/base_16.rb +3 -1
  8. data/lib/code/node/base_2.rb +3 -1
  9. data/lib/code/node/base_8.rb +3 -1
  10. data/lib/code/node/boolean.rb +4 -2
  11. data/lib/code/node/call.rb +35 -12
  12. data/lib/code/node/call_argument.rb +16 -5
  13. data/lib/code/node/code.rb +5 -4
  14. data/lib/code/node/decimal.rb +2 -0
  15. data/lib/code/node/{dictionnary.rb → dictionary.rb} +14 -5
  16. data/lib/code/node/function.rb +7 -4
  17. data/lib/code/node/function_parameter.rb +3 -1
  18. data/lib/code/node/if.rb +5 -3
  19. data/lib/code/node/left_operation.rb +63 -0
  20. data/lib/code/node/list.rb +2 -0
  21. data/lib/code/node/negation.rb +2 -0
  22. data/lib/code/node/not.rb +2 -0
  23. data/lib/code/node/nothing.rb +3 -1
  24. data/lib/code/node/number.rb +2 -0
  25. data/lib/code/node/right_operation.rb +70 -0
  26. data/lib/code/node/splat.rb +2 -0
  27. data/lib/code/node/square_bracket.rb +37 -0
  28. data/lib/code/node/statement.rb +13 -5
  29. data/lib/code/node/string.rb +3 -1
  30. data/lib/code/node/ternary.rb +5 -3
  31. data/lib/code/node/unary_minus.rb +2 -0
  32. data/lib/code/node/while.rb +6 -4
  33. data/lib/code/node.rb +11 -5
  34. data/lib/code/object/argument.rb +13 -7
  35. data/lib/code/object/boolean.rb +43 -5
  36. data/lib/code/object/class.rb +17 -0
  37. data/lib/code/object/context.rb +36 -0
  38. data/lib/code/object/decimal.rb +252 -100
  39. data/lib/code/object/dictionary.rb +641 -0
  40. data/lib/code/object/function.rb +54 -27
  41. data/lib/code/object/global.rb +65 -19
  42. data/lib/code/object/identifier_list.rb +47 -0
  43. data/lib/code/object/integer.rb +320 -137
  44. data/lib/code/object/list.rb +140 -138
  45. data/lib/code/object/nothing.rb +10 -4
  46. data/lib/code/object/number.rb +6 -1
  47. data/lib/code/object/range.rb +85 -88
  48. data/lib/code/object/ruby_function.rb +11 -6
  49. data/lib/code/object/string.rb +51 -48
  50. data/lib/code/object.rb +117 -139
  51. data/lib/code/parser/addition.rb +4 -2
  52. data/lib/code/parser/and_operator.rb +4 -2
  53. data/lib/code/parser/bitwise_and.rb +4 -2
  54. data/lib/code/parser/bitwise_or.rb +4 -2
  55. data/lib/code/parser/boolean.rb +3 -1
  56. data/lib/code/parser/call.rb +17 -11
  57. data/lib/code/parser/chained_call.rb +10 -22
  58. data/lib/code/parser/class.rb +9 -6
  59. data/lib/code/parser/code.rb +6 -4
  60. data/lib/code/parser/{dictionnary.rb → dictionary.rb} +16 -13
  61. data/lib/code/parser/equal.rb +9 -36
  62. data/lib/code/parser/equality.rb +4 -2
  63. data/lib/code/parser/function.rb +24 -9
  64. data/lib/code/parser/greater.rb +6 -3
  65. data/lib/code/parser/group.rb +4 -2
  66. data/lib/code/parser/if.rb +6 -4
  67. data/lib/code/parser/if_modifier.rb +5 -25
  68. data/lib/code/parser/left_operation.rb +40 -0
  69. data/lib/code/parser/list.rb +6 -5
  70. data/lib/code/parser/multiplication.rb +4 -2
  71. data/lib/code/parser/name.rb +19 -4
  72. data/lib/code/parser/negation.rb +4 -2
  73. data/lib/code/parser/not_keyword.rb +5 -3
  74. data/lib/code/parser/nothing.rb +3 -10
  75. data/lib/code/parser/number.rb +4 -2
  76. data/lib/code/parser/or_keyword.rb +4 -2
  77. data/lib/code/parser/or_operator.rb +4 -2
  78. data/lib/code/parser/power.rb +4 -28
  79. data/lib/code/parser/range.rb +4 -2
  80. data/lib/code/parser/rescue.rb +6 -26
  81. data/lib/code/parser/right_operation.rb +40 -0
  82. data/lib/code/parser/shift.rb +4 -2
  83. data/lib/code/parser/splat.rb +5 -3
  84. data/lib/code/parser/square_bracket.rb +48 -0
  85. data/lib/code/parser/statement.rb +3 -1
  86. data/lib/code/parser/string.rb +12 -10
  87. data/lib/code/parser/ternary.rb +10 -11
  88. data/lib/code/parser/unary_minus.rb +5 -3
  89. data/lib/code/parser/while.rb +5 -3
  90. data/lib/code/parser/whitespace.rb +2 -0
  91. data/lib/code/parser.rb +10 -3
  92. data/lib/code/ruby.rb +4 -2
  93. data/lib/code/type/hash.rb +38 -0
  94. data/lib/code/type/maybe.rb +29 -0
  95. data/lib/code/type/or.rb +38 -0
  96. data/lib/code/type/repeat.rb +38 -0
  97. data/lib/code/type/sig.rb +130 -0
  98. data/lib/code/type.rb +25 -0
  99. data/lib/code/version.rb +3 -0
  100. data/lib/code-ruby.rb +1 -2
  101. data/lib/code.rb +15 -16
  102. data/spec/code/node/call_spec.rb +39 -0
  103. data/spec/code/object/boolean_spec.rb +18 -0
  104. data/spec/code/object/decimal_spec.rb +51 -0
  105. data/spec/code/object/dictionary_spec.rb +98 -0
  106. data/spec/code/object/function_spec.rb +42 -0
  107. data/spec/code/object/integer_spec.rb +43 -0
  108. data/spec/code/object/nothing_spec.rb +14 -0
  109. data/spec/code/object/range_spec.rb +23 -0
  110. data/spec/code/parser/boolean_spec.rb +5 -10
  111. data/spec/code/parser/chained_call.rb +4 -5
  112. data/spec/code/parser/{dictionnary_spec.rb → dictionary_spec.rb} +5 -6
  113. data/spec/code/parser/function_spec.rb +4 -5
  114. data/spec/code/parser/group_spec.rb +5 -12
  115. data/spec/code/parser/if_modifier_spec.rb +18 -0
  116. data/spec/code/parser/list_spec.rb +4 -5
  117. data/spec/code/parser/number_spec.rb +4 -5
  118. data/spec/code/parser/string_spec.rb +4 -5
  119. data/spec/code/parser_spec.rb +22 -16
  120. data/spec/code/type_spec.rb +21 -0
  121. data/spec/code_spec.rb +171 -0
  122. data/spec/spec_helper.rb +1 -6
  123. metadata +61 -137
  124. data/.cherry.js +0 -21
  125. data/.editorconfig +0 -9
  126. data/.github/workflows/rspec.yml +0 -14
  127. data/.gitignore +0 -2
  128. data/.prettierrc +0 -3
  129. data/.tool-versions +0 -1
  130. data/CHANGELOG.md +0 -55
  131. data/LICENSE +0 -7
  132. data/README.md +0 -103
  133. data/TODO +0 -17
  134. data/bin/code +0 -76
  135. data/bin/format +0 -3
  136. data/bin/publish +0 -19
  137. data/bin/template +0 -85
  138. data/bin/test +0 -17
  139. data/docs/class.code +0 -9
  140. data/docs/euler/1.template +0 -10
  141. data/docs/euler/2.template +0 -16
  142. data/docs/euler/3.template +0 -16
  143. data/docs/euler/4.template +0 -10
  144. data/docs/euler/5.template +0 -13
  145. data/docs/fibonnaci.template +0 -14
  146. data/docs/meetup.code +0 -12
  147. data/docs/precedence.template +0 -36
  148. data/docs/rain.code +0 -22
  149. data/docs/slack.code +0 -17
  150. data/docs/stripe.code +0 -7
  151. data/docs/twitter.code +0 -9
  152. data/language-ruby.gemspec +0 -17
  153. data/lib/code/node/chained_call.rb +0 -23
  154. data/lib/code/node/equal.rb +0 -34
  155. data/lib/code/node/if_modifier.rb +0 -47
  156. data/lib/code/node/operation.rb +0 -38
  157. data/lib/code/node/power.rb +0 -20
  158. data/lib/code/node/rescue.rb +0 -17
  159. data/lib/code/object/dictionnary.rb +0 -96
  160. data/lib/code/parser/equality_lower.rb +0 -9
  161. data/lib/code/parser/operation.rb +0 -35
  162. data/lib/language/atom.rb +0 -342
  163. data/lib/language/output.rb +0 -130
  164. data/lib/language/parser/absent/present.rb +0 -8
  165. data/lib/language/parser/absent.rb +0 -6
  166. data/lib/language/parser/end_of_input.rb +0 -6
  167. data/lib/language/parser/interuption.rb +0 -38
  168. data/lib/language/parser/not_end_of_input.rb +0 -6
  169. data/lib/language/parser/str/not_found.rb +0 -16
  170. data/lib/language/parser/str.rb +0 -6
  171. data/lib/language/parser.rb +0 -53
  172. data/lib/language-ruby.rb +0 -10
  173. data/lib/language.rb +0 -80
  174. data/lib/template/node/code_part.rb +0 -13
  175. data/lib/template/node/part.rb +0 -19
  176. data/lib/template/node/template.rb +0 -15
  177. data/lib/template/node/text_part.rb +0 -13
  178. data/lib/template/node.rb +0 -4
  179. data/lib/template/parser/template.rb +0 -39
  180. data/lib/template/parser.rb +0 -19
  181. data/lib/template/version.rb +0 -3
  182. data/lib/template-ruby.rb +0 -10
  183. data/lib/template.rb +0 -50
  184. data/spec/code/addition_spec.rb +0 -13
  185. data/spec/code/and_operator_spec.rb +0 -13
  186. data/spec/code/bitwise_and_spec.rb +0 -13
  187. data/spec/code/bitwise_or_spec.rb +0 -13
  188. data/spec/code/boolean_spec.rb +0 -13
  189. data/spec/code/call_spec.rb +0 -21
  190. data/spec/code/chained_call_spec.rb +0 -16
  191. data/spec/code/code_spec.rb +0 -11
  192. data/spec/code/dictionnary_spec.rb +0 -17
  193. data/spec/code/equal_spec.rb +0 -26
  194. data/spec/code/equality_spec.rb +0 -13
  195. data/spec/code/function_spec.rb +0 -18
  196. data/spec/code/greater_spec.rb +0 -18
  197. data/spec/code/group_spec.rb +0 -12
  198. data/spec/code/if_modifier_spec.rb +0 -20
  199. data/spec/code/if_spec.rb +0 -25
  200. data/spec/code/list_spec.rb +0 -19
  201. data/spec/code/multiplication_spec.rb +0 -18
  202. data/spec/code/negation_spec.rb +0 -20
  203. data/spec/code/not_keyword_spec.rb +0 -13
  204. data/spec/code/nothing_spec.rb +0 -17
  205. data/spec/code/number_spec.rb +0 -22
  206. data/spec/code/or_keyword_spec.rb +0 -17
  207. data/spec/code/or_operator_spec.rb +0 -16
  208. data/spec/code/parser/call_spec.rb +0 -26
  209. data/spec/code/power_spec.rb +0 -13
  210. data/spec/code/range_spec.rb +0 -16
  211. data/spec/code/rescue_spec.rb +0 -13
  212. data/spec/code/shift_spec.rb +0 -13
  213. data/spec/code/splat_spec.rb +0 -13
  214. data/spec/code/string_spec.rb +0 -27
  215. data/spec/code/ternary_spec.rb +0 -18
  216. data/spec/code/unary_minus_spec.rb +0 -13
  217. data/spec/code/while_spec.rb +0 -18
  218. data/template-ruby.gemspec +0 -19
@@ -1,23 +1,29 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- RSpec.describe "Code::Parser" do
4
- subject { Code::Parser.parse(input) }
3
+ require "spec_helper"
5
4
 
5
+ RSpec.describe Code::Parser do
6
6
  [
7
- ["", []],
8
- [" ", []],
9
- ["\n", []],
10
- ["nothing", [{ nothing: "nothing" }]],
11
- [" nothing ", [{ nothing: "nothing" }]],
12
- [
13
- "nothing null nil",
14
- [{ nothing: "nothing" }, { nothing: "null" }, { nothing: "nil" }]
15
- ]
16
- ].each do |input, output|
17
- context input.inspect do
18
- let(:input) { input }
7
+ "",
8
+ " ",
9
+ "\n",
10
+ "# comment",
11
+ "/* comment",
12
+ "/* comment */",
13
+ "// comment",
14
+ "/* first comment */ # second comment",
15
+ "nothing",
16
+ " nothing ",
17
+ "nothing nothing nothing"
18
+ ].each do |input, _output|
19
+ it input.inspect do
20
+ Code::Parser.parse(input)
21
+ end
22
+ end
19
23
 
20
- it { expect(subject).to eq(output) }
24
+ Dir["spec/fixtures/code/parser/**/*.code"].each do |filename|
25
+ it "parses #{filename}" do
26
+ Code::Parser.parse(File.read(filename))
21
27
  end
22
28
  end
23
29
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Code::Type do
6
+ describe "valid" do
7
+ ["1 + 2", "2 * 3.4"].each do |input|
8
+ it input do
9
+ expect { Code.evaluate(input) }.to_not raise_error
10
+ end
11
+ end
12
+ end
13
+
14
+ describe "invalid" do
15
+ ["1 - :a", "2 * true"].each do |input|
16
+ it input do
17
+ expect { Code.evaluate(input) }.to raise_error(Code::Error::TypeError)
18
+ end
19
+ end
20
+ end
21
+ end
data/spec/code_spec.rb ADDED
@@ -0,0 +1,171 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Code do
6
+ [
7
+ ["1 + 1", "2"],
8
+ ["a = 1", "1"],
9
+ ["a = 1 b = 2 c = a + b c", "3"],
10
+ ["a = 1 a += 1 a", "2"],
11
+ ["a = b = c = 1 a + b + c", "3"],
12
+ ["3.times {}", "3"],
13
+ ["a = 1 3.times { a += 1 } a", "4"],
14
+ ['user = {} user[:name] = "Dorian" user[:name]', ":Dorian"],
15
+ ['user = {} user.name = "Dorian" user.name', ":Dorian"],
16
+ [
17
+ "user = { name: :Dorian, age: 31 } user.delete_if(String) user.keys",
18
+ '["age"]'
19
+ ],
20
+ [
21
+ "(user = { name: :Dorian, age: 31 }).transform_values { user.name }.age",
22
+ ":Dorian"
23
+ ],
24
+ ["1 & 1", "1"],
25
+ ["true && false", "false"],
26
+ ["true && true", "true"],
27
+ ["1 | 2", "3"],
28
+ ["1 ^ 2", "3"],
29
+ %w[true true],
30
+ %w[false false],
31
+ ["[1, 2, 3].select { |n| n.even? }", "[2]"],
32
+ ["[1, 2, 3].select { |n| n.even? }.select { |n| n.odd? }", "[]"],
33
+ %w[{} {}],
34
+ ["{ a: 1, b: 2, c: 3 }", '{"a" => 1, "b" => 2, "c" => 3}'],
35
+ ['{ "first_name": "Dorian" }', '{"first_name" => "Dorian"}'],
36
+ ["a = 1 a", "1"],
37
+ ["a = 1 a += 1 a", "2"],
38
+ ["a = 1 a -= 1 a", "0"],
39
+ ["a = 1 a *= 2 a", "2"],
40
+ ["a = 1 a /= 2 a", "0.5"],
41
+ ["a = 10 a %= 2 a", "0"],
42
+ ["a = 1 a >>= 1 a", "0"],
43
+ ["a = 1 a <<= 1 a", "2"],
44
+ ["a = 1 a |= 2 a", "3"],
45
+ ["a = 1 a ^= 2 a", "3"],
46
+ ["a = false a ||= true a", "true"],
47
+ ["a = false a &&= true a", "false"],
48
+ ["1 == 1", "true"],
49
+ ["1 == 1 and 2 == 2", "true"],
50
+ ["1 > 2", "false"],
51
+ ["1 < 2", "true"],
52
+ ["1 <= 1", "true"],
53
+ ["1 >= 1", "true"],
54
+ ["(true false)", "false"],
55
+ ["if true 1", "1"],
56
+ ["unless false 1", "1"],
57
+ ["if false 1", "nothing"],
58
+ ["unless true 1", "nothing"],
59
+ ["if false 1 else 2", "2"],
60
+ ["if false 1 elsif true 2", "2"],
61
+ ["if false 1 elsif false 2", "nothing"],
62
+ ["if false 1 else if true 2", "2"],
63
+ ["if false 1 else if false 2", "nothing"],
64
+ ["if false 1 else unless false 2", "2"],
65
+ ["if false 1 else unless true 2", "nothing"],
66
+ ["[]", "[]"],
67
+ ["[1, 2, 3]", "[1, 2, 3]"],
68
+ ["[1, 2, 3].include?(2)", "true"],
69
+ ["[1, 2, 3].include?(4)", "false"],
70
+ ["[[true]]", "[[true]]"],
71
+ ["2 * 3", "6"],
72
+ ["2 * 3 + 2", "8"],
73
+ ["2 + 2 * 3", "8"],
74
+ ["2 / 4", "0.5"],
75
+ ["4 % 3", "1"],
76
+ %w[!false true],
77
+ %w[!!true true],
78
+ %w[!!1 true],
79
+ %w[+1 1],
80
+ %w[+1.0 1.0],
81
+ %w[+true true],
82
+ ["not true", "false"],
83
+ ["not not false", "false"],
84
+ %w[0 0],
85
+ %w[1.1 1.1],
86
+ %w[0x10 16],
87
+ %w[0o10 8],
88
+ %w[0b10 2],
89
+ %w[1e1 10],
90
+ %w[1.0e1 10.0],
91
+ %w[10e1.0 100.0],
92
+ ["true or false", "true"],
93
+ ["true and false", "false"],
94
+ ["random = 1 random", "1"],
95
+ ["true || false", "true"],
96
+ ["false || false", "false"],
97
+ ["2 ** 3", "8"],
98
+ ["2 ** 3 ** 2", "512"],
99
+ ["a rescue :oops", ":oops"],
100
+ ["[1, 2].map(&:to_string)", "[:1, :2]"],
101
+ %w['' ""],
102
+ %w["" ''],
103
+ %w[:hello :hello],
104
+ %w[:admin? :admin?],
105
+ %w[:update!.to_string :update!],
106
+ ["'Hello Dorian'", '"Hello Dorian"'],
107
+ ['"Hello Dorian"', '"Hello Dorian"'],
108
+ ["'Hello \\{name}'", ':Hello + " \\{name}"'],
109
+ ['"Hello \\{name}"', '"Hello \\{" + "name}"'],
110
+ ["'Hello {1}'", '"Hello 1"'],
111
+ ['"Hello {1}"', '"Hello 1"'],
112
+ %w["Hello".include?("H") true],
113
+ %w["Hello".downcase :hello],
114
+ ["true ? 1", "1"],
115
+ ["false ? 1", ""],
116
+ ["true ? 1 : 2", "1"],
117
+ ["false ? 1 : 2", "2"],
118
+ %w[-1 -1],
119
+ %w[--1 1],
120
+ %w[-1.0 -1.0],
121
+ %w[--1.0 1.0],
122
+ ["while false", "nothing"],
123
+ ["a = 0\nwhile a < 10 a += 1 end a", "10"],
124
+ ["until true", "nothing"],
125
+ ["a = 0\nuntil a > 10 a += 1 end a", "11"],
126
+ ["1 >> 1", "0"],
127
+ ["1 << 1", "2"],
128
+ ["[1, 2].map(&:to_string)", '["1", "2"]']
129
+ ].each do |input, expected|
130
+ it "#{input} == #{expected}" do
131
+ expect(Code.evaluate(input)).to eq(Code.evaluate(expected))
132
+ end
133
+ end
134
+
135
+ [["puts(true)", "true\n"], %w[print(false) false]].each do |input, expected|
136
+ it "#{input} prints #{expected}" do
137
+ io = StringIO.new
138
+ Code.evaluate(input, io:)
139
+ expect(io.string).to eq(expected)
140
+ end
141
+ end
142
+
143
+ it "converts nil" do
144
+ ruby = Code::Ruby.from_code(Code.evaluate("a", ruby: { a: nil }))
145
+
146
+ expect(ruby).to eq(nil)
147
+ end
148
+
149
+ it "works with downcase" do
150
+ expect(Code.evaluate("downcase", "{ downcase: 1 }")).to eq(
151
+ Code.evaluate("1")
152
+ )
153
+ end
154
+
155
+ it "works with nested objects" do
156
+ expect(
157
+ Code.evaluate("items.first.title", ruby: { items: [{ title: "Hello" }] })
158
+ ).to eq(Code.evaluate(":Hello"))
159
+ end
160
+
161
+ it "works with arrays" do
162
+ expect(
163
+ Code.evaluate(
164
+ "items.map { |item| item.title }",
165
+ ruby: {
166
+ items: [{ title: "Hello" }]
167
+ }
168
+ )
169
+ ).to eq(Code.evaluate("[:Hello]"))
170
+ end
171
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1 @@
1
- require_relative "../lib/template-ruby"
2
- require "json"
3
-
4
- RSpec.configure do |c|
5
- c.example_status_persistence_file_path = "tmp/examples.txt"
6
- end
1
+ require_relative "../lib/code-ruby"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-13 00:00:00.000000000 Z
11
+ date: 2023-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -24,45 +24,30 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: language-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: 'A programming language, like Code.evaluate("1 + 1") # => 2'
28
42
  email: dorian@dorianmarie.fr
29
43
  executables: []
30
44
  extensions: []
31
45
  extra_rdoc_files: []
32
46
  files:
33
- - ".cherry.js"
34
- - ".editorconfig"
35
- - ".github/workflows/rspec.yml"
36
- - ".gitignore"
37
- - ".prettierrc"
38
47
  - ".rspec"
39
- - ".tool-versions"
40
- - CHANGELOG.md
41
48
  - Gemfile
42
49
  - Gemfile.lock
43
- - LICENSE
44
- - README.md
45
- - TODO
46
- - bin/code
47
- - bin/format
48
- - bin/publish
49
- - bin/template
50
- - bin/test
51
50
  - code-ruby.gemspec
52
- - docs/class.code
53
- - docs/euler/1.template
54
- - docs/euler/2.template
55
- - docs/euler/3.template
56
- - docs/euler/4.template
57
- - docs/euler/5.template
58
- - docs/fibonnaci.template
59
- - docs/meetup.code
60
- - docs/precedence.template
61
- - docs/rain.code
62
- - docs/slack.code
63
- - docs/stripe.code
64
- - docs/twitter.code
65
- - language-ruby.gemspec
66
51
  - lib/code-ruby.rb
67
52
  - lib/code.rb
68
53
  - lib/code/error.rb
@@ -74,24 +59,21 @@ files:
74
59
  - lib/code/node/boolean.rb
75
60
  - lib/code/node/call.rb
76
61
  - lib/code/node/call_argument.rb
77
- - lib/code/node/chained_call.rb
78
62
  - lib/code/node/code.rb
79
63
  - lib/code/node/decimal.rb
80
- - lib/code/node/dictionnary.rb
81
- - lib/code/node/equal.rb
64
+ - lib/code/node/dictionary.rb
82
65
  - lib/code/node/function.rb
83
66
  - lib/code/node/function_parameter.rb
84
67
  - lib/code/node/if.rb
85
- - lib/code/node/if_modifier.rb
68
+ - lib/code/node/left_operation.rb
86
69
  - lib/code/node/list.rb
87
70
  - lib/code/node/negation.rb
88
71
  - lib/code/node/not.rb
89
72
  - lib/code/node/nothing.rb
90
73
  - lib/code/node/number.rb
91
- - lib/code/node/operation.rb
92
- - lib/code/node/power.rb
93
- - lib/code/node/rescue.rb
74
+ - lib/code/node/right_operation.rb
94
75
  - lib/code/node/splat.rb
76
+ - lib/code/node/square_bracket.rb
95
77
  - lib/code/node/statement.rb
96
78
  - lib/code/node/string.rb
97
79
  - lib/code/node/ternary.rb
@@ -100,10 +82,13 @@ files:
100
82
  - lib/code/object.rb
101
83
  - lib/code/object/argument.rb
102
84
  - lib/code/object/boolean.rb
85
+ - lib/code/object/class.rb
86
+ - lib/code/object/context.rb
103
87
  - lib/code/object/decimal.rb
104
- - lib/code/object/dictionnary.rb
88
+ - lib/code/object/dictionary.rb
105
89
  - lib/code/object/function.rb
106
90
  - lib/code/object/global.rb
91
+ - lib/code/object/identifier_list.rb
107
92
  - lib/code/object/integer.rb
108
93
  - lib/code/object/list.rb
109
94
  - lib/code/object/nothing.rb
@@ -121,15 +106,15 @@ files:
121
106
  - lib/code/parser/chained_call.rb
122
107
  - lib/code/parser/class.rb
123
108
  - lib/code/parser/code.rb
124
- - lib/code/parser/dictionnary.rb
109
+ - lib/code/parser/dictionary.rb
125
110
  - lib/code/parser/equal.rb
126
111
  - lib/code/parser/equality.rb
127
- - lib/code/parser/equality_lower.rb
128
112
  - lib/code/parser/function.rb
129
113
  - lib/code/parser/greater.rb
130
114
  - lib/code/parser/group.rb
131
115
  - lib/code/parser/if.rb
132
116
  - lib/code/parser/if_modifier.rb
117
+ - lib/code/parser/left_operation.rb
133
118
  - lib/code/parser/list.rb
134
119
  - lib/code/parser/multiplication.rb
135
120
  - lib/code/parser/name.rb
@@ -137,14 +122,15 @@ files:
137
122
  - lib/code/parser/not_keyword.rb
138
123
  - lib/code/parser/nothing.rb
139
124
  - lib/code/parser/number.rb
140
- - lib/code/parser/operation.rb
141
125
  - lib/code/parser/or_keyword.rb
142
126
  - lib/code/parser/or_operator.rb
143
127
  - lib/code/parser/power.rb
144
128
  - lib/code/parser/range.rb
145
129
  - lib/code/parser/rescue.rb
130
+ - lib/code/parser/right_operation.rb
146
131
  - lib/code/parser/shift.rb
147
132
  - lib/code/parser/splat.rb
133
+ - lib/code/parser/square_bracket.rb
148
134
  - lib/code/parser/statement.rb
149
135
  - lib/code/parser/string.rb
150
136
  - lib/code/parser/ternary.rb
@@ -152,74 +138,35 @@ files:
152
138
  - lib/code/parser/while.rb
153
139
  - lib/code/parser/whitespace.rb
154
140
  - lib/code/ruby.rb
155
- - lib/language-ruby.rb
156
- - lib/language.rb
157
- - lib/language/atom.rb
158
- - lib/language/output.rb
159
- - lib/language/parser.rb
160
- - lib/language/parser/absent.rb
161
- - lib/language/parser/absent/present.rb
162
- - lib/language/parser/end_of_input.rb
163
- - lib/language/parser/interuption.rb
164
- - lib/language/parser/not_end_of_input.rb
165
- - lib/language/parser/str.rb
166
- - lib/language/parser/str/not_found.rb
167
- - lib/template-ruby.rb
168
- - lib/template.rb
169
- - lib/template/node.rb
170
- - lib/template/node/code_part.rb
171
- - lib/template/node/part.rb
172
- - lib/template/node/template.rb
173
- - lib/template/node/text_part.rb
174
- - lib/template/parser.rb
175
- - lib/template/parser/template.rb
176
- - lib/template/version.rb
177
- - spec/code/addition_spec.rb
178
- - spec/code/and_operator_spec.rb
179
- - spec/code/bitwise_and_spec.rb
180
- - spec/code/bitwise_or_spec.rb
181
- - spec/code/boolean_spec.rb
182
- - spec/code/call_spec.rb
183
- - spec/code/chained_call_spec.rb
184
- - spec/code/code_spec.rb
185
- - spec/code/dictionnary_spec.rb
186
- - spec/code/equal_spec.rb
187
- - spec/code/equality_spec.rb
188
- - spec/code/function_spec.rb
189
- - spec/code/greater_spec.rb
190
- - spec/code/group_spec.rb
191
- - spec/code/if_modifier_spec.rb
192
- - spec/code/if_spec.rb
193
- - spec/code/list_spec.rb
194
- - spec/code/multiplication_spec.rb
195
- - spec/code/negation_spec.rb
196
- - spec/code/not_keyword_spec.rb
197
- - spec/code/nothing_spec.rb
198
- - spec/code/number_spec.rb
199
- - spec/code/or_keyword_spec.rb
200
- - spec/code/or_operator_spec.rb
141
+ - lib/code/type.rb
142
+ - lib/code/type/hash.rb
143
+ - lib/code/type/maybe.rb
144
+ - lib/code/type/or.rb
145
+ - lib/code/type/repeat.rb
146
+ - lib/code/type/sig.rb
147
+ - lib/code/version.rb
148
+ - spec/code/node/call_spec.rb
149
+ - spec/code/object/boolean_spec.rb
150
+ - spec/code/object/decimal_spec.rb
151
+ - spec/code/object/dictionary_spec.rb
152
+ - spec/code/object/function_spec.rb
153
+ - spec/code/object/integer_spec.rb
154
+ - spec/code/object/nothing_spec.rb
155
+ - spec/code/object/range_spec.rb
201
156
  - spec/code/parser/boolean_spec.rb
202
- - spec/code/parser/call_spec.rb
203
157
  - spec/code/parser/chained_call.rb
204
- - spec/code/parser/dictionnary_spec.rb
158
+ - spec/code/parser/dictionary_spec.rb
205
159
  - spec/code/parser/function_spec.rb
206
160
  - spec/code/parser/group_spec.rb
161
+ - spec/code/parser/if_modifier_spec.rb
207
162
  - spec/code/parser/list_spec.rb
208
163
  - spec/code/parser/number_spec.rb
209
164
  - spec/code/parser/string_spec.rb
210
165
  - spec/code/parser_spec.rb
211
- - spec/code/power_spec.rb
212
- - spec/code/range_spec.rb
213
- - spec/code/rescue_spec.rb
214
- - spec/code/shift_spec.rb
215
- - spec/code/splat_spec.rb
216
- - spec/code/string_spec.rb
217
- - spec/code/ternary_spec.rb
218
- - spec/code/unary_minus_spec.rb
219
- - spec/code/while_spec.rb
166
+ - spec/code/type_spec.rb
167
+ - spec/code_spec.rb
220
168
  - spec/spec_helper.rb
221
- - template-ruby.gemspec
222
- homepage: https://github.com/dorianmariefr/template-ruby
169
+ homepage: https://github.com/dorianmariefr/code-ruby
223
170
  licenses:
224
171
  - MIT
225
172
  metadata: {}
@@ -238,52 +185,29 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
185
  - !ruby/object:Gem::Version
239
186
  version: '0'
240
187
  requirements: []
241
- rubygems_version: 3.3.26
188
+ rubygems_version: 3.4.22
242
189
  signing_key:
243
190
  specification_version: 4
244
191
  summary: A programming language
245
192
  test_files:
246
- - spec/code/addition_spec.rb
247
- - spec/code/and_operator_spec.rb
248
- - spec/code/bitwise_and_spec.rb
249
- - spec/code/bitwise_or_spec.rb
250
- - spec/code/boolean_spec.rb
251
- - spec/code/call_spec.rb
252
- - spec/code/chained_call_spec.rb
253
- - spec/code/code_spec.rb
254
- - spec/code/dictionnary_spec.rb
255
- - spec/code/equal_spec.rb
256
- - spec/code/equality_spec.rb
257
- - spec/code/function_spec.rb
258
- - spec/code/greater_spec.rb
259
- - spec/code/group_spec.rb
260
- - spec/code/if_modifier_spec.rb
261
- - spec/code/if_spec.rb
262
- - spec/code/list_spec.rb
263
- - spec/code/multiplication_spec.rb
264
- - spec/code/negation_spec.rb
265
- - spec/code/not_keyword_spec.rb
266
- - spec/code/nothing_spec.rb
267
- - spec/code/number_spec.rb
268
- - spec/code/or_keyword_spec.rb
269
- - spec/code/or_operator_spec.rb
193
+ - spec/code/node/call_spec.rb
194
+ - spec/code/object/boolean_spec.rb
195
+ - spec/code/object/decimal_spec.rb
196
+ - spec/code/object/dictionary_spec.rb
197
+ - spec/code/object/function_spec.rb
198
+ - spec/code/object/integer_spec.rb
199
+ - spec/code/object/nothing_spec.rb
200
+ - spec/code/object/range_spec.rb
270
201
  - spec/code/parser/boolean_spec.rb
271
- - spec/code/parser/call_spec.rb
272
202
  - spec/code/parser/chained_call.rb
273
- - spec/code/parser/dictionnary_spec.rb
203
+ - spec/code/parser/dictionary_spec.rb
274
204
  - spec/code/parser/function_spec.rb
275
205
  - spec/code/parser/group_spec.rb
206
+ - spec/code/parser/if_modifier_spec.rb
276
207
  - spec/code/parser/list_spec.rb
277
208
  - spec/code/parser/number_spec.rb
278
209
  - spec/code/parser/string_spec.rb
279
210
  - spec/code/parser_spec.rb
280
- - spec/code/power_spec.rb
281
- - spec/code/range_spec.rb
282
- - spec/code/rescue_spec.rb
283
- - spec/code/shift_spec.rb
284
- - spec/code/splat_spec.rb
285
- - spec/code/string_spec.rb
286
- - spec/code/ternary_spec.rb
287
- - spec/code/unary_minus_spec.rb
288
- - spec/code/while_spec.rb
211
+ - spec/code/type_spec.rb
212
+ - spec/code_spec.rb
289
213
  - spec/spec_helper.rb
data/.cherry.js DELETED
@@ -1,21 +0,0 @@
1
- module.exports = {
2
- project_name: 'dorianmariefr/template-ruby',
3
- metrics: [
4
- {
5
- name: 'todo',
6
- pattern: /TODO:/i,
7
- },
8
- {
9
- name: 'fixme',
10
- pattern: /FIXME:/i,
11
- },
12
- {
13
- name: 'rubocop',
14
- pattern: /rubocop:disable/,
15
- },
16
- {
17
- name: 'eslint',
18
- pattern: /eslint-disable/,
19
- },
20
- ],
21
- }
data/.editorconfig DELETED
@@ -1,9 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- charset = utf-8
5
- end_of_line = lf
6
- insert_final_newline = true
7
- indent_style = space
8
- indent_size = 2
9
- trim_trailing_whitespace = true
@@ -1,14 +0,0 @@
1
- name: RSpec
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- build:
7
- name: RSpec
8
- runs-on: ubuntu-latest
9
-
10
- steps:
11
- - uses: actions/checkout@v1
12
- - uses: actions/setup-ruby@v1
13
- - run: bundle install
14
- - run: bundle exec rspec
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- *.gem
2
- tmp/
data/.prettierrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "rubyPlugins": "plugin/trailing_comma"
3
- }
data/.tool-versions DELETED
@@ -1 +0,0 @@
1
- ruby 3.1.3
data/CHANGELOG.md DELETED
@@ -1,55 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## 0.4.0 / 2022-10-21
9
-
10
- - Rewrite of how functions are called internally (no more `public_send`)
11
- - Call ruby functions from template/code
12
-
13
- ## 0.3.1 / 2022-10-13
14
-
15
- - Fix Zeitwerk auto-loading issue
16
-
17
- ## 0.3.0 / 2022-10-10
18
-
19
- - `bin/template` accepts `--timeout` (or `-t`) parameter
20
- - Adds `bin/code` with same options as `bin/template`
21
- - Prevent loose syntax like `{ a: }`, `[1,,,]` and `()`
22
- - Change precedence of defined? (to allow `defined?(name) ? name : nothing`)
23
- - Updates parsers to allow `while false end == nothing`
24
- - String interpolations like `"1 + 1 = {1 + 1}"`
25
- - `context(:name)` to get a function without calling it for instance
26
- - `.to_string` on all objects
27
- - `1 + "a"` and `"a" + 1.0` for instance now convert to strings
28
- - `Dictionnary#each` e.g. `{ a: 1 }.each { |k, v| print(k) }`
29
- - Fix context duplication issue that was preventing implementation of recursive
30
- functions like Fibonacci
31
-
32
- ## 0.2.4 / 2022-08-02
33
-
34
- - Add method `String#*`, e.g. `{"Dorian " \* 2}" -> "Dorian Dorian "
35
- - Add executable to gem, e.g. `template --help`
36
-
37
- ## 0.2.3 / 2022-08-31
38
-
39
- - Add default timeout for code and template parsing and evaluation
40
-
41
- ## 0.2.2 / 2022-08-31
42
-
43
- - Fix parsing error when the template is empty, e.g. ""
44
-
45
- ## 0.2.1 / 2022-08-31
46
-
47
- - Fix parsing error on empty code like `Hello {`
48
-
49
- ## 0.2.0 / 2022-08-30
50
-
51
- - Programming language capable of solving the first 5 Project Euler problems
52
-
53
- ## 0.1.0 / 2022-07-28
54
-
55
- - Initial version with interpolation