-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.txt
executable file
·66 lines (43 loc) · 1.93 KB
/
doc.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
_syntax-reprinter.ss_: print syntax objects, preserving lines and columns
Quick Example
-------------
Let's say that we had a syntax with complete location information, and would like
to reprint it, preserving columns and lines. That's the job of _syntax-reprinter_.
> (require (planet "syntax-reprinter.ss ("dyoo" "syntax-reprinter.plt")))
> (define outp (open-output-string))
>
> (syntax-reprint
(syntax (define (factorial x)
(if (= x 0)
1
(* x (factorial (sub1 x))))))
outp)
>
> (get-output-string outp)
" (define (factorial x)\n (if (= x 0)\n 1\n (* x (factorial (sub1 x)))))"
>
> (printf "~a~n" (get-output-string outp))
(define (factorial x)
(if (= x 0)
1
(* x (factorial (sub1 x)))))
>
That's pretty much it. Only one function is provided here, _syntax-reprint_.
Functions
---------
> syntax-reprint: syntax [output-port] -> void
Prints out the syntax to the output-port, adding newlines and spaces according to the
syntax-line and syntax-column properties of the syntax.
If the output-port isn't given, uses (current-output-port) by default.
Known Bugs
----------
Handling syntaxes where there are newlines right before a closing paren isn't handled;
I don't think enough information is preserved in syntax objects to reconstruct the
textual representation. (If I'm wrong, please correct me so I can fix it! *grin*)
Thanks
------
Thanks to Kyle Smith for getting me interested in the problem. See:
http://list.cs.brown.edu/pipermail/plt-scheme/2007-January/016054.html
for the thread that starts things up. Also, thanks to Guillaume Marceau for
getting me involved with DivaScheme. Writing code without it would
be otherwise very painful. Thanks to the rest of the PLT team!