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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85bcd0988a353fb851e5ff955c2b5196f39193e1c3c8fb6ca4a111d6260e774d
4
- data.tar.gz: 80efbc138038947b866eaac96ef21d5cdccd04a461a25f2e17cbd7ce925ceaec
3
+ metadata.gz: 0ba2ee0fbbd336f3604e9c51014a458c0a54eefcb30939fc6f2a72ba25941fb6
4
+ data.tar.gz: 687f46ff98b74d65d523404ba9350fd62921eada8e105f4fe0d9215eac036118
5
5
  SHA512:
6
- metadata.gz: 16d02e652b9221990ac027423e677a8f27c285d582c6bfb368f585140305e1c48dff5add4a8491a7996b5be99e34efd761e7fb280d8932fc6548622939b166b4
7
- data.tar.gz: 8ab10f9991b7029d9366e47d434a9e9166568b870369f1fe585007fbe2cf9b750c84e8eb3b8fb015db255977eef80fd3255750fa99006d577a9564b640d84319
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). It is not intended to be production-ready like Clojure: that would be a lot of work, and Ruby is already a rich, elegant language.
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
- Instead, Kapusta aims to bring some of the simplicity and joy of Lisp to Ruby. Where Fennel uses Lua's stdlib and runtime, Kapusta uses Ruby's. You can use it for small apps, LeetCode, DragonRuby, or maybe even Rails.
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
- exe/kapusta --compile examples/fizzbuzz.kap > examples/fizzbuzz.rb
42
+ kapusta --compile examples/fizzbuzz.kap > examples/fizzbuzz.rb
45
43
  ruby examples/fizzbuzz.rb
46
44
  ```
47
45
 
48
- For mruby-compatible output, such as DragonRuby, use:
46
+ For mruby 3 compatible output, such as DragonRuby, use:
49
47
 
50
48
  ```
51
- exe/kapusta --compile --target=mruby examples/match.kap > examples/match-mruby.rb
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 trailing symbol-keyed hash is emitted as Ruby keyword arguments
119
- - a final function literal argument is emitted as a Ruby block
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://git.sr.ht/~m15a/vim-fennel-syntax
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 mruby') do |target|
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=mruby] <file.kap> | kapusta <file.kap> [args...]'
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 mruby_target?
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 mruby_target?
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)
@@ -25,8 +25,8 @@ module Kapusta
25
25
  (@form_stack ||= []).last
26
26
  end
27
27
 
28
- def mruby_target?
29
- @target == :mruby
28
+ def mruby3_target?
29
+ @target == :mruby3
30
30
  end
31
31
 
32
32
  def positionable?(form)
@@ -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 :mruby
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
@@ -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 mruby is supported',
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',
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kapusta
4
- VERSION = '0.11.1'
4
+ VERSION = '0.11.2'
5
5
  end
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 mruby with --target=mruby' do
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=mruby', path])
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 mruby is supported')
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=mruby', path]) }
108
+ expect { described_class.start(['--target=mruby3', path]) }
109
109
  .to raise_error(SystemExit)
110
110
  end
111
111
 
@@ -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: :mruby)
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: :mruby)
702
+ mruby_ruby = compile_example(name, target: :mruby3)
703
703
 
704
704
  if mruby_ruby == ruby
705
705
  expect(mruby_status).to be_success
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.11.1
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgenii Morozov