[racket-users] RE: empty lines in a grammer of defform of scribble

2017-03-28 Thread Jos Koot
Option 3 works very fine.
I have incorporated it in https://github.com/joskoot/turing.
Looks very good.
Thanks again, Jos

-Original Message-
From: Dupéron Georges [mailto:jahvascriptman...@gmail.com] 
Sent: martes, 28 de marzo de 2017 15:13
To: Racket Users
Cc: jos.k...@gmail.com
Subject: Re: empty lines in a grammer of defform of scribble

Le lundi 27 mars 2017 22:36:43 UTC+2, jos.koot a écrit :
> When I use #:grammar in a defform,
> the rules of the grammer are separated by empty lines.
> 
> I would like to avoid these empty lines.
> Is it possible?

I haven't seen a built-in mechanism to control this. Generally speaking, the 
tools for documenting bindings are somewhat inflexible,
if your use case falls out of the existing options. This leaves you with three 
possibilities:

1) Copy the source code of the @defform macro, and patch it to your needs
2) Add an option to control this in the mainstream scribble, and hope/wait for 
your Pull Request to be accepted
3) Call the current, official @defform macro, and patch the result.

Solution 1 is future-proof, but your implementation and the official one may 
drift apart, yielding slight inconsistencies in the
rendered output.

Solution 2 sounds better, although I wonder how many quick-fixes like this one 
@defform and similar macros can bear, given that they
are already a maze of particularly complex code, with lots of special-casing.

Solution 3 is the simplest, but is also more brittle, as you depend on the 
output of @defform staying roughly the same.

Here's a quick and dirty implementation of solution 3, note that if you intend 
to use this in production, you should try to make the
match pattern a bit more robust (i.e. a bit more general, in several cases I 
assume single-element lists, and any change in the
implementation of @defform is likely to break this code).

#lang scribble/manual
@(require scribble/manual
  scribble/core
  racket/match
  racket/list)
