template-ruby 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Gemfile +2 -1
- data/Gemfile.lock +27 -54
- data/TODO +17 -0
- data/bin/code +56 -31
- data/bin/format +3 -0
- data/bin/template +62 -20
- data/bin/test +17 -0
- data/code-ruby.gemspec +1 -3
- data/docs/class.code +9 -0
- data/docs/euler/1.template +1 -5
- data/docs/euler/5.template +0 -1
- data/docs/meetup.code +12 -0
- data/docs/precedence.template +6 -39
- data/docs/rain.code +22 -0
- data/docs/slack.code +17 -0
- data/docs/stripe.code +7 -0
- data/docs/twitter.code +9 -0
- data/language-ruby.gemspec +18 -0
- data/lib/code/node/base_10.rb +29 -0
- data/lib/code/node/base_16.rb +13 -0
- data/lib/code/node/base_2.rb +13 -0
- data/lib/code/node/base_8.rb +13 -0
- data/lib/code/node/boolean.rb +7 -7
- data/lib/code/node/call.rb +32 -38
- data/lib/code/node/call_argument.rb +11 -27
- data/lib/code/node/chained_call.rb +10 -27
- data/lib/code/node/code.rb +4 -6
- data/lib/code/node/decimal.rb +26 -0
- data/lib/code/node/dictionnary.rb +20 -9
- data/lib/code/node/equal.rb +18 -20
- data/lib/code/node/function.rb +10 -7
- data/lib/code/node/function_parameter.rb +31 -0
- data/lib/code/node/if.rb +36 -32
- data/lib/code/node/if_modifier.rb +35 -36
- data/lib/code/node/list.rb +6 -8
- data/lib/code/node/negation.rb +5 -23
- data/lib/code/node/not.rb +15 -0
- data/lib/code/node/nothing.rb +1 -1
- data/lib/code/node/number.rb +14 -12
- data/lib/code/node/operation.rb +21 -16
- data/lib/code/node/power.rb +10 -6
- data/lib/code/node/rescue.rb +4 -3
- data/lib/code/node/splat.rb +15 -0
- data/lib/code/node/statement.rb +48 -70
- data/lib/code/node/string.rb +42 -16
- data/lib/code/node/ternary.rb +7 -9
- data/lib/code/node/unary_minus.rb +5 -12
- data/lib/code/node/while.rb +17 -24
- data/lib/code/node.rb +7 -8
- data/lib/code/object/argument.rb +2 -11
- data/lib/code/object/decimal.rb +45 -30
- data/lib/code/object/dictionnary.rb +6 -5
- data/lib/code/object/function.rb +20 -23
- data/lib/code/object/global.rb +11 -6
- data/lib/code/object/integer.rb +73 -30
- data/lib/code/object/list.rb +40 -34
- data/lib/code/object/range.rb +18 -17
- data/lib/code/object/ruby_function.rb +12 -6
- data/lib/code/object/string.rb +22 -12
- data/lib/code/object.rb +82 -24
- data/lib/code/parser/addition.rb +12 -20
- data/lib/code/parser/and_operator.rb +9 -20
- data/lib/code/parser/bitwise_and.rb +9 -20
- data/lib/code/parser/bitwise_or.rb +12 -20
- data/lib/code/parser/boolean.rb +10 -7
- data/lib/code/parser/call.rb +92 -60
- data/lib/code/parser/chained_call.rb +47 -0
- data/lib/code/parser/class.rb +45 -0
- data/lib/code/parser/code.rb +17 -10
- data/lib/code/parser/dictionnary.rb +56 -30
- data/lib/code/parser/equal.rb +87 -35
- data/lib/code/parser/equality.rb +23 -24
- data/lib/code/parser/equality_lower.rb +9 -0
- data/lib/code/parser/function.rb +67 -42
- data/lib/code/parser/greater.rb +25 -0
- data/lib/code/parser/group.rb +13 -8
- data/lib/code/parser/if.rb +51 -21
- data/lib/code/parser/if_modifier.rb +43 -16
- data/lib/code/parser/list.rb +32 -19
- data/lib/code/parser/multiplication.rb +15 -20
- data/lib/code/parser/name.rb +96 -84
- data/lib/code/parser/negation.rb +20 -9
- data/lib/code/parser/not_keyword.rb +14 -12
- data/lib/code/parser/nothing.rb +13 -8
- data/lib/code/parser/number.rb +124 -68
- data/lib/code/parser/operation.rb +35 -0
- data/lib/code/parser/or_keyword.rb +12 -20
- data/lib/code/parser/or_operator.rb +9 -20
- data/lib/code/parser/power.rb +32 -14
- data/lib/code/parser/range.rb +9 -17
- data/lib/code/parser/rescue.rb +29 -13
- data/lib/code/parser/shift.rb +11 -21
- data/lib/code/parser/splat.rb +31 -0
- data/lib/code/parser/statement.rb +4 -3
- data/lib/code/parser/string.rb +53 -62
- data/lib/code/parser/ternary.rb +36 -15
- data/lib/code/parser/unary_minus.rb +23 -5
- data/lib/code/parser/while.rb +26 -15
- data/lib/code/parser/whitespace.rb +49 -0
- data/lib/code/parser.rb +15 -0
- data/lib/code/ruby.rb +13 -12
- data/lib/code-ruby.rb +2 -11
- data/lib/code.rb +16 -13
- data/lib/language/atom.rb +343 -0
- data/lib/language/output.rb +130 -0
- data/lib/language/parser/absent/present.rb +8 -0
- data/lib/language/parser/absent.rb +6 -0
- data/lib/language/parser/end_of_input.rb +6 -0
- data/lib/language/parser/interuption.rb +38 -0
- data/lib/language/parser/not_end_of_input.rb +6 -0
- data/lib/language/parser/str/not_found.rb +16 -0
- data/lib/language/parser/str.rb +6 -0
- data/lib/language/parser.rb +53 -0
- data/lib/language-ruby.rb +10 -0
- data/lib/language.rb +80 -0
- data/lib/template/node/code_part.rb +1 -1
- data/lib/template/node/part.rb +1 -1
- data/lib/template/node/template.rb +1 -1
- data/lib/template/node/text_part.rb +1 -1
- data/lib/template/node.rb +1 -1
- data/lib/template/parser/template.rb +26 -17
- data/lib/template/parser.rb +15 -0
- data/lib/template/version.rb +1 -1
- data/lib/template-ruby.rb +2 -11
- data/lib/template.rb +6 -11
- data/spec/code/addition_spec.rb +13 -0
- data/spec/code/and_operator_spec.rb +13 -0
- data/spec/code/bitwise_and_spec.rb +13 -0
- data/spec/code/bitwise_or_spec.rb +13 -0
- data/spec/code/boolean_spec.rb +13 -0
- data/spec/code/call_spec.rb +21 -0
- data/spec/code/chained_call_spec.rb +16 -0
- data/spec/code/dictionnary_spec.rb +17 -0
- data/spec/code/equal_spec.rb +26 -0
- data/spec/code/equality_spec.rb +13 -0
- data/spec/code/function_spec.rb +18 -0
- data/spec/code/greater_spec.rb +18 -0
- data/spec/code/group_spec.rb +12 -0
- data/spec/code/if_modifier_spec.rb +20 -0
- data/spec/code/if_spec.rb +25 -0
- data/spec/code/list_spec.rb +17 -0
- data/spec/code/multiplication_spec.rb +18 -0
- data/spec/code/negation_spec.rb +20 -0
- data/spec/code/not_keyword_spec.rb +13 -0
- data/spec/code/nothing_spec.rb +17 -0
- data/spec/code/number_spec.rb +22 -0
- data/spec/code/or_keyword_spec.rb +17 -0
- data/spec/code/or_operator_spec.rb +16 -0
- data/spec/code/parser/boolean_spec.rb +5 -7
- data/spec/code/parser/call_spec.rb +16 -56
- data/spec/code/parser/chained_call.rb +17 -0
- data/spec/code/parser/dictionnary_spec.rb +8 -9
- data/spec/code/parser/function_spec.rb +5 -21
- data/spec/code/parser/group_spec.rb +18 -0
- data/spec/code/parser/list_spec.rb +9 -20
- data/spec/code/parser/number_spec.rb +4 -109
- data/spec/code/parser/string_spec.rb +9 -17
- data/spec/code/parser_spec.rb +23 -0
- data/spec/code/power_spec.rb +13 -0
- data/spec/code/range_spec.rb +16 -0
- data/spec/code/rescue_spec.rb +13 -0
- data/spec/code/shift_spec.rb +13 -0
- data/spec/code/splat_spec.rb +13 -0
- data/spec/code/string_spec.rb +25 -0
- data/spec/code/ternary_spec.rb +18 -0
- data/spec/code/unary_minus_spec.rb +13 -0
- data/spec/code/while_spec.rb +18 -0
- data/spec/spec_helper.rb +4 -1
- data/template-ruby.gemspec +2 -4
- metadata +112 -72
- data/lib/code/node/base_10_decimal.rb +0 -32
- data/lib/code/node/base_10_integer.rb +0 -32
- data/lib/code/node/base_10_number.rb +0 -19
- data/lib/code/node/base_16_number.rb +0 -19
- data/lib/code/node/base_2_number.rb +0 -19
- data/lib/code/node/base_8_number.rb +0 -19
- data/lib/code/node/block.rb +0 -17
- data/lib/code/node/defined.rb +0 -19
- data/lib/code/node/dictionnary_key_value.rb +0 -23
- data/lib/code/node/function_argument.rb +0 -45
- data/lib/code/node/group.rb +0 -13
- data/lib/code/node/keyword_call_argument.rb +0 -30
- data/lib/code/node/keyword_function_argument.rb +0 -33
- data/lib/code/node/name.rb +0 -28
- data/lib/code/node/not_keyword.rb +0 -13
- data/lib/code/node/or_keyword.rb +0 -34
- data/lib/code/node/range.rb +0 -31
- data/lib/code/node/regular_call_argument.rb +0 -34
- data/lib/code/node/regular_function_argument.rb +0 -36
- data/lib/code/node/string_characters.rb +0 -13
- data/lib/code/node/string_component.rb +0 -23
- data/lib/code/node/string_interpolation.rb +0 -13
- data/lib/code/parser/defined.rb +0 -20
- data/lib/code/parser/greater_than.rb +0 -33
- data/spec/call_spec.rb +0 -22
- data/spec/code/error/type_error_spec.rb +0 -63
- data/spec/code/parser/name_spec.rb +0 -15
- data/spec/code/parser/nothing_spec.rb +0 -19
- data/spec/code_spec.rb +0 -182
- data/spec/function_spec.rb +0 -26
- data/spec/template/parser/template_spec.rb +0 -19
- data/spec/template_spec.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22324991b6fb7e6440917eef572f8983c60038e83812ee04315f92ea1da17bc8
|
4
|
+
data.tar.gz: 9b0a7f5d97a9a076b711e7bf8872722d46a2906f98e988f9b661a150a5dcec00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92248c14d47399ff98720083182d4933a064679a8d5a218256aa6097c307ffbfcaf7f7a5830624210306978aa7ccbe2301dc94f606b2ad05c65e618e966ca2f4
|
7
|
+
data.tar.gz: 36e9c2247fa179763e091499d2c4315e45bb302308e7460ac4b9fca3513bfad0ae7bfe4fbf95ea2071295b3d892874bc5b26248a2f19762c3a3d6e66a0f48812
|
data/.gitignore
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
*.gem
|
2
|
-
|
2
|
+
tmp/
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,74 +1,47 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/dorianmariefr/syntax_tree.git
|
3
|
+
revision: f7c9dc36a3d60c90a8d2411f123913b37319dc11
|
4
|
+
specs:
|
5
|
+
syntax_tree (5.0.1)
|
6
|
+
prettier_print (>= 1.1.0)
|
7
|
+
|
1
8
|
PATH
|
2
9
|
remote: .
|
3
10
|
specs:
|
4
|
-
code-ruby (0.
|
5
|
-
|
6
|
-
|
7
|
-
zeitwerk (~> 2
|
8
|
-
template-ruby (0.3.1)
|
9
|
-
activesupport (~> 7)
|
10
|
-
parslet (~> 2)
|
11
|
-
zeitwerk (~> 2.6)
|
11
|
+
code-ruby (0.4.0)
|
12
|
+
zeitwerk (~> 2)
|
13
|
+
template-ruby (0.4.0)
|
14
|
+
zeitwerk (~> 2)
|
12
15
|
|
13
16
|
GEM
|
14
17
|
remote: https://rubygems.org/
|
15
18
|
specs:
|
16
|
-
activesupport (7.0.4)
|
17
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
-
i18n (>= 1.6, < 2)
|
19
|
-
minitest (>= 5.1)
|
20
|
-
tzinfo (~> 2.0)
|
21
|
-
concurrent-ruby (1.1.10)
|
22
19
|
diff-lcs (1.5.0)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
syntax_tree (>= 2.7.1)
|
32
|
-
syntax_tree-haml (>= 1.1.0)
|
33
|
-
syntax_tree-rbs (>= 0.2.0)
|
34
|
-
prettier_print (0.1.0)
|
35
|
-
rbs (2.6.0)
|
36
|
-
rspec (3.11.0)
|
37
|
-
rspec-core (~> 3.11.0)
|
38
|
-
rspec-expectations (~> 3.11.0)
|
39
|
-
rspec-mocks (~> 3.11.0)
|
40
|
-
rspec-core (3.11.0)
|
41
|
-
rspec-support (~> 3.11.0)
|
42
|
-
rspec-expectations (3.11.1)
|
20
|
+
prettier_print (1.1.0)
|
21
|
+
rspec (3.12.0)
|
22
|
+
rspec-core (~> 3.12.0)
|
23
|
+
rspec-expectations (~> 3.12.0)
|
24
|
+
rspec-mocks (~> 3.12.0)
|
25
|
+
rspec-core (3.12.0)
|
26
|
+
rspec-support (~> 3.12.0)
|
27
|
+
rspec-expectations (3.12.0)
|
43
28
|
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
-
rspec-support (~> 3.
|
45
|
-
rspec-mocks (3.
|
29
|
+
rspec-support (~> 3.12.0)
|
30
|
+
rspec-mocks (3.12.0)
|
46
31
|
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
-
rspec-support (~> 3.
|
48
|
-
rspec-support (3.
|
49
|
-
|
50
|
-
|
51
|
-
syntax_tree-haml (1.3.1)
|
52
|
-
haml (>= 5.2)
|
53
|
-
prettier_print
|
54
|
-
syntax_tree (>= 2.0.1)
|
55
|
-
syntax_tree-rbs (0.5.0)
|
56
|
-
prettier_print
|
57
|
-
rbs
|
58
|
-
syntax_tree (>= 2.0.1)
|
59
|
-
temple (0.8.2)
|
60
|
-
tilt (2.0.11)
|
61
|
-
tzinfo (2.0.5)
|
62
|
-
concurrent-ruby (~> 1.0)
|
63
|
-
zeitwerk (2.6.1)
|
32
|
+
rspec-support (~> 3.12.0)
|
33
|
+
rspec-support (3.12.0)
|
34
|
+
ruby-prof (1.4.3)
|
35
|
+
zeitwerk (2.6.6)
|
64
36
|
|
65
37
|
PLATFORMS
|
66
38
|
arm64-darwin-21
|
67
39
|
|
68
40
|
DEPENDENCIES
|
69
41
|
code-ruby!
|
70
|
-
prettier
|
71
42
|
rspec
|
43
|
+
ruby-prof
|
44
|
+
syntax_tree!
|
72
45
|
template-ruby!
|
73
46
|
|
74
47
|
BUNDLED WITH
|
data/TODO
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
- Class
|
2
|
+
- Function parameters regular splat *args
|
3
|
+
- Function parameters keyword splat **kargs
|
4
|
+
- Function parameters block &block
|
5
|
+
- Block parameters regular splat *args
|
6
|
+
- Block parameters keyword splat **kargs
|
7
|
+
- Block parameters block &block
|
8
|
+
- Dictionnary regular splat { *args }
|
9
|
+
- Dictionnary keyword splat { **kargs }
|
10
|
+
- Dictionnary block { &block }
|
11
|
+
- Dictionnary expand name { user } and { user: }
|
12
|
+
- Rescue with exception name, rescue Code::Undefined
|
13
|
+
- Rescue with exception catched, rescue => e
|
14
|
+
- begin end
|
15
|
+
- begin rescue end
|
16
|
+
- begin rescue ensure end
|
17
|
+
- begin rescue else end
|
data/bin/code
CHANGED
@@ -3,49 +3,74 @@
|
|
3
3
|
require "optparse"
|
4
4
|
require_relative "../lib/template-ruby"
|
5
5
|
|
6
|
-
options = { timeout: 0 }
|
7
|
-
|
8
|
-
OptionParser
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
input = File.read(input)
|
6
|
+
options = { timeout: 0, profile: false }
|
7
|
+
|
8
|
+
OptionParser
|
9
|
+
.new do |opts|
|
10
|
+
opts.banner = "Usage: bin/code [options]"
|
11
|
+
|
12
|
+
opts.on(
|
13
|
+
"-i INPUT",
|
14
|
+
"--input=INPUT",
|
15
|
+
"Input in the code language (String or File)"
|
16
|
+
) do |input|
|
17
|
+
input = File.read(input) if File.exists?(input)
|
18
|
+
|
19
|
+
options[:input] = input
|
18
20
|
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
opts.on(
|
23
|
+
"-c CONTEXT",
|
24
|
+
"--context=CONTEXT",
|
25
|
+
"Context in the code language (String or File)"
|
26
|
+
) do |context|
|
27
|
+
context = File.read(context) if File.exists?(context)
|
22
28
|
|
23
|
-
|
24
|
-
"-c CONTEXT",
|
25
|
-
"--context=CONTEXT",
|
26
|
-
"Context in the code language (String or File)"
|
27
|
-
) do |context|
|
28
|
-
if File.exists?(context)
|
29
|
-
context = File.read(context)
|
29
|
+
options[:context] = context
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
opts.on("-p", "--parse", "Get parser results for input") do |parse|
|
33
|
+
options[:parse] = parse
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
opts.on(
|
37
|
+
"-t TIMEOUT",
|
38
|
+
"--timeout=TIMEOUT",
|
39
|
+
"Set timeout in seconds"
|
40
|
+
) { |timeout| options[:timeout] = timeout.to_f }
|
38
41
|
|
39
|
-
|
40
|
-
|
42
|
+
opts.on(
|
43
|
+
"--profile",
|
44
|
+
"Profile Ruby code"
|
45
|
+
) do |timeout|
|
46
|
+
require "ruby-prof"
|
47
|
+
options[:profile] = true
|
48
|
+
end
|
41
49
|
end
|
42
|
-
|
50
|
+
.parse!
|
43
51
|
|
44
52
|
input = options.fetch(:input, "")
|
45
53
|
context = options.fetch(:context, "")
|
46
54
|
|
55
|
+
if options[:profile]
|
56
|
+
RubyProf.start
|
57
|
+
end
|
58
|
+
|
47
59
|
if options[:parse]
|
48
|
-
pp ::Code::Parser
|
60
|
+
pp ::Code::Parser.parse(input).to_raw
|
49
61
|
else
|
50
|
-
print
|
62
|
+
print(
|
63
|
+
Code.evaluate(
|
64
|
+
input,
|
65
|
+
context,
|
66
|
+
io: $stdout,
|
67
|
+
timeout: options[:timeout]
|
68
|
+
).to_s
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
if options[:profile]
|
73
|
+
result = RubyProf.stop
|
74
|
+
printer = RubyProf::FlatPrinter.new(result)
|
75
|
+
printer.print($stdout)
|
51
76
|
end
|
data/bin/format
ADDED
data/bin/template
CHANGED
@@ -3,41 +3,83 @@
|
|
3
3
|
require "optparse"
|
4
4
|
require_relative "../lib/template-ruby"
|
5
5
|
|
6
|
-
options = { timeout: 0 }
|
6
|
+
options = { timeout: 0, profile: false, profiler: "text" }
|
7
7
|
|
8
|
-
OptionParser
|
9
|
-
|
8
|
+
OptionParser
|
9
|
+
.new do |opts|
|
10
|
+
opts.banner = "Usage: template [options]"
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
input
|
12
|
+
opts.on(
|
13
|
+
"-i INPUT",
|
14
|
+
"--input=INPUT",
|
15
|
+
"Input in the template language (String or File)"
|
16
|
+
) do |input|
|
17
|
+
input = File.read(input) if File.exists?(input)
|
18
|
+
|
19
|
+
options[:input] = input
|
14
20
|
end
|
15
21
|
|
16
|
-
|
17
|
-
|
22
|
+
opts.on(
|
23
|
+
"-c CONTEXT",
|
24
|
+
"--context=CONTEXT",
|
25
|
+
"Context in the code language (String or File)"
|
26
|
+
) do |context|
|
27
|
+
context = File.read(context) if File.exists?(context)
|
18
28
|
|
19
|
-
|
20
|
-
if File.exists?(context)
|
21
|
-
context = File.read(context)
|
29
|
+
options[:context] = context
|
22
30
|
end
|
23
31
|
|
24
|
-
|
25
|
-
|
32
|
+
opts.on("-p", "--parse", "Get parser results for input") do |parse|
|
33
|
+
options[:parse] = parse
|
34
|
+
end
|
26
35
|
|
27
|
-
|
28
|
-
|
29
|
-
|
36
|
+
opts.on(
|
37
|
+
"-t TIMEOUT",
|
38
|
+
"--timeout=TIMEOUT",
|
39
|
+
"Set timeout in seconds"
|
40
|
+
) { |timeout| options[:timeout] = timeout.to_f }
|
41
|
+
|
42
|
+
opts.on(
|
43
|
+
"--profile",
|
44
|
+
"Profile Ruby code"
|
45
|
+
) do |timeout|
|
46
|
+
require "ruby-prof"
|
47
|
+
options[:profile] = true
|
48
|
+
end
|
30
49
|
|
31
|
-
|
32
|
-
|
50
|
+
opts.on(
|
51
|
+
"--profiler TYPE",
|
52
|
+
"Profiler output type (text (default) or html)"
|
53
|
+
) do |profiler|
|
54
|
+
require "ruby-prof"
|
55
|
+
options[:profile] = true
|
56
|
+
options[:profiler] = profiler
|
57
|
+
end
|
33
58
|
end
|
34
|
-
|
59
|
+
.parse!
|
35
60
|
|
36
61
|
input = options.fetch(:input, "")
|
37
62
|
context = options.fetch(:context, "")
|
38
63
|
|
64
|
+
if options[:profile]
|
65
|
+
RubyProf.start
|
66
|
+
end
|
67
|
+
|
39
68
|
if options[:parse]
|
40
|
-
pp ::Template::Parser
|
69
|
+
pp ::Template::Parser.parse(input).to_raw
|
41
70
|
else
|
42
71
|
Template.render(input, context, io: $stdout, timeout: options[:timeout])
|
43
72
|
end
|
73
|
+
|
74
|
+
if options[:profile]
|
75
|
+
result = RubyProf.stop
|
76
|
+
if options[:profiler] == "text"
|
77
|
+
printer = RubyProf::FlatPrinter.new(result)
|
78
|
+
printer.print($stdout)
|
79
|
+
elsif options[:profiler] == "html"
|
80
|
+
printer = RubyProf::GraphHtmlPrinter.new(result)
|
81
|
+
printer.print($stdout)
|
82
|
+
else
|
83
|
+
abort "#{options[:profiler]} not recognized"
|
84
|
+
end
|
85
|
+
end
|
data/bin/test
ADDED
data/code-ruby.gemspec
CHANGED
@@ -13,7 +13,5 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.homepage = "https://github.com/dorianmariefr/template-ruby"
|
14
14
|
s.license = "MIT"
|
15
15
|
|
16
|
-
s.add_dependency "
|
17
|
-
s.add_dependency "parslet", "~> 2"
|
18
|
-
s.add_dependency "zeitwerk", "~> 2.6"
|
16
|
+
s.add_dependency "zeitwerk", "~> 2"
|
19
17
|
end
|
data/docs/class.code
ADDED
data/docs/euler/1.template
CHANGED
data/docs/euler/5.template
CHANGED
data/docs/meetup.code
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
url = fetch(:url) { "https://www.meetup.com/parisrb" }
|
2
|
+
response = HTTP.get(url)
|
3
|
+
times = response.css(".groupHome-eventsList-upcomingEvents time")
|
4
|
+
times = times.map(&:datetime).map { |time| Time.from_epoch(time.to_integer) }
|
5
|
+
|
6
|
+
times.each do |time|
|
7
|
+
if (1.day.from_now...(1.day.from_now + 1.hour)).include?(time)
|
8
|
+
Sms.send("Event in one day {url}")
|
9
|
+
elsif (2.hours.from_now...(1.hour.from_now)).include(time)
|
10
|
+
Sms.send("Event in two hours {url}")
|
11
|
+
end
|
12
|
+
end
|
data/docs/precedence.template
CHANGED
@@ -1,69 +1,36 @@
|
|
1
1
|
- Code
|
2
|
-
- {a = "Go" a += "od" a}
|
3
2
|
- Statement
|
4
|
-
- {a = "Good"}
|
5
3
|
- Equality
|
6
|
-
|
4
|
+
- Splat
|
5
|
+
- Class
|
7
6
|
- While
|
8
|
-
- {a = 0
|
9
|
-
while a < 10 a += 1 "Good" end}
|
10
7
|
- If
|
11
|
-
- {if true "Good" end}
|
12
8
|
- IfModifier
|
13
|
-
- {"Good" if true}
|
14
9
|
- OrKeyword
|
15
|
-
- {false or "Good"}
|
16
10
|
- NotKeyword
|
17
|
-
- {not false and "Good"}
|
18
11
|
- Equal
|
19
|
-
- {a = "Good"}
|
20
12
|
- Rescue
|
21
|
-
- {0 > "String" rescue "Good"}
|
22
13
|
- Ternary
|
23
|
-
- {nothing ? "Bad" : "Good"}
|
24
|
-
- Defined
|
25
|
-
- {a = 1 "Good" if defined?(a)}
|
26
14
|
- Range
|
27
|
-
- {("Good".."Bad").first}
|
28
15
|
- OrOperator
|
29
|
-
- {false || "Good"}
|
30
16
|
- AndOperator
|
31
|
-
|
32
|
-
-
|
33
|
-
- {2 > 1 ? "Good"}
|
17
|
+
- EqualityLower
|
18
|
+
- Greater
|
34
19
|
- BitwiseOr
|
35
|
-
- {2 | 1 == 3 ? "Good"}
|
36
20
|
- BitwiseAnd
|
37
|
-
- {2 & 1 == 0 ? "Good"}
|
38
21
|
- Shift
|
39
|
-
- {1 << 1 == 2 ? "Good"}
|
40
22
|
- Addition
|
41
|
-
- {1 + 1 == 2 ? "Good"}
|
42
23
|
- Multiplication
|
43
|
-
- {1 * 2 == 2 ? "Good"}
|
44
24
|
- UnaryMinus
|
45
|
-
- {-1 == 1 - 2 ? "Good"}
|
46
25
|
- Power
|
47
|
-
- {2 ** 2 == 4 ? "Good"}
|
48
26
|
- Negation
|
49
|
-
- {!false ? "Good"}
|
50
27
|
- Function
|
51
|
-
|
52
|
-
- Call
|
53
|
-
- {["Good"].first}
|
28
|
+
- ChainedCall
|
54
29
|
- Dictionnary
|
55
|
-
- {{a: "Good"}.a}
|
56
30
|
- List
|
57
|
-
- {["Good", "Bad"].first}
|
58
31
|
- String
|
59
|
-
- {"Good"}
|
60
32
|
- Number
|
61
|
-
- {1 == 1 ? "Good"}
|
62
33
|
- Boolean
|
63
|
-
- {true ? "Good"}
|
64
34
|
- Nothing
|
65
|
-
- {nothing ? "Bad" : "Good"}
|
66
35
|
- Group
|
67
|
-
|
68
|
-
- Name
|
69
|
-
- {a = "Good" a}
|
36
|
+
- Call
|
data/docs/rain.code
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
paris = { latitude: 48.8566, longitude: 2.4022 }
|
2
|
+
latitude = fetch(:latitude) { paris.latitude }
|
3
|
+
longitude = fetch(:longitude) { paris.longitude }
|
4
|
+
duration = fetch(:duration) { 1.hour }
|
5
|
+
hour = duration.from_now.hour
|
6
|
+
|
7
|
+
response =
|
8
|
+
HTTP.get(
|
9
|
+
"https://api.open-meteo.com/v1/forecast",
|
10
|
+
parameters: {
|
11
|
+
latitude: latitude,
|
12
|
+
longitude: longitude,
|
13
|
+
hourly: :precipitation
|
14
|
+
}
|
15
|
+
)
|
16
|
+
|
17
|
+
precipitation = response.hourly.precipitation[hour]
|
18
|
+
precipitation = (precipitation * 100).to_integer
|
19
|
+
|
20
|
+
if precipitation > 0
|
21
|
+
Sms.send("There will be {precipitation}% of precipitation in the next hour")
|
22
|
+
end
|
data/docs/slack.code
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Slack.send("Who is leading the syncs?", channel: "#team-template")
|
2
|
+
|
3
|
+
Twitter.send("What do you want to do this week?")
|
4
|
+
|
5
|
+
Discord.send("Who will be the game master this week?")
|
6
|
+
|
7
|
+
Email.send(
|
8
|
+
subject: "What did you do last week?",
|
9
|
+
from: "dorian@thoughtbot.com",
|
10
|
+
reply_to: "rob@thoughtbot.com"
|
11
|
+
)
|
12
|
+
|
13
|
+
Email.send(
|
14
|
+
subject: "What do you want to do this week?",
|
15
|
+
from: "dorian@thoughtbot.com",
|
16
|
+
reply_to: "rob@thoughtbot.com"
|
17
|
+
)
|
data/docs/stripe.code
ADDED
data/docs/twitter.code
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
twitter_username = fetch(:twitter_username) { "dorianmariefr" }
|
2
|
+
|
3
|
+
Twitter
|
4
|
+
.search("to:{twitter_username}", type: :recent)
|
5
|
+
.each do |tweet|
|
6
|
+
next if Storage.exists?(tweet.id)
|
7
|
+
Storage.create!(tweet.id)
|
8
|
+
Sms.send("New mention: {tweet.user.screen_name}: {tweet.text}")
|
9
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative "lib/template/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "language-ruby"
|
5
|
+
s.version = ::Template::Version
|
6
|
+
s.summary = "A Parsing Expression Grammar (PEG)"
|
7
|
+
s.description =
|
8
|
+
'A Parsing Expression Grammar (PEG) for making parsers'
|
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
|
+
|
17
|
+
s.add_dependency "zeitwerk", "~> 2"
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Code
|
2
|
+
class Node
|
3
|
+
class Base10 < Node
|
4
|
+
def initialize(parsed)
|
5
|
+
@whole = parsed.delete(:whole)
|
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
|
+
exponent = @exponent.evaluate(**args)
|
17
|
+
|
18
|
+
if exponent.is_a?(::Code::Object::Integer)
|
19
|
+
::Code::Object::Integer.new(@whole.to_i, exponent: exponent)
|
20
|
+
else
|
21
|
+
::Code::Object::Decimal.new(@whole, exponent: exponent)
|
22
|
+
end
|
23
|
+
else
|
24
|
+
::Code::Object::Integer.new(@whole.to_i)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|