kapusta 0.11.1 → 0.11.2
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 +8 -10
- data/lib/kapusta/cli.rb +2 -2
- data/lib/kapusta/compiler/emitter/bindings.rb +1 -1
- data/lib/kapusta/compiler/emitter/control_flow.rb +1 -1
- data/lib/kapusta/compiler/emitter/support.rb +2 -2
- data/lib/kapusta/compiler.rb +1 -1
- data/lib/kapusta/errors.rb +1 -1
- data/lib/kapusta/version.rb +1 -1
- data/spec/cli_spec.rb +4 -4
- data/spec/examples_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0ba2ee0fbbd336f3604e9c51014a458c0a54eefcb30939fc6f2a72ba25941fb6
|
|
4
|
+
data.tar.gz: 687f46ff98b74d65d523404ba9350fd62921eada8e105f4fe0d9215eac036118
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 070c9c5f4435f2e825f0bdb70ceb25f3cc5eba62745cae80f9d348aa4fc886d74a5f8ed06a93a62d572adbfadfbce5e93b3e37993a5d637e68d615af6e1ecfa7
|
|
7
|
+
data.tar.gz: fc1697cfb31821c867c468666eee7bb3cd6af985c446cba8ea35e3c50c5928750a0989ce31c250d2c1d47f79b4f338e319a17cb00abb314c7213a1e3f2eb89e1
|
data/README.md
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Kapusta is a Lisp for the Ruby runtime.
|
|
4
4
|
|
|
5
|
-
It is inspired by [Fennel](https://fennel-lang.org).
|
|
5
|
+
It is inspired by [Fennel](https://fennel-lang.org). Kapusta aims to bring the simplicity and joy of Lisp to Ruby. Where Fennel uses Lua's stdlib and runtime, Kapusta uses Ruby's.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
For more information about Kapusta, see the official Fennel documentation and tutorials.
|
|
7
|
+
For more information about Kapusta, see the official Fennel documentation and tutorials, but replace Lua with Ruby.
|
|
10
8
|
|
|
11
9
|
## Features
|
|
12
10
|
|
|
@@ -41,14 +39,14 @@ exe/kapusta examples/fizzbuzz.kap
|
|
|
41
39
|
or
|
|
42
40
|
|
|
43
41
|
```
|
|
44
|
-
|
|
42
|
+
kapusta --compile examples/fizzbuzz.kap > examples/fizzbuzz.rb
|
|
45
43
|
ruby examples/fizzbuzz.rb
|
|
46
44
|
```
|
|
47
45
|
|
|
48
|
-
For mruby
|
|
46
|
+
For mruby 3 compatible output, such as DragonRuby, use:
|
|
49
47
|
|
|
50
48
|
```
|
|
51
|
-
|
|
49
|
+
kapusta --compile --target=mruby3 examples/match.kap > examples/match-mruby3.rb
|
|
52
50
|
```
|
|
53
51
|
|
|
54
52
|
## Use from Ruby
|
|
@@ -115,8 +113,8 @@ Kapusta-specific additions:
|
|
|
115
113
|
- `ivar` or `@var` / `cvar` or `@@var` / `gvar` or `$var`
|
|
116
114
|
- `try` / `catch` / `finally` plus `raise` for exceptions
|
|
117
115
|
- `(ruby "...")` raw host escape hatch
|
|
118
|
-
- a
|
|
119
|
-
- a
|
|
116
|
+
- pass Ruby keyword arguments by ending a call with a symbol-keyed hash: `(File.open path "r" {:encoding "UTF-8"})`
|
|
117
|
+
- pass a Ruby block by ending a call with a `(fn ...)` or `#(...)` literal: `(File.open path "r" (fn [io] (: io :read)))`
|
|
120
118
|
|
|
121
119
|
## Format
|
|
122
120
|
|
|
@@ -130,7 +128,7 @@ Use `kapusta-ls` in the editor of your choice.
|
|
|
130
128
|
|
|
131
129
|
## Syntax highlight
|
|
132
130
|
|
|
133
|
-
For Vim, you can use https://
|
|
131
|
+
For Vim, you can use [`vim-syntax/`](https://github.com/evmorov/kapusta/tree/main/vim-syntax/).
|
|
134
132
|
|
|
135
133
|
## License
|
|
136
134
|
|
data/lib/kapusta/cli.rb
CHANGED
|
@@ -39,7 +39,7 @@ module Kapusta
|
|
|
39
39
|
OptionParser.new do |parser|
|
|
40
40
|
parser.banner = usage
|
|
41
41
|
parser.on('-c', '--compile', 'Compile .kap to Ruby') { options.compile = true }
|
|
42
|
-
parser.on('--target=TARGET', 'Compile for
|
|
42
|
+
parser.on('--target=TARGET', 'Compile for mruby3') do |target|
|
|
43
43
|
options.target = Kapusta::Compiler.normalize_target(target)
|
|
44
44
|
end
|
|
45
45
|
parser.on('-h', '--help', 'Show this help') { options.help = true }
|
|
@@ -69,7 +69,7 @@ module Kapusta
|
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
def self.usage
|
|
72
|
-
'usage: kapusta [--compile|-c] [--target=
|
|
72
|
+
'usage: kapusta [--compile|-c] [--target=mruby3] <file.kap> | kapusta <file.kap> [args...]'
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
75
|
end
|
|
@@ -178,7 +178,7 @@ module Kapusta
|
|
|
178
178
|
|
|
179
179
|
def emit_toplevel_method_bridge(ruby_name)
|
|
180
180
|
method_name = ruby_name.to_sym.inspect
|
|
181
|
-
if
|
|
181
|
+
if mruby3_target?
|
|
182
182
|
return [
|
|
183
183
|
"define_singleton_method(#{method_name}) do |*args|",
|
|
184
184
|
indent("Object.instance_method(#{method_name}).bind(self).call(*args)"),
|
|
@@ -96,7 +96,7 @@ module Kapusta
|
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
def emit_case_body(value_var, clauses, env, current_scope, mode)
|
|
99
|
-
return try_emit_compat_case(value_var, clauses, env, current_scope, mode) if
|
|
99
|
+
return try_emit_compat_case(value_var, clauses, env, current_scope, mode) if mruby3_target?
|
|
100
100
|
|
|
101
101
|
try_emit_native_case(value_var, clauses, env, current_scope, mode) ||
|
|
102
102
|
try_emit_compat_case(value_var, clauses, env, current_scope, mode)
|
data/lib/kapusta/compiler.rb
CHANGED
|
@@ -61,7 +61,7 @@ module Kapusta
|
|
|
61
61
|
def self.normalize_target(target)
|
|
62
62
|
case target
|
|
63
63
|
when nil then nil
|
|
64
|
-
when :mruby, 'mruby' then :
|
|
64
|
+
when :mruby3, 'mruby3', :mruby, 'mruby' then :mruby3
|
|
65
65
|
else
|
|
66
66
|
raise Error, Kapusta::Errors.format(:unknown_target, target: target.inspect)
|
|
67
67
|
end
|
data/lib/kapusta/errors.rb
CHANGED
|
@@ -64,7 +64,7 @@ module Kapusta
|
|
|
64
64
|
unexpected_eof: 'unexpected eof',
|
|
65
65
|
unexpected_vararg: 'unexpected vararg',
|
|
66
66
|
unknown_special_form: 'unknown special form: %{name}',
|
|
67
|
-
unknown_target: 'unknown target %{target}; only
|
|
67
|
+
unknown_target: 'unknown target %{target}; only mruby3 is supported',
|
|
68
68
|
unquote_outside_quasiquote: 'unquote outside quasiquote',
|
|
69
69
|
unquote_splice_outside_list: 'unquote-splice must appear inside a quoted list/vec',
|
|
70
70
|
unterminated_string: 'unterminated string',
|
data/lib/kapusta/version.rb
CHANGED
data/spec/cli_spec.rb
CHANGED
|
@@ -66,11 +66,11 @@ RSpec.describe Kapusta::CLI do
|
|
|
66
66
|
end
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
it 'compiles case and match forms for
|
|
69
|
+
it 'compiles case and match forms for mruby3 with --target=mruby3' do
|
|
70
70
|
path = File.expand_path('../examples/match.kap', __dir__)
|
|
71
71
|
|
|
72
72
|
ruby = capture_stdout do
|
|
73
|
-
described_class.start(['--compile', '--target=
|
|
73
|
+
described_class.start(['--compile', '--target=mruby3', path])
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
expect(ruby).not_to match(/^\s*in\b/)
|
|
@@ -98,14 +98,14 @@ RSpec.describe Kapusta::CLI do
|
|
|
98
98
|
.to raise_error(SystemExit)
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
-
expect(error_output).to include('unknown target "mri"; only
|
|
101
|
+
expect(error_output).to include('unknown target "mri"; only mruby3 is supported')
|
|
102
102
|
end
|
|
103
103
|
|
|
104
104
|
it 'rejects target without compile mode' do
|
|
105
105
|
path = File.expand_path('../examples/fizzbuzz.kap', __dir__)
|
|
106
106
|
|
|
107
107
|
error_output = capture_stderr do
|
|
108
|
-
expect { described_class.start(['--target=
|
|
108
|
+
expect { described_class.start(['--target=mruby3', path]) }
|
|
109
109
|
.to raise_error(SystemExit)
|
|
110
110
|
end
|
|
111
111
|
|
data/spec/examples_spec.rb
CHANGED
|
@@ -446,7 +446,7 @@ RSpec.describe 'examples' do
|
|
|
446
446
|
|
|
447
447
|
it 'underscore-patterns.kap on mruby keeps loose nil and strict fallback separate' do
|
|
448
448
|
path = File.join(EXAMPLES_DIR, 'underscore-patterns.kap')
|
|
449
|
-
ruby = compile_example('underscore-patterns.kap', target: :
|
|
449
|
+
ruby = compile_example('underscore-patterns.kap', target: :mruby3)
|
|
450
450
|
|
|
451
451
|
expect(run_mruby_source(ruby, path:)).to eq(<<~OUT)
|
|
452
452
|
5
|
|
@@ -699,7 +699,7 @@ RSpec.describe 'mruby runtime examples' do
|
|
|
699
699
|
if mruby_status.success? && mruby_stdout == expected
|
|
700
700
|
expect(run_mruby_source(ruby, path:)).to eq(expected)
|
|
701
701
|
else
|
|
702
|
-
mruby_ruby = compile_example(name, target: :
|
|
702
|
+
mruby_ruby = compile_example(name, target: :mruby3)
|
|
703
703
|
|
|
704
704
|
if mruby_ruby == ruby
|
|
705
705
|
expect(mruby_status).to be_success
|