lips
lips copied to clipboard
formatter breaks code that has comments
const code = `
(define i 0) ;;
(define i (let ((i 2)) (+ i 3)))
`;
async function main() {
/* this is head of devel branch when I wrote this */
const lips = await import("https://cdn.jsdelivr.net/gh/jcubic/lips@74055b5a1172ff48e3fe075e319142b840c492c1/dist/lips.esm.min.js");
console.log(code);
console.log(new lips.Formatter(code).break().format());
}
main();
it prints that the formatted code is
(define i 0)
;; (define i (let ((i 2))
(+ i 3)))
which is syntax error.
if the initial code is this:
(define i 0) ;;
(define i 1)
the formatted output is:
(define i 0)
which is syntactically correct but not complete.
So comments are not handled in any way with the formatter, the formatter was used with code returned by the parser, and the parser strips any comments.
I need to check how it works in the REPL that pretty printed when you copy and paste.
It should be fixed but note that formatter has a lot of issues. The main that may be important to your use, is that it don't add breaks after S-Expression.
This is the issue track formatter:
- https://github.com/jcubic/lips/issues/189
I wanted to fix this quickly, but it requires a bit more work.
Note that formatter is rule based and the rules are located in lips.Formatter.rules, but it's not documented.