Skip to content

Commit

Permalink
fix parsing quotation without data #280
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Mar 25, 2024
1 parent f05e4eb commit f17facc
Show file tree
Hide file tree
Showing 8 changed files with 325 additions and 291 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
* fix Petrofsky let [#341](https://github.com/jcubic/lips/issues/341)
* fix `repr` of cycles
* fix parsing regex that have escaped open bracket
* fix parsing quotation without data

## 1.0.0-beta.18
### Breaking
Expand Down
65 changes: 36 additions & 29 deletions bin/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
exec,
compile,
parse,
Parser,
Formatter,
serialize,
unserialize,
Expand Down Expand Up @@ -76,7 +77,10 @@ function debug(message) {
async function run(code, interpreter, use_dynamic = false, env = null, stack = false) {
try {
return await interpreter.exec(code, { use_dynamic, env });
} catch (e) {
} catch(e) {
if (e instanceof Parser.Unterminated) {
return;
}
print_error(e, stack);
}
}
Expand Down Expand Up @@ -457,6 +461,36 @@ function run_repl(err, rl) {
}
let prev_line;
const is_emacs = process.env.INSIDE_EMACS;
function continue_multiline() {
multiline = true;
if (cmd.match(/\x1b\[200~/) || !supports_paste_brackets) {
rl.prompt();
if (is_emacs) {
rl.setPrompt('');
} else {
rl.setPrompt(continuePrompt);
}
if (terminal) {
rl.write(' '.repeat(prompt.length - continuePrompt.length));
}
} else {
let ind;
try {
ind = indent(code, 2, prompt.length - continuePrompt.length);
} catch (e) {
ind = 0;
}
const spaces = new Array(ind + 1).join(' ');
if (is_emacs) {
rl.setPrompt('');
rl.prompt();
} else {
rl.setPrompt(continuePrompt);
rl.prompt();
rl.write(spaces);
}
}
}
bootstrap(interp).then(function() {
if (supports_paste_brackets) {
process.stdin.on('keypress', (c, k) => {
Expand Down Expand Up @@ -525,34 +559,7 @@ function run_repl(err, rl) {
rl.resume();
});
} else {
multiline = true;
if (cmd.match(/\x1b\[200~/) || !supports_paste_brackets) {
rl.prompt();
if (is_emacs) {
rl.setPrompt('');
} else {
rl.setPrompt(continuePrompt);
}
if (terminal) {
rl.write(' '.repeat(prompt.length - continuePrompt.length));
}
} else {
let ind;
try {
ind = indent(code, 2, prompt.length - continuePrompt.length);
} catch (e) {
ind = 0;
}
const spaces = new Array(ind + 1).join(' ');
if (is_emacs) {
rl.setPrompt('');
rl.prompt();
} else {
rl.setPrompt(continuePrompt);
rl.prompt();
rl.write(spaces);
}
}
continue_multiline();
}
} catch (e) {
console.error(e.message);
Expand Down
Loading

0 comments on commit f17facc

Please sign in to comment.