0
lorentz
3y

What's the minimal feature set that can make a language as ornamented as JS into a comfortable REPL?
Should I write a full parser or should I try to patch my way around with regex?
It will have to interface a lot with JS so it has to be able to manage JS datastructures in some fashion, which means that I can't just make a whole new command line with its own programs.

My current plan:
Some delimiter (probably a semicolon) will take the output of a command and inject it in the next in case you decide halfway through a line to do some more processing, It also awaits promises and does some other nice stuff to make controlling such pipelines easy. I have an elaborate system in mind to decide where a value must be injected to make the line valid so in most cases you don't even have to indicate it. JS has beautifully simple syntax rules so I have a lot of technical balance to burn before I start building technical debt.

I have some ideas for automatic parentheses and commas in function calls. I realize while using a command line you do not want to tap shift often. My main idea here is that two names or values in js are always joined by an operator so the first missing operator is a call and following missing operators are commas until the end of line. This has lots of nasty edge cases though, like that no argument expression can begin with a unary operator or a bracket of any shape. You can always prepend a comma but it's cognitive load.

Anyway, do you have any suggestion or warning besides "js bad" which I know but it's the most popular sandboxable language and has a massive existing set of libraries which I kinda need.

Comments
  • 0
    You could use ye olde JS REPL and wrap the functions of your application (whatever it is) via Node or V8's FFI?

    Or use a JS engine with built in sandboxing, like Duktape (I think...)
  • 0
    @RememberMe I decided to go all in and write plugins for Acorn. This way I have unparalelled flexibility in modifying legal javascript so I can do fun stuff like infectious promises in operators, but it becomes very tricky to realise some other plans like interpreting expressions with a missing operand as functions.
  • 0
    I really need to clean my scope, a language that allows you to omit both operators and names is not going to work.
Add Comment