code-ruby 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +9 -0
- data/.github/workflows/rspec.yml +14 -0
- data/.gitignore +2 -0
- data/.prettierrc +3 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +31 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +70 -0
- data/LICENSE +7 -0
- data/README.md +103 -0
- data/TODO.md +1 -0
- data/bin/template +39 -0
- data/code-ruby.gemspec +22 -0
- data/docs/euler/1.template +14 -0
- data/docs/euler/2.template +16 -0
- data/docs/euler/3.template +16 -0
- data/docs/euler/4.template +11 -0
- data/docs/euler/5.template +14 -0
- data/docs/precedence.template +94 -0
- data/lib/code/error.rb +15 -0
- data/lib/code/node/base_10_decimal.rb +32 -0
- data/lib/code/node/base_10_integer.rb +32 -0
- data/lib/code/node/base_10_number.rb +19 -0
- data/lib/code/node/base_16_number.rb +19 -0
- data/lib/code/node/base_2_number.rb +19 -0
- data/lib/code/node/base_8_number.rb +19 -0
- data/lib/code/node/block.rb +17 -0
- data/lib/code/node/boolean.rb +22 -0
- data/lib/code/node/call.rb +52 -0
- data/lib/code/node/call_argument.rb +37 -0
- data/lib/code/node/chained_call.rb +38 -0
- data/lib/code/node/code.rb +16 -0
- data/lib/code/node/defined.rb +19 -0
- data/lib/code/node/dictionnary.rb +22 -0
- data/lib/code/node/dictionnary_key_value.rb +23 -0
- data/lib/code/node/equal.rb +36 -0
- data/lib/code/node/function.rb +17 -0
- data/lib/code/node/function_argument.rb +45 -0
- data/lib/code/node/group.rb +13 -0
- data/lib/code/node/if.rb +55 -0
- data/lib/code/node/if_modifier.rb +48 -0
- data/lib/code/node/keyword_call_argument.rb +30 -0
- data/lib/code/node/keyword_function_argument.rb +33 -0
- data/lib/code/node/list.rb +19 -0
- data/lib/code/node/name.rb +50 -0
- data/lib/code/node/negation.rb +33 -0
- data/lib/code/node/not_keyword.rb +13 -0
- data/lib/code/node/nothing.rb +12 -0
- data/lib/code/node/number.rb +23 -0
- data/lib/code/node/operation.rb +33 -0
- data/lib/code/node/or_keyword.rb +34 -0
- data/lib/code/node/power.rb +16 -0
- data/lib/code/node/range.rb +31 -0
- data/lib/code/node/regular_call_argument.rb +34 -0
- data/lib/code/node/regular_function_argument.rb +36 -0
- data/lib/code/node/rescue.rb +16 -0
- data/lib/code/node/statement.rb +81 -0
- data/lib/code/node/string.rb +17 -0
- data/lib/code/node/ternary.rb +26 -0
- data/lib/code/node/unary_minus.rb +22 -0
- data/lib/code/node/while.rb +42 -0
- data/lib/code/node.rb +14 -0
- data/lib/code/object/argument.rb +41 -0
- data/lib/code/object/boolean.rb +27 -0
- data/lib/code/object/decimal.rb +54 -0
- data/lib/code/object/dictionnary.rb +55 -0
- data/lib/code/object/function.rb +64 -0
- data/lib/code/object/integer.rb +116 -0
- data/lib/code/object/list.rb +217 -0
- data/lib/code/object/nothing.rb +23 -0
- data/lib/code/object/number.rb +6 -0
- data/lib/code/object/range.rb +158 -0
- data/lib/code/object/string.rb +68 -0
- data/lib/code/object.rb +130 -0
- data/lib/code/parser/addition.rb +29 -0
- data/lib/code/parser/and_operator.rb +28 -0
- data/lib/code/parser/bitwise_and.rb +28 -0
- data/lib/code/parser/bitwise_or.rb +29 -0
- data/lib/code/parser/boolean.rb +14 -0
- data/lib/code/parser/call.rb +90 -0
- data/lib/code/parser/code.rb +19 -0
- data/lib/code/parser/defined.rb +20 -0
- data/lib/code/parser/dictionnary.rb +41 -0
- data/lib/code/parser/equal.rb +42 -0
- data/lib/code/parser/equality.rb +36 -0
- data/lib/code/parser/function.rb +57 -0
- data/lib/code/parser/greater_than.rb +33 -0
- data/lib/code/parser/group.rb +17 -0
- data/lib/code/parser/if.rb +33 -0
- data/lib/code/parser/if_modifier.rb +28 -0
- data/lib/code/parser/list.rb +29 -0
- data/lib/code/parser/multiplication.rb +30 -0
- data/lib/code/parser/name.rb +89 -0
- data/lib/code/parser/negation.rb +19 -0
- data/lib/code/parser/not_keyword.rb +21 -0
- data/lib/code/parser/nothing.rb +17 -0
- data/lib/code/parser/number.rb +98 -0
- data/lib/code/parser/or_keyword.rb +29 -0
- data/lib/code/parser/or_operator.rb +28 -0
- data/lib/code/parser/power.rb +25 -0
- data/lib/code/parser/range.rb +25 -0
- data/lib/code/parser/rescue.rb +23 -0
- data/lib/code/parser/shift.rb +31 -0
- data/lib/code/parser/statement.rb +8 -0
- data/lib/code/parser/string.rb +72 -0
- data/lib/code/parser/ternary.rb +25 -0
- data/lib/code/parser/unary_minus.rb +13 -0
- data/lib/code/parser/while.rb +25 -0
- data/lib/code/parser.rb +4 -0
- data/lib/code-ruby.rb +11 -0
- data/lib/code.rb +29 -0
- data/lib/template/node/code_part.rb +13 -0
- data/lib/template/node/part.rb +19 -0
- data/lib/template/node/template.rb +15 -0
- data/lib/template/node/text_part.rb +13 -0
- data/lib/template/node.rb +4 -0
- data/lib/template/parser/template.rb +30 -0
- data/lib/template/parser.rb +4 -0
- data/lib/template/version.rb +3 -0
- data/lib/template-ruby.rb +11 -0
- data/lib/template.rb +34 -0
- data/spec/call_spec.rb +22 -0
- data/spec/code/error/type_error_spec.rb +65 -0
- data/spec/code/parser/boolean_spec.rb +18 -0
- data/spec/code/parser/call_spec.rb +66 -0
- data/spec/code/parser/dictionnary_spec.rb +46 -0
- data/spec/code/parser/function_spec.rb +32 -0
- data/spec/code/parser/list_spec.rb +29 -0
- data/spec/code/parser/name_spec.rb +15 -0
- data/spec/code/parser/nothing_spec.rb +19 -0
- data/spec/code/parser/number_spec.rb +117 -0
- data/spec/code/parser/string_spec.rb +30 -0
- data/spec/code_spec.rb +108 -0
- data/spec/function_spec.rb +26 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/template/parser/template_spec.rb +19 -0
- data/spec/template_spec.rb +27 -0
- data/template-ruby.gemspec +24 -0
- metadata +266 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Template::Parser::Template do
|
4
|
+
subject { described_class.new.parse(input) }
|
5
|
+
|
6
|
+
[
|
7
|
+
["hello", [{ text: "hello" }]],
|
8
|
+
["hello {name}", [{ text: "hello " }, { code: [{ name: "name" }] }]],
|
9
|
+
["{name", [{ code: [{ name: "name" }] }]],
|
10
|
+
].each do |(input, expected)|
|
11
|
+
context input.inspect do
|
12
|
+
let(:input) { input }
|
13
|
+
|
14
|
+
it "succeeds" do
|
15
|
+
expect(subject).to eq(expected)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Template do
|
4
|
+
subject { described_class.render(input, input_context) }
|
5
|
+
|
6
|
+
[
|
7
|
+
["Hello World", "", "Hello World"],
|
8
|
+
["1 + 1 = {2}", "", "1 + 1 = 2"],
|
9
|
+
["Hello {name}", '{ name: "Dorian" }', "Hello Dorian"],
|
10
|
+
[
|
11
|
+
"Hello {user.first_name}",
|
12
|
+
'{ user: { first_name: "Dorian" } }',
|
13
|
+
"Hello Dorian",
|
14
|
+
],
|
15
|
+
["Hello {", "", "Hello "],
|
16
|
+
["", "", ""],
|
17
|
+
].each do |(input, input_context, expected)|
|
18
|
+
context "#{input.inspect} #{input_context.inspect}" do
|
19
|
+
let(:input) { input }
|
20
|
+
let(:input_context) { input_context }
|
21
|
+
|
22
|
+
it "succeeds" do
|
23
|
+
expect(subject).to eq(expected)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative "lib/template/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "template-ruby"
|
5
|
+
s.version = ::Template::Version
|
6
|
+
s.summary = "A templating programming language"
|
7
|
+
s.description =
|
8
|
+
'Like "Hello {name}" with {name: "Dorian"} gives "Hello Dorian"'
|
9
|
+
s.authors = ["Dorian Marié"]
|
10
|
+
s.email = "dorian@dorianmarie.fr"
|
11
|
+
s.files = `git ls-files`.split($/)
|
12
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
13
|
+
s.require_paths = ["lib"]
|
14
|
+
s.homepage = "https://github.com/dorianmariefr/template-ruby"
|
15
|
+
s.license = "MIT"
|
16
|
+
s.executables = "template"
|
17
|
+
|
18
|
+
s.add_dependency "activesupport", "~> 7"
|
19
|
+
s.add_dependency "parslet", "~> 2"
|
20
|
+
s.add_dependency "zeitwerk", "~> 2.6"
|
21
|
+
|
22
|
+
s.add_development_dependency "prettier", "~> 3"
|
23
|
+
s.add_development_dependency "rspec", "~> 3"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,266 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: code-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dorian Marié
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-09-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: parslet
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: zeitwerk
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.6'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: prettier
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3'
|
83
|
+
description: 'A programming language, like Code.evaluate("1 + 1") # => 2'
|
84
|
+
email: dorian@dorianmarie.fr
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- ".editorconfig"
|
90
|
+
- ".github/workflows/rspec.yml"
|
91
|
+
- ".gitignore"
|
92
|
+
- ".prettierrc"
|
93
|
+
- ".rspec"
|
94
|
+
- CHANGELOG.md
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE
|
98
|
+
- README.md
|
99
|
+
- TODO.md
|
100
|
+
- bin/template
|
101
|
+
- code-ruby.gemspec
|
102
|
+
- docs/euler/1.template
|
103
|
+
- docs/euler/2.template
|
104
|
+
- docs/euler/3.template
|
105
|
+
- docs/euler/4.template
|
106
|
+
- docs/euler/5.template
|
107
|
+
- docs/precedence.template
|
108
|
+
- lib/code-ruby.rb
|
109
|
+
- lib/code.rb
|
110
|
+
- lib/code/error.rb
|
111
|
+
- lib/code/node.rb
|
112
|
+
- lib/code/node/base_10_decimal.rb
|
113
|
+
- lib/code/node/base_10_integer.rb
|
114
|
+
- lib/code/node/base_10_number.rb
|
115
|
+
- lib/code/node/base_16_number.rb
|
116
|
+
- lib/code/node/base_2_number.rb
|
117
|
+
- lib/code/node/base_8_number.rb
|
118
|
+
- lib/code/node/block.rb
|
119
|
+
- lib/code/node/boolean.rb
|
120
|
+
- lib/code/node/call.rb
|
121
|
+
- lib/code/node/call_argument.rb
|
122
|
+
- lib/code/node/chained_call.rb
|
123
|
+
- lib/code/node/code.rb
|
124
|
+
- lib/code/node/defined.rb
|
125
|
+
- lib/code/node/dictionnary.rb
|
126
|
+
- lib/code/node/dictionnary_key_value.rb
|
127
|
+
- lib/code/node/equal.rb
|
128
|
+
- lib/code/node/function.rb
|
129
|
+
- lib/code/node/function_argument.rb
|
130
|
+
- lib/code/node/group.rb
|
131
|
+
- lib/code/node/if.rb
|
132
|
+
- lib/code/node/if_modifier.rb
|
133
|
+
- lib/code/node/keyword_call_argument.rb
|
134
|
+
- lib/code/node/keyword_function_argument.rb
|
135
|
+
- lib/code/node/list.rb
|
136
|
+
- lib/code/node/name.rb
|
137
|
+
- lib/code/node/negation.rb
|
138
|
+
- lib/code/node/not_keyword.rb
|
139
|
+
- lib/code/node/nothing.rb
|
140
|
+
- lib/code/node/number.rb
|
141
|
+
- lib/code/node/operation.rb
|
142
|
+
- lib/code/node/or_keyword.rb
|
143
|
+
- lib/code/node/power.rb
|
144
|
+
- lib/code/node/range.rb
|
145
|
+
- lib/code/node/regular_call_argument.rb
|
146
|
+
- lib/code/node/regular_function_argument.rb
|
147
|
+
- lib/code/node/rescue.rb
|
148
|
+
- lib/code/node/statement.rb
|
149
|
+
- lib/code/node/string.rb
|
150
|
+
- lib/code/node/ternary.rb
|
151
|
+
- lib/code/node/unary_minus.rb
|
152
|
+
- lib/code/node/while.rb
|
153
|
+
- lib/code/object.rb
|
154
|
+
- lib/code/object/argument.rb
|
155
|
+
- lib/code/object/boolean.rb
|
156
|
+
- lib/code/object/decimal.rb
|
157
|
+
- lib/code/object/dictionnary.rb
|
158
|
+
- lib/code/object/function.rb
|
159
|
+
- lib/code/object/integer.rb
|
160
|
+
- lib/code/object/list.rb
|
161
|
+
- lib/code/object/nothing.rb
|
162
|
+
- lib/code/object/number.rb
|
163
|
+
- lib/code/object/range.rb
|
164
|
+
- lib/code/object/string.rb
|
165
|
+
- lib/code/parser.rb
|
166
|
+
- lib/code/parser/addition.rb
|
167
|
+
- lib/code/parser/and_operator.rb
|
168
|
+
- lib/code/parser/bitwise_and.rb
|
169
|
+
- lib/code/parser/bitwise_or.rb
|
170
|
+
- lib/code/parser/boolean.rb
|
171
|
+
- lib/code/parser/call.rb
|
172
|
+
- lib/code/parser/code.rb
|
173
|
+
- lib/code/parser/defined.rb
|
174
|
+
- lib/code/parser/dictionnary.rb
|
175
|
+
- lib/code/parser/equal.rb
|
176
|
+
- lib/code/parser/equality.rb
|
177
|
+
- lib/code/parser/function.rb
|
178
|
+
- lib/code/parser/greater_than.rb
|
179
|
+
- lib/code/parser/group.rb
|
180
|
+
- lib/code/parser/if.rb
|
181
|
+
- lib/code/parser/if_modifier.rb
|
182
|
+
- lib/code/parser/list.rb
|
183
|
+
- lib/code/parser/multiplication.rb
|
184
|
+
- lib/code/parser/name.rb
|
185
|
+
- lib/code/parser/negation.rb
|
186
|
+
- lib/code/parser/not_keyword.rb
|
187
|
+
- lib/code/parser/nothing.rb
|
188
|
+
- lib/code/parser/number.rb
|
189
|
+
- lib/code/parser/or_keyword.rb
|
190
|
+
- lib/code/parser/or_operator.rb
|
191
|
+
- lib/code/parser/power.rb
|
192
|
+
- lib/code/parser/range.rb
|
193
|
+
- lib/code/parser/rescue.rb
|
194
|
+
- lib/code/parser/shift.rb
|
195
|
+
- lib/code/parser/statement.rb
|
196
|
+
- lib/code/parser/string.rb
|
197
|
+
- lib/code/parser/ternary.rb
|
198
|
+
- lib/code/parser/unary_minus.rb
|
199
|
+
- lib/code/parser/while.rb
|
200
|
+
- lib/template-ruby.rb
|
201
|
+
- lib/template.rb
|
202
|
+
- lib/template/node.rb
|
203
|
+
- lib/template/node/code_part.rb
|
204
|
+
- lib/template/node/part.rb
|
205
|
+
- lib/template/node/template.rb
|
206
|
+
- lib/template/node/text_part.rb
|
207
|
+
- lib/template/parser.rb
|
208
|
+
- lib/template/parser/template.rb
|
209
|
+
- lib/template/version.rb
|
210
|
+
- spec/call_spec.rb
|
211
|
+
- spec/code/error/type_error_spec.rb
|
212
|
+
- spec/code/parser/boolean_spec.rb
|
213
|
+
- spec/code/parser/call_spec.rb
|
214
|
+
- spec/code/parser/dictionnary_spec.rb
|
215
|
+
- spec/code/parser/function_spec.rb
|
216
|
+
- spec/code/parser/list_spec.rb
|
217
|
+
- spec/code/parser/name_spec.rb
|
218
|
+
- spec/code/parser/nothing_spec.rb
|
219
|
+
- spec/code/parser/number_spec.rb
|
220
|
+
- spec/code/parser/string_spec.rb
|
221
|
+
- spec/code_spec.rb
|
222
|
+
- spec/function_spec.rb
|
223
|
+
- spec/spec_helper.rb
|
224
|
+
- spec/template/parser/template_spec.rb
|
225
|
+
- spec/template_spec.rb
|
226
|
+
- template-ruby.gemspec
|
227
|
+
homepage: https://github.com/dorianmariefr/template-ruby
|
228
|
+
licenses:
|
229
|
+
- MIT
|
230
|
+
metadata: {}
|
231
|
+
post_install_message:
|
232
|
+
rdoc_options: []
|
233
|
+
require_paths:
|
234
|
+
- lib
|
235
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
236
|
+
requirements:
|
237
|
+
- - ">="
|
238
|
+
- !ruby/object:Gem::Version
|
239
|
+
version: '0'
|
240
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
241
|
+
requirements:
|
242
|
+
- - ">="
|
243
|
+
- !ruby/object:Gem::Version
|
244
|
+
version: '0'
|
245
|
+
requirements: []
|
246
|
+
rubygems_version: 3.3.18
|
247
|
+
signing_key:
|
248
|
+
specification_version: 4
|
249
|
+
summary: A programming language
|
250
|
+
test_files:
|
251
|
+
- spec/call_spec.rb
|
252
|
+
- spec/code/error/type_error_spec.rb
|
253
|
+
- spec/code/parser/boolean_spec.rb
|
254
|
+
- spec/code/parser/call_spec.rb
|
255
|
+
- spec/code/parser/dictionnary_spec.rb
|
256
|
+
- spec/code/parser/function_spec.rb
|
257
|
+
- spec/code/parser/list_spec.rb
|
258
|
+
- spec/code/parser/name_spec.rb
|
259
|
+
- spec/code/parser/nothing_spec.rb
|
260
|
+
- spec/code/parser/number_spec.rb
|
261
|
+
- spec/code/parser/string_spec.rb
|
262
|
+
- spec/code_spec.rb
|
263
|
+
- spec/function_spec.rb
|
264
|
+
- spec/spec_helper.rb
|
265
|
+
- spec/template/parser/template_spec.rb
|
266
|
+
- spec/template_spec.rb
|