Re: [racket-users] syntax write using @-syntax
I was hoping you'd chime in, Eli. > > (match stx-or-sepxr > > [(? syntax? stx) (print/at-exp (syntax->datum stx))] > That's a major mistake! Well, syntax->datum usually is. :) But the usual reason why it's a mistake, seemed N/A here, to produce a plain text .scrbl file. Thanks for pointing out the reader syntax properties! The mistake that mortifies me more is that I spelled it "sepxr". O_o -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] syntax write using @-syntax
> I think you're right. My application is the replacement tool for McFly, and > I want to eliminate the need for distributed packages to need a package > dependency like on `mcfly-runtime`. Maybe you don't need to eliminate that? It would only be a build dependency: A using package's info.rkt would list your package in `build-deps` not `deps`. Although your package would still get installed for developers who don't use it directly, at least it would be omitted from binary packages: http://docs.racket-lang.org/pkg/strip.html -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] syntax write using @-syntax
On Sun, Oct 4, 2015 at 2:53 AM, Neil Van Dykewrote: > Thanks, Eli. That's one of the things I was afraid of. > > The other thing is: does a Scribble formatter ever look at the > line/column position information in the syntax objects? (I thought I > recalled it seeming to do this years ago, maybe for the start of a > multi-line verbatim-like markup.) The *reader* ignores uniform indentation, so when you write something like: @foo{bar baz blah} it reads two spaces for the second line and four for the third. There are a few more rules that make sense in general. I think that they're all listed in the reader documentation (which is also used as test cases, assuming it hasn't changed). If you're talking about the formatter which is part of the html/latex/etc renderer in the documentation system, then I think that it just treats the forms as anything, which means that it doesn't see the source code indentation. > I decided that just a normal Racket sexp write to the ".scrbl" file > suits my needs, since the file doesn't need to be edited manually. > > I also like your idea of just copying the bits of original source > text. (I've done similar things before, with > "http://www.neilvandyke.org/racket-progedit/;.) Though that would > seem to make it even harder to kludge navigating from Scribble errors > on this semi-generated file to the original source bits in the > original source files. Right -- that was the reason for my comment: maybe there's some way to keep the source code where it is, and refer to it from the files that you generate, so no textual generation is actually needed... -- ((x=>x(x))(x=>x(x))) Eli Barzilay: http://barzilay.org/ Maze is Life! -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] syntax write using @-syntax
On Wed, Sep 30, 2015 at 1:54 PM, Greg Hendershottwrote: > So a kind of pretty-printing for at-expressions? > > I'm not aware of an existing procedure to do this. When I wrote about the reader implementation, I did it with a cute hack that: * Uses backslash as the command character instead of @ * Uses a language that extends scribble/text by making unknown backslashed forms print themselves out * Pipe the result into latex The result of that is a combination of latex and racket: some random \foo[bar]{baz} would spit itself out if `foo` is not defined, but if you do define it, then it's the usual application of a function -- so you can define some commands in latex, and other commands in racket. The interesting bit is the second bullet which is doing, IIUC, roughly what Neil wants and you try to do. I looked at the code at some point, and it's not too good enough to just put out (mostly due to its age), but if you're interested (Neil) I can send you the whole thing. In any case, one major comment: > (define (print/at-exp stx-or-sepxr) > (match stx-or-sepxr > [(? syntax? stx) (print/at-exp (syntax->datum stx))] That's a major mistake! The reader puts useful information in the syntax properties. It should tell you how what is a scribble form (so you don't transform everything), and many expressions are in the datum part. Without that, I'm guessing this code will break with common expressions that look like @foo[#:bar "baz"]{blah}. The strings also have useful properties that identify newlines and indentation. There's not enough to reconstruct the original source completely though -- but if the forms come from an existing file, then I think that the best way to hack that is to use the source information and just read the contents of the file. (A bad hack that might lead to a better way to do whatever, something that doesn't require copying source code...) -- ((x=>x(x))(x=>x(x))) Eli Barzilay: http://barzilay.org/ Maze is Life! -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] syntax write using @-syntax
Thanks, Eli. That's one of the things I was afraid of. The other thing is: does a Scribble formatter ever look at the line/column position information in the syntax objects? (I thought I recalled it seeming to do this years ago, maybe for the start of a multi-line verbatim-like markup.) I decided that just a normal Racket sexp write to the ".scrbl" file suits my needs, since the file doesn't need to be edited manually. I also like your idea of just copying the bits of original source text. (I've done similar things before, with "http://www.neilvandyke.org/racket-progedit/;.) Though that would seem to make it even harder to kludge navigating from Scribble errors on this semi-generated file to the original source bits in the original source files. Neil V. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] syntax write using @-syntax
Eli Barzilay wrote on 10/04/2015 03:06 AM: The *reader* ignores uniform indentation, so when you write something like: That's what I was remembering. Thanks. Right -- that was the reason for my comment: maybe there's some way to keep the source code where it is, and refer to it from the files that you generate, so no textual generation is actually needed... I think you're right. My application is the replacement tool for McFly, and I want to eliminate the need for distributed packages to need a package dependency like on `mcfly-runtime`. So, the tool generates a normal-looking ".scrbl" file to include in the package. I think the way to do it is to use the generated normal-looking ".scrbl" file *only* for the distributed package, but have the programmer who is writing the package is having Scribble using syntax objects that have the source location info instead (though there is still some kludging, but it's reasonable). Neil V. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] syntax write using @-syntax
So a kind of pretty-printing for at-expressions? I'm not aware of an existing procedure to do this. It has some interesting wrinkles. Following is my "Greenspun's Tenth Rule" version. (An ad hoc, informally-specified, bug-ridden, slow implementation of half of what's probably needed.) I've commented some deficiencies, I suspect there are many more. #lang racket ;; IMPROVE-ME: Make something usable as a pretty-print-handler (define (print/at-exp stx-or-sepxr) (match stx-or-sepxr [(? syntax? stx) (print/at-exp (syntax->datum stx))] [(list (? symbol? f) (? (negate string?) xs) ... (? string? ss) ... ys ...) (display #\@) (display f) (unless (empty? xs) (display #\[) (display (string-join (map ~a xs) " ")) (display #\])) (unless (and (empty? ss) (empty? ys)) (display #\{) (for ([v (in-list (append ss ys))]) (cond [(string? v) (display v)] ;; FIXME: Encode @ as @"@" ;; IMPROVE-ME: Surround in pipe chars only when necessary ;; IMPROVE-ME: Do line-wrapping at column N. [else (display "@|") (display v) (display "|")])) (display #\}))] [(list (? symbol? f) vs ...) (display #\@) (display f) (display #\[) (display (string-join (map ~v vs) " ")) (display #\])] [v (print v)])) (print/at-exp #'(foo 1 2)) (newline) (print/at-exp #'(foo 1 2 "a")) (newline) (print/at-exp #'(foo 1 2 "a b")) (newline) (print/at-exp #'(foo 1 2 "a b")) (newline) (print/at-exp #'(foo "a")) (newline) (print/at-exp #'(foo "a" "b")) (newline) (print/at-exp #'(foo "a " "b")) (newline) (print/at-exp #'(foo "a is " a " and b is " b)) (newline) (print/at-exp #'(foo "a" "b" 1 2)) (newline) (print/at-exp #'(foo "The " (code "x") " argument.")) (newline) Output: @foo[1 2] @foo[1 2]{a} @foo[1 2]{a b} @foo[1 2]{a b} @foo{a} @foo{ab} @foo{a b} @foo{a is @|a| and b is @|b|} @foo{ab@|1|@|2|} @foo{The @|(code x)| argument.} -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] syntax write using @-syntax
Clarification: The goal is to write a Scribble file, in @-syntax, so that it looks much like a human would write, with the at-signs and (ideally) curly braces. The input to this writing would be a tree of syntax objects. Neil Van Dyke wrote on 09/30/2015 06:25 AM: Is there already a way to programmatically write syntax objects using @-syntax, such that the output could be read with the @-reader? I want to write a `.scrbl` file in @-syntax, from syntax objects that mostly came from `scribble/reader` `read-syntax-inside`. Neil V. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] syntax write using @-syntax
Thanks, Greg. Greg Hendershott wrote on 09/30/2015 01:54 PM: I'm not aware of an existing procedure to do this. It has some interesting wrinkles. Following is my "Greenspun's Tenth Rule" version. [...] -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.