repl 0.1.0+1 repl: ^0.1.0+1 copied to clipboard
A REPL for Dart.
A REPL for Dart. #
Prior art #
Based on early version of a proof of concept REPL environment for Dart from a pair of articles by Andreas Kirsch and an example in the Dart SDK tests and the recharge package
Features #
- ✅ MVP with expression evaluation
- ✅ Use code from BlackHC's work to parse input for statements vs expressions
- ✅ Use
cli_repl
for better repl ergonomics - ✅ Use standard
pub activate
for package to run its binary instead of shell script - ✅ Improve usage documentation
- ✅ Use hotreload with a scratchpad file
- ❌ ?? Support built in package imports
- ❌ ?? Support arbitrary package imports
- ❌ ?? Use scratchpad with dedicated Isolate
?? - not clear if this is a workable approach
Usage #
To install the repl use:
dart pub global activate repl
Then as long as the pub system cache is on your path you can run it using: drepl
Supported features #
You can currently use expressions and statements as well as a few built-in's are supported (see below), its already possible to do a few useful things with the REPL.
For instance you can do JS style IIFE's:
> (){final data = ['this', 'is', 'a', 'test']; for(int i = 0; i < data.length; i++) print(data[i]); }()
But of course that is a bit contrived an example as you could also do:
> ['this', 'is', 'a', 'test'].forEach((x) => print(x))
Some statements are also possible, eg.
> int sqr(int a) => a*a;
> sqr(5)
> 25
Built-in's
print()
- print to output
reload()
- trigger a hot-reload (doesn't work well at the moment)
Editing, History, Shortcuts
see the cli_repl package documentation for supported short-cut keys.
Development #
Clone this repo, then from the top level of this repo and then run using:
dart bin/main.dart
Future plans #
A more powerful though much more involved implmentation route would be to use the Dart embedding API, perhaps via FFI to avoid needing to deal with too much c/c++ dev, assuming its possible for DartVM to call into itself via FFI using the embedding api?
Contributing #
All contributions: PRs, bug reports, feature requests, documentation are most welcome.
Contribution guidelines: TODO.