kapusta 0.3.0 → 0.4.1
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.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/bin/check-all +19 -0
- data/bin/fennel-parity +157 -0
- data/examples/macros-dbg.kap +9 -0
- data/examples/macros-multi.kap +12 -0
- data/examples/macros-swap.kap +9 -0
- data/examples/macros-thrice-if.kap +18 -0
- data/examples/macros-unless.kap +7 -0
- data/examples/macros-when-let.kap +7 -0
- data/examples/packet-router.kap +2 -5
- data/examples/tic-tac-toe.kap +4 -9
- data/examples/ugly-number.kap +22 -0
- data/lib/kapusta/ast.rb +42 -0
- data/lib/kapusta/compiler/emitter/expressions.rb +34 -0
- data/lib/kapusta/compiler/emitter/patterns.rb +7 -11
- data/lib/kapusta/compiler/emitter/support.rb +2 -1
- data/lib/kapusta/compiler/macro_expander.rb +256 -0
- data/lib/kapusta/compiler.rb +8 -0
- data/lib/kapusta/formatter.rb +216 -87
- data/lib/kapusta/reader.rb +46 -10
- data/lib/kapusta/version.rb +1 -1
- data/lib/kapusta.rb +5 -5
- data/spec/examples_spec.rb +51 -0
- data/spec/formatter_spec.rb +8 -10
- metadata +11 -1
data/spec/examples_spec.rb
CHANGED
|
@@ -500,4 +500,55 @@ RSpec.describe 'examples' do
|
|
|
500
500
|
it 'subtract-product-sum.kap' do
|
|
501
501
|
expect(run_example('subtract-product-sum.kap')).to eq("15\n21\n0\n")
|
|
502
502
|
end
|
|
503
|
+
|
|
504
|
+
it 'ugly-number.kap' do
|
|
505
|
+
expect(run_example('ugly-number.kap')).to eq("true\ntrue\nfalse\nfalse\ntrue\n")
|
|
506
|
+
end
|
|
507
|
+
|
|
508
|
+
it 'macros-unless.kap' do
|
|
509
|
+
expect(run_example('macros-unless.kap')).to eq(<<~OUT)
|
|
510
|
+
"shown"
|
|
511
|
+
"also shown"
|
|
512
|
+
OUT
|
|
513
|
+
end
|
|
514
|
+
|
|
515
|
+
it 'macros-swap.kap' do
|
|
516
|
+
expect(run_example('macros-swap.kap')).to eq("2\n1\n")
|
|
517
|
+
end
|
|
518
|
+
|
|
519
|
+
it 'macros-when-let.kap' do
|
|
520
|
+
expect(run_example('macros-when-let.kap')).to eq(<<~OUT)
|
|
521
|
+
"got"
|
|
522
|
+
3
|
|
523
|
+
"done"
|
|
524
|
+
OUT
|
|
525
|
+
end
|
|
526
|
+
|
|
527
|
+
it 'macros-multi.kap' do
|
|
528
|
+
expect(run_example('macros-multi.kap')).to eq("10\n20\n7\n")
|
|
529
|
+
end
|
|
530
|
+
|
|
531
|
+
it 'macros-thrice-if.kap' do
|
|
532
|
+
expect(run_example('macros-thrice-if.kap')).to eq(<<~OUT)
|
|
533
|
+
"tick"
|
|
534
|
+
1
|
|
535
|
+
"tick"
|
|
536
|
+
2
|
|
537
|
+
"tick"
|
|
538
|
+
3
|
|
539
|
+
"final"
|
|
540
|
+
3
|
|
541
|
+
OUT
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
it 'macros-dbg.kap' do
|
|
545
|
+
expect(run_example('macros-dbg.kap')).to eq(<<~OUT)
|
|
546
|
+
"dbg"
|
|
547
|
+
6
|
|
548
|
+
"result"
|
|
549
|
+
6
|
|
550
|
+
"dbg"
|
|
551
|
+
50
|
|
552
|
+
OUT
|
|
553
|
+
end
|
|
503
554
|
end
|
data/spec/formatter_spec.rb
CHANGED
|
@@ -210,16 +210,14 @@ RSpec.describe Kapusta::Formatter do
|
|
|
210
210
|
end
|
|
211
211
|
|
|
212
212
|
expect(output).to eq(<<~KAP)
|
|
213
|
-
(let
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
role
|
|
222
|
-
"Engineer"]
|
|
213
|
+
(let [
|
|
214
|
+
profile
|
|
215
|
+
{:name "Ada"
|
|
216
|
+
; active user
|
|
217
|
+
:active true}
|
|
218
|
+
; next binding
|
|
219
|
+
role
|
|
220
|
+
"Engineer"]
|
|
223
221
|
(print profile role))
|
|
224
222
|
KAP
|
|
225
223
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kapusta
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Evgenii Morozov
|
|
@@ -20,8 +20,10 @@ files:
|
|
|
20
20
|
- Gemfile
|
|
21
21
|
- README.md
|
|
22
22
|
- Rakefile
|
|
23
|
+
- bin/check-all
|
|
23
24
|
- bin/compile-examples
|
|
24
25
|
- bin/console
|
|
26
|
+
- bin/fennel-parity
|
|
25
27
|
- bin/setup
|
|
26
28
|
- examples/accumulator.kap
|
|
27
29
|
- examples/ackermann.kap
|
|
@@ -56,6 +58,12 @@ files:
|
|
|
56
58
|
- examples/kwargs.kap
|
|
57
59
|
- examples/leap-year.kap
|
|
58
60
|
- examples/length-of-last-word.kap
|
|
61
|
+
- examples/macros-dbg.kap
|
|
62
|
+
- examples/macros-multi.kap
|
|
63
|
+
- examples/macros-swap.kap
|
|
64
|
+
- examples/macros-thrice-if.kap
|
|
65
|
+
- examples/macros-unless.kap
|
|
66
|
+
- examples/macros-when-let.kap
|
|
59
67
|
- examples/majority-element.kap
|
|
60
68
|
- examples/manhattan-distance.kap
|
|
61
69
|
- examples/match.kap
|
|
@@ -92,6 +100,7 @@ files:
|
|
|
92
100
|
- examples/tset.kap
|
|
93
101
|
- examples/two-sum-hash.kap
|
|
94
102
|
- examples/two-sum.kap
|
|
103
|
+
- examples/ugly-number.kap
|
|
95
104
|
- examples/underscore-patterns.kap
|
|
96
105
|
- examples/use_bank_account.rb
|
|
97
106
|
- examples/valid-parentheses-1.kap
|
|
@@ -113,6 +122,7 @@ files:
|
|
|
113
122
|
- lib/kapusta/compiler/emitter/interop.rb
|
|
114
123
|
- lib/kapusta/compiler/emitter/patterns.rb
|
|
115
124
|
- lib/kapusta/compiler/emitter/support.rb
|
|
125
|
+
- lib/kapusta/compiler/macro_expander.rb
|
|
116
126
|
- lib/kapusta/compiler/normalizer.rb
|
|
117
127
|
- lib/kapusta/env.rb
|
|
118
128
|
- lib/kapusta/error.rb
|