Re: [racket-users] How to recover whitespace from syntax->string

2021-04-10 Thread jackh...@gmail.com
I had to build something for this in my Resyntax project. My takeaways were: - There's no substitute for just reading the file. If you have a `syntax-original?` subform, you can use the srcloc information to read t

Re: [racket-users] How to recover whitespace from syntax->string

2021-04-09 Thread Jeff Henrikson
It turns out that I have more trouble with printing whitespace from syntax.  Consider this: (require racket) (require syntax/to-string) (define (syntax-on-lines-v1 xs)   (define (iter fin ys)     (let ((y (read-syntax "" fin)))   (if (eof-object? y)   (rever

Re: [racket-users] How to recover whitespace from syntax->string

2021-04-09 Thread Jeff Henrikson
Laurent, Thank you very much.  It probably would have taken me a long time on my own to think of the possibility that the port was at fault. Jeff On 4/9/21 4:29 AM, Laurent wrote: You need to enable line/character counting with `port-count-lines!`: #lang racket (require syntax/to-string)

Re: [racket-users] How to recover whitespace from syntax->string

2021-04-09 Thread Laurent
You need to enable line/character counting with `port-count-lines!`: #lang racket (require syntax/to-string) (define in (open-input-string "(comment\n \"hello world\"\n line)")) (port-count-lines! in) (syntax->string (read-syntax "mystring" in)) ; -> "comment\n \"hello world\"\n line" On Fri,