@(define (defform-remove-empty-lines the-defform)
   (match the-defform
 [(box-splice
   (list
before ...
(nested-flow nf-style
 (list
  (table t-style
 (list other ...
   (list
(table (style "specgrammar" tspec-style)
   (list lines ...)))
   more ...
after ...))
  (define without-empty-lines
;; an empty lines is a sequence of five empty columns:
(remove* (list
  (list
   (paragraph (style #f '(omitable)) (element #f (list (element 
'tt '(nbsp)
   (paragraph (style #f '(omitable)) (element #f (list (element 
'tt '(nbsp)
   (paragraph (style #f '(omitable)) (element #f (list (element 
'tt '(nbsp)
   (paragraph (style #f '(omitable)) (element #f (list (element 
'tt '(nbsp)
   (paragraph (style #f '(omitable)) (element #f (list (element 
'tt '(nbsp)))
 lines))
  (box-splice
   (append
before
(list (nested-flow nf-style
   (list
(table t-style
   (append other
   (list (list
  (table (style "specgrammar" 
tspec-style)
 without-empty-lines)))
   more)
after))]))

@defform-remove-empty-lines[
 @defform[(foo bar baz quux)
  #:grammar ([bar (code:line xxx)
  (code:line yyy)]
 [baz (code:line zzz)
  (code:line ttt)]
 [quux (code:line aaa)
  (code:line bbb)])]{
  Blah blah lots of text.}]

-- 
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.


[racket-users] RE: empty lines in a grammer of defform of scribble

2017-03-28 Thread Jos Koot
Thanks very much indeed for your comprehensive answer.
I tried your code given for option 3.
Works well, but your warning makes me hesitate.
Well, I'll see.
I already have a lot of old code no longer accepted by Racket.
Not a big problem, but requires work to adapt.
Thanks a lot again,
Jos Koot

-Original Message-
From: Dupéron Georges [mailto:jahvascriptman...@gmail.com] 
Sent: martes, 28 de marzo de 2017 15:13
To: Racket Users
Cc: jos.k...@gmail.com
Subject: Re: empty lines in a grammer of defform of scribble

Le lundi 27 mars 2017 22:36:43 UTC+2, jos.koot a écrit :
> When I use #:grammar in a defform,
> the rules of the grammer are separated by empty lines.
> 
> I would like to avoid these empty lines.
> Is it possible?

I haven't seen a built-in mechanism to control this. Generally speaking, the 
tools for documenting bindings are somewhat inflexible,
if your use case falls out of the existing options. This leaves you with three 
possibilities:

1) Copy the source code of the @defform macro, and patch it to your needs
2) Add an option to control this in the mainstream scribble, and hope/wait for 
your Pull Request to be accepted
3) Call the current, official @defform macro, and patch the result.

Solution 1 is future-proof, but your implementation and the official one may 
drift apart, yielding slight inconsistencies in the
rendered output.

Solution 2 sounds better, although I wonder how many quick-fixes like this one 
@defform and similar macros can bear, given that they
are already a maze of particularly complex code, with lots of special-casing.

Solution 3 is the simplest, but is also more brittle, as you depend on the 
output of @defform staying roughly the same.

Here's a quick and dirty implementation of solution 3, note that if you intend 
to use this in production, you should try to make the
match pattern a bit more robust (i.e. a bit more general, in several cases I 
assume single-element lists, and any change in the
implementation of @defform is likely to break this code).

#lang scribble/manual
@(require scribble/manual
  scribble/core
  racket/match
  racket/list)
@(define (defform-remove-empty-lines the-defform)
   (match the-defform
 [(box-splice
   (list
before ...
(nested-flow nf-style
 (list
  (table t-style
 (list other ...
   (list
(table (style "specgrammar" tspec-style)
   (list lines ...)))
   more ...
after ...))
  (define without-empty-lines
;; an empty lines is a sequence of five empty columns:
(remove* (list
  (list
   (paragraph (style #f '(omitable)) (element #f (list (element 
'tt '(nbsp)
   (paragraph (style #f '(omitable)) (element #f (list (element 
'tt '(nbsp)
   (paragraph (style #f '(omitable)) (element #f (list (element 
'tt '(nbsp)
   (paragraph (style #f '(omitable)) (element #f (list (element 
'tt '(nbsp)
   (paragraph (style #f '(omitable)) (element #f (list (element 
'tt '(nbsp)))
 lines))
  (box-splice
   (append
before
(list (nested-flow nf-style
   (list
(table t-style
   (append other
   (list (list
  (table (style "specgrammar" 
tspec-style)
 without-empty-lines)))
   more)
after))]))

@defform-remove-empty-lines[
 @defform[(foo bar baz quux)
  #:grammar ([bar (code:line xxx)
  (code:line yyy)]
 [baz (code:line zzz)
  (code:line ttt)]
 [quux (code:line aaa)
  (code:line bbb)])]{
  Blah blah lots of text.}]

-- 
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.


[racket-users] Re: empty lines in a grammer of defform of scribble

2017-03-28 Thread Dupéron Georges
Le lundi 27 mars 2017 22:36:43 UTC+2, jos.koot a écrit :
> When I use #:grammar in a defform,
> the rules of the grammer are separated by empty lines.
> 
> I would like to avoid these empty lines.
> Is it possible?

I haven't seen a built-in mechanism to control this. Generally speaking, the 
tools for documenting bindings are somewhat inflexible, if your use case falls 
out of the existing options. This leaves you with three possibilities:

1) Copy the source code of the @defform macro, and patch it to your needs
2) Add an option to control this in the mainstream scribble, and hope/wait for 
your Pull Request to be accepted
3) Call the current, official @defform macro, and patch the result.

Solution 1 is future-proof, but your implementation and the official one may 
drift apart, yielding slight inconsistencies in the rendered output.

Solution 2 sounds better, although I wonder how many quick-fixes like this one 
@defform and similar macros can bear, given that they are already a maze of 
particularly complex code, with lots of special-casing.

Solution 3 is the simplest, but is also more brittle, as you depend on the 
output of @defform staying roughly the same.

Here's a quick and dirty implementation of solution 3, note that if you intend 
to use this in production, you should try to make the match pattern a bit more 
robust (i.e. a bit more general, in several cases I assume single-element 
lists, and any change in the implementation of @defform is likely to break this 
code).

#lang scribble/manual
@(require scribble/manual
  scribble/core
  racket/match
  racket/list)
@(define (defform-remove-empty-lines the-defform)
   (match the-defform
 [(box-splice
   (list
before ...
(nested-flow nf-style
 (list
  (table t-style
 (list other ...
   (list
(table (style "specgrammar" tspec-style)
   (list lines ...)))
   more ...
after ...))
  (define without-empty-lines
;; an empty lines is a sequence of five empty columns:
(remove* (list
  (list
   (paragraph (style #f '(omitable)) (element #f (list (element 
'tt '(nbsp)
   (paragraph (style #f '(omitable)) (element #f (list (element 
'tt '(nbsp)
   (paragraph (style #f '(omitable)) (element #f (list (element 
'tt '(nbsp)
   (paragraph (style #f '(omitable)) (element #f (list (element 
'tt '(nbsp)
   (paragraph (style #f '(omitable)) (element #f (list (element 
'tt '(nbsp)))
 lines))
  (box-splice
   (append
before
(list (nested-flow nf-style
   (list
(table t-style
   (append other
   (list (list
  (table (style "specgrammar" 
tspec-style)
 without-empty-lines)))
   more)
after))]))

@defform-remove-empty-lines[
 @defform[(foo bar baz quux)
  #:grammar ([bar (code:line xxx)
  (code:line yyy)]
 [baz (code:line zzz)
  (code:line ttt)]
 [quux (code:line aaa)
  (code:line bbb)])]{
  Blah blah lots of text.}]

-- 
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.