template-ruby 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +14 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile +2 -1
- data/Gemfile.lock +6 -1
- data/LICENSE +7 -0
- data/README.md +98 -5
- data/bin/code +51 -0
- data/bin/template +9 -5
- data/code-ruby.gemspec +22 -0
- data/docs/euler/4.template +0 -1
- data/docs/fibonnaci.template +14 -0
- data/docs/precedence.template +6 -31
- data/lib/code/node/code.rb +7 -1
- data/lib/code/node/list.rb +7 -7
- data/lib/code/node/name.rb +6 -1
- data/lib/code/node/string.rb +11 -6
- data/lib/code/node/string_characters.rb +13 -0
- data/lib/code/node/string_component.rb +23 -0
- data/lib/code/node/string_interpolation.rb +13 -0
- data/lib/code/object/argument.rb +1 -1
- data/lib/code/object/decimal.rb +22 -1
- data/lib/code/object/dictionnary.rb +24 -0
- data/lib/code/object/function.rb +2 -1
- data/lib/code/object/integer.rb +18 -20
- data/lib/code/object/list.rb +4 -0
- data/lib/code/object/string.rb +10 -2
- data/lib/code/object.rb +7 -0
- data/lib/code/parser/and_operator.rb +4 -4
- data/lib/code/parser/call.rb +3 -3
- data/lib/code/parser/code.rb +3 -4
- data/lib/code/parser/defined.rb +2 -2
- data/lib/code/parser/dictionnary.rb +1 -1
- data/lib/code/parser/equality.rb +4 -4
- data/lib/code/parser/function.rb +3 -2
- data/lib/code/parser/group.rb +1 -1
- data/lib/code/parser/if.rb +3 -3
- data/lib/code/parser/list.rb +1 -1
- data/lib/code/parser/not_keyword.rb +2 -2
- data/lib/code/parser/statement.rb +1 -1
- data/lib/code/parser/string.rb +19 -4
- data/lib/code/parser/ternary.rb +3 -3
- data/lib/code-ruby.rb +12 -0
- data/lib/code.rb +10 -10
- data/lib/template/version.rb +3 -0
- data/lib/template-ruby.rb +3 -1
- data/lib/template.rb +21 -11
- data/spec/code/error/type_error_spec.rb +0 -2
- data/spec/code/parser/dictionnary_spec.rb +5 -32
- data/spec/code/parser/string_spec.rb +15 -16
- data/spec/code_spec.rb +13 -0
- data/spec/template_spec.rb +6 -0
- data/template-ruby.gemspec +3 -2
- metadata +15 -4
@@ -4,26 +4,25 @@ RSpec.describe Code::Parser::String do
|
|
4
4
|
subject { described_class.new.parse(input) }
|
5
5
|
|
6
6
|
[
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
].each do |(input, expected)|
|
7
|
+
"'hello'",
|
8
|
+
'"hello"',
|
9
|
+
"''",
|
10
|
+
'""',
|
11
|
+
"'\\''",
|
12
|
+
'"\\t"',
|
13
|
+
"'\\r'",
|
14
|
+
'"\\b\\f\\n\\r\\t"',
|
15
|
+
'"\\uABCG"',
|
16
|
+
"'\\u0123\\u4567\\u89aA\\ubBcC\\UdDeE\\ufFfF'",
|
17
|
+
":asc",
|
18
|
+
"'1 + 1 = {1 + 1}'",
|
19
|
+
"'a + b = {'{'a'}{'b'}'}'"
|
20
|
+
].each do |input|
|
22
21
|
context input.inspect do
|
23
22
|
let(:input) { input }
|
24
23
|
|
25
24
|
it "succeeds" do
|
26
|
-
expect
|
25
|
+
expect { subject }.to_not raise_error
|
27
26
|
end
|
28
27
|
end
|
29
28
|
end
|
data/spec/code_spec.rb
CHANGED
@@ -95,6 +95,19 @@ RSpec.describe Code do
|
|
95
95
|
["until true end", ""],
|
96
96
|
["until true\nend", ""],
|
97
97
|
%w[("Good".."Bad").first Good],
|
98
|
+
['"Dorian " * 2', "Dorian Dorian "],
|
99
|
+
["while false end == nothing", "true"],
|
100
|
+
['"1 + 1 = {1 + 1}"', "1 + 1 = 2"],
|
101
|
+
["'1 + 1 = {1 + 1}'", "1 + 1 = 2"],
|
102
|
+
["{}.to_string + [].to_string", "{}[]"],
|
103
|
+
["'a' + 1", "a1"],
|
104
|
+
["'a' + 1.0", "a1.0"],
|
105
|
+
["1 + 'a'", "1a"],
|
106
|
+
["1.0 + 'a'", "1.0a"],
|
107
|
+
["1 << 1", "2"],
|
108
|
+
["1.0 << 1", "2"],
|
109
|
+
["1 << 1.0", "2"],
|
110
|
+
["1.0 << 1.0", "2"],
|
98
111
|
].each do |(input, expected)|
|
99
112
|
context input.inspect do
|
100
113
|
let(:input) { input }
|
data/spec/template_spec.rb
CHANGED
@@ -12,7 +12,13 @@ RSpec.describe Template do
|
|
12
12
|
'{ user: { first_name: "Dorian" } }',
|
13
13
|
"Hello Dorian",
|
14
14
|
],
|
15
|
+
[
|
16
|
+
"{add(1, 2)",
|
17
|
+
'add = (a, b) => { a + b } { add: context(:add) }',
|
18
|
+
"3",
|
19
|
+
],
|
15
20
|
["Hello {", "", "Hello "],
|
21
|
+
["{{a: 1}.each { |k, v| print(k) } nothing", "", "a"],
|
16
22
|
["", "", ""],
|
17
23
|
].each do |(input, input_context, expected)|
|
18
24
|
context "#{input.inspect} #{input_context.inspect}" do
|
data/template-ruby.gemspec
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require_relative "lib/template
|
1
|
+
require_relative "lib/template/version"
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "template-ruby"
|
5
|
-
s.version = ::Template::
|
5
|
+
s.version = ::Template::Version
|
6
6
|
s.summary = "A templating programming language"
|
7
7
|
s.description =
|
8
8
|
'Like "Hello {name}" with {name: "Dorian"} gives "Hello Dorian"'
|
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.require_paths = ["lib"]
|
14
14
|
s.homepage = "https://github.com/dorianmariefr/template-ruby"
|
15
15
|
s.license = "MIT"
|
16
|
+
s.executables = "template"
|
16
17
|
|
17
18
|
s.add_dependency "activesupport", "~> 7"
|
18
19
|
s.add_dependency "parslet", "~> 2"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: template-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.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: 2022-
|
11
|
+
date: 2022-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -82,25 +82,32 @@ dependencies:
|
|
82
82
|
version: '3'
|
83
83
|
description: 'Like "Hello {name}" with {name: "Dorian"} gives "Hello Dorian"'
|
84
84
|
email: dorian@dorianmarie.fr
|
85
|
-
executables:
|
85
|
+
executables:
|
86
|
+
- template
|
86
87
|
extensions: []
|
87
88
|
extra_rdoc_files: []
|
88
89
|
files:
|
89
90
|
- ".editorconfig"
|
91
|
+
- ".github/workflows/rspec.yml"
|
90
92
|
- ".gitignore"
|
91
93
|
- ".prettierrc"
|
92
94
|
- ".rspec"
|
93
95
|
- CHANGELOG.md
|
94
96
|
- Gemfile
|
95
97
|
- Gemfile.lock
|
98
|
+
- LICENSE
|
96
99
|
- README.md
|
100
|
+
- bin/code
|
97
101
|
- bin/template
|
102
|
+
- code-ruby.gemspec
|
98
103
|
- docs/euler/1.template
|
99
104
|
- docs/euler/2.template
|
100
105
|
- docs/euler/3.template
|
101
106
|
- docs/euler/4.template
|
102
107
|
- docs/euler/5.template
|
108
|
+
- docs/fibonnaci.template
|
103
109
|
- docs/precedence.template
|
110
|
+
- lib/code-ruby.rb
|
104
111
|
- lib/code.rb
|
105
112
|
- lib/code/error.rb
|
106
113
|
- lib/code/node.rb
|
@@ -142,6 +149,9 @@ files:
|
|
142
149
|
- lib/code/node/rescue.rb
|
143
150
|
- lib/code/node/statement.rb
|
144
151
|
- lib/code/node/string.rb
|
152
|
+
- lib/code/node/string_characters.rb
|
153
|
+
- lib/code/node/string_component.rb
|
154
|
+
- lib/code/node/string_interpolation.rb
|
145
155
|
- lib/code/node/ternary.rb
|
146
156
|
- lib/code/node/unary_minus.rb
|
147
157
|
- lib/code/node/while.rb
|
@@ -201,6 +211,7 @@ files:
|
|
201
211
|
- lib/template/node/text_part.rb
|
202
212
|
- lib/template/parser.rb
|
203
213
|
- lib/template/parser/template.rb
|
214
|
+
- lib/template/version.rb
|
204
215
|
- spec/call_spec.rb
|
205
216
|
- spec/code/error/type_error_spec.rb
|
206
217
|
- spec/code/parser/boolean_spec.rb
|
@@ -237,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
248
|
- !ruby/object:Gem::Version
|
238
249
|
version: '0'
|
239
250
|
requirements: []
|
240
|
-
rubygems_version: 3.3.
|
251
|
+
rubygems_version: 3.3.7
|
241
252
|
signing_key:
|
242
253
|
specification_version: 4
|
243
254
|
summary: A templating programming language
|