Skip to content

Commit

Permalink
add syntax highlighting to pprint in Node REPL #33
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Feb 18, 2021
1 parent fc1929a commit 03efe94
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions bin/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,35 +169,51 @@ var interp = Interpreter('repl', {
});
});
}),
__dirname: __dirname,
__filename: __filename,
// -------------------------------------------------------------------------
stdout: OutputPort(function(x) {
if (typeof x !== 'string') {
x = this.get('repr')(x);
}
newline = !x.match(/\n$/);
process.stdout.write(x);
}),
// -------------------------------------------------------------------------
__dirname: __dirname,
__filename: __filename,
// -------------------------------------------------------------------------
'stack-trace': doc(function() {
if (strace) {
console.log(strace);
}
}, `(stack-trace)
Function display stack trace of last error`),
// -------------------------------------------------------------------------
exit: doc(function(code) {
process.exit(code);
}, `(exit)
(exit error-code)
Function exits LIPS script or the REPL.`),
// -------------------------------------------------------------------------
pprint: doc(function(arg) {
if (arg instanceof Pair) {
arg = new Formatter(arg.toString(true)).break().format();
this.get('display').call(this, scheme(arg));
} else {
this.get('write').call(this, scheme(arg));
}
this.get('newline').call(this);
}, env.get('pprint').__doc__),
// -------------------------------------------------------------------------
help: doc(new Macro('help', function(code, { error }) {
var new_code = new Pair(new LSymbol('__help'), code);
var doc = evaluate(new_code, { env: this, error });
if (doc) {
console.log(doc.toString());
}
}), env.get('help').__doc__),
// -------------------------------------------------------------------------
'__help': env.get('help')
});

Expand Down

0 comments on commit 03efe94

Please sign in to comment.