Skip to content

Commit

Permalink
fix parsing comments without newline at the end #280
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Mar 25, 2024
1 parent f17facc commit 01def3e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 27 deletions.
6 changes: 3 additions & 3 deletions bin/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ function debug(message) {
console.log(message);
}
// -----------------------------------------------------------------------------
async function run(code, interpreter, use_dynamic = false, env = null, stack = false) {
async function run(code, interpreter, use_dynamic = false, env = null, stack = false, log_unterminated = true) {
try {
return await interpreter.exec(code, { use_dynamic, env });
} catch(e) {
if (e instanceof Parser.Unterminated) {
if (e instanceof Parser.Unterminated && !log_unterminated) {
return;
}
print_error(e, stack);
Expand Down Expand Up @@ -531,7 +531,7 @@ function run_repl(err, rl) {
rl.setPrompt('');
rl.pause();
prev_eval = prev_eval.then(function() {
const result = run(code, interp, dynamic, null, options.t || options.trace);
const result = run(code, interp, dynamic, null, options.t || options.trace, false);
cmd = '';
return result;
}).then(function(result) {
Expand Down
15 changes: 9 additions & 6 deletions dist/lips.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions dist/lips.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/lips.esm.min.js

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions dist/lips.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/lips.min.js

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -1232,9 +1232,12 @@ class Lexer {
var line = this.__input__.split('\n')[this._line];
throw new Error(`Invalid Syntax at line ${this._line + 1}\n${line}`);
}
if (this._state !== null) {
// we need to ignore comments becase they can be the last expression in code

Check failure on line 1235 in src/lips.js

View workflow job for this annotation

GitHub Actions / Check for spelling errors

becase ==> because
// without extra newline at the end
if (![null, Lexer.comment].includes(this._state)) {
const line_number = this.__input__.substring(0, this._newline).match(/\n/g)?.length ?? 0;
throw new Unterminated(`Invalid Syntax at line ${line_number + 1}: Unterminated expression`);
const line = this.__input__.substring(this._newline);
throw new Unterminated(`Invalid Syntax at line ${line_number + 1}: Unterminated expression ${line}`);
}
}
}
Expand Down

0 comments on commit 01def3e

Please sign in to comment.