eraserhd / parinfer-rust

A Rust port of parinfer.
ISC License
546 stars 42 forks source link

Unexpected handling of tabs #118

Open bentxt opened 2 years ago

bentxt commented 2 years ago

Hi I like using parinfer but in this case something goes wrong. Since I cannot figure out what the problem is, I had to disable parinfer completely, because otherwise it messes up existing code like:

(define (read-file name)
  (call-with-input-file name
    (lambda (port)
      (letrec ((recur (lambda ()
            (let ((expr (read port)))
              (if (eof-object? expr)
                  '()
                  (cons expr (recur)))))))
    (recur)))))

which parinfer transforms to:


(define (read-file name)
  (call-with-input-file name
    (lambda (port)
      (letrec ((recur (lambda ()))))
                (let ((expr (read port)))
                  (if (eof-object? expr)
                      '()
                      (cons expr (recur))))))
    (recur))
bentxt commented 2 years ago

I think by reformating the source code I prevent the unwanted transformation:

(define (read-file name)
   (call-with-input-file name
      (lambda (port)
         (letrec 
            ((recur 
               (lambda () 
                  (let ((expr (read port)))
                     (if (eof-object? expr)
                        '()
                        (cons expr (recur)))))))
           (recur)))))

I somehow possible I would prefer the source code in its original form

eraserhd commented 2 years ago

Hi! It looks like there are tabs in the original, and neither the original parinfer implementation, nor this one, supports them well (they both replace the tabs with exactly two spaces regardless of where the tab is aligned). If I replace the tabs with spaces, I get the result you want.

I think that fixing this would require specifying tab widths, and adding real tab logic based on input column.

Related: #86