ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Example of passing unexpanded text between \startfoo ... \stopfoo into Lua?
@ 2009-06-18 16:21 Kevin D. Robbins
  2009-06-18 16:53 ` Wolfgang Schuster
  2009-06-19  9:49 ` Matthijs Kooijman
  0 siblings, 2 replies; 5+ messages in thread
From: Kevin D. Robbins @ 2009-06-18 16:21 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 625 bytes --]

Hi Hans and others,

I've been searching the mailing list and source code for one or more
examples of passing unexpanded text appearing between a \startfoo ...
\stopfoo block into Lua, but without luck. Is there such an example you
could point me to?

A colleague and I are experimenting with strategies to implement a literate
programming module for ConTeXt, and we'd like to have something like

\startcodeblock[language=c,file=foo.c, etc.][blockname]
// This is the main routine...
int main()
{
   return 0;
}
\stopcodeblock

We would appreciate any thoughts you have about how to implement such a
module.

Thanks,

Kevin

[-- Attachment #1.2: Type: text/html, Size: 698 bytes --]

[-- Attachment #2: Type: text/plain, Size: 487 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Example of passing unexpanded text between \startfoo ... \stopfoo into Lua?
  2009-06-18 16:21 Example of passing unexpanded text between \startfoo ... \stopfoo into Lua? Kevin D. Robbins
@ 2009-06-18 16:53 ` Wolfgang Schuster
  2009-06-30 15:02   ` Kevin D. Robbins
  2009-06-19  9:49 ` Matthijs Kooijman
  1 sibling, 1 reply; 5+ messages in thread
From: Wolfgang Schuster @ 2009-06-18 16:53 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 18.06.2009 um 18:21 schrieb Kevin D. Robbins:

> Hi Hans and others,
>
> I've been searching the mailing list and source code for one or more  
> examples of passing unexpanded text appearing between a  
> \startfoo ... \stopfoo block into Lua, but without luck. Is there  
> such an example you could point me to?


Something like this (if not give us more information)?

\def\startcodeblock
   {\begingroup
    \setcatcodetable\luacatcodes
    \dodoubleempty\dostartcodeblock}

\long\def\dostartcodeblock[#1][#2]#3\stopcodeblock
   {\modulecode{literateprogramming.codeblock([==[#3]==])}%
    \endgroup}

\startmodulecode

literateprogramming = literateprogramming or { }

function literateprogramming.codeblock(content)
     global.print(content)
end

\stopmodulecode

\starttext

\startcodeblock[language=c,file=foo.c, etc.][blockname]
// This is the main routine...
int main()
{
    return 0;
}
\stopcodeblock

\stoptext

Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Example of passing unexpanded text between \startfoo ... \stopfoo into Lua?
  2009-06-18 16:21 Example of passing unexpanded text between \startfoo ... \stopfoo into Lua? Kevin D. Robbins
  2009-06-18 16:53 ` Wolfgang Schuster
@ 2009-06-19  9:49 ` Matthijs Kooijman
  2009-06-30 15:13   ` Kevin D. Robbins
  1 sibling, 1 reply; 5+ messages in thread
From: Matthijs Kooijman @ 2009-06-19  9:49 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 718 bytes --]

Hi Kevin,

> A colleague and I are experimenting with strategies to implement a literate
> programming module for ConTeXt, and we'd like to have something like
Im not exactly sure what you're trying to achieve, but perhaps you could do
this using a prettyprinter? A pretty printer gets passed each line in the
\startfoo \stopfoo block and can change the line in any way it wants
(including removing it). IIRC there is some minimal general preprocessing
done, something with whitespace I think.

> \startcodeblock[language=c,file=foo.c, etc.][blockname]
> // This is the main routine...
> int main()
> {
>    return 0;
> }
> \stopcodeblock
Perhaps you could say a bit about what the above should output?

Gr.

Matthijs

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

[-- Attachment #2: Type: text/plain, Size: 487 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Example of passing unexpanded text between \startfoo ... \stopfoo into Lua?
  2009-06-18 16:53 ` Wolfgang Schuster
@ 2009-06-30 15:02   ` Kevin D. Robbins
  0 siblings, 0 replies; 5+ messages in thread
From: Kevin D. Robbins @ 2009-06-30 15:02 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1853 bytes --]

Thanks, Wolfgang. My colleague and I are working with the method you
suggested, and we'll report back when we've made more progress. We're
getting there, but slowly.

We always appreciate your help and the help of others on the mailing list!

Kevin

On Thu, Jun 18, 2009 at 10:53 AM, Wolfgang Schuster <
schuster.wolfgang@googlemail.com> wrote:

>
> Am 18.06.2009 um 18:21 schrieb Kevin D. Robbins:
>
>  Hi Hans and others,
>>
>> I've been searching the mailing list and source code for one or more
>> examples of passing unexpanded text appearing between a \startfoo ...
>> \stopfoo block into Lua, but without luck. Is there such an example you
>> could point me to?
>>
>
>
> Something like this (if not give us more information)?
>
> \def\startcodeblock
>  {\begingroup
>   \setcatcodetable\luacatcodes
>   \dodoubleempty\dostartcodeblock}
>
> \long\def\dostartcodeblock[#1][#2]#3\stopcodeblock
>  {\modulecode{literateprogramming.codeblock([==[#3]==])}%
>   \endgroup}
>
> \startmodulecode
>
> literateprogramming = literateprogramming or { }
>
> function literateprogramming.codeblock(content)
>    global.print(content)
> end
>
> \stopmodulecode
>
> \starttext
>
> \startcodeblock[language=c,file=foo.c, etc.][blockname]
> // This is the main routine...
> int main()
> {
>   return 0;
> }
> \stopcodeblock
>
> \stoptext
>
> Wolfgang
>
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : ntg-context@ntg.nl /
> http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive  : https://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
>
> ___________________________________________________________________________________
>

[-- Attachment #1.2: Type: text/html, Size: 2883 bytes --]

[-- Attachment #2: Type: text/plain, Size: 487 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Example of passing unexpanded text between \startfoo ... \stopfoo into Lua?
  2009-06-19  9:49 ` Matthijs Kooijman
@ 2009-06-30 15:13   ` Kevin D. Robbins
  0 siblings, 0 replies; 5+ messages in thread
From: Kevin D. Robbins @ 2009-06-30 15:13 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 2642 bytes --]

There would be at least two results of the \start/\stop-codeblock: first,
the code would be pretty printed as you sugggested in the resulting program
documentation; second, the code would be written to an external source file
foo.c that could then be compiled with, for example, gcc.

Some other features of literate programming include replacement, where in
one code block you reference another that should be cut-and-pasted at the
point of reference in the resulting source file, and cross-references
between code blocks, where in the typeset program documentation each code
block is typeset with references to the other code blocks that use it.

Right now, we've got a prototype implementation that properly writes the
source files with replacements. In MkIV, right now, the cross-referencing
method is not working. We're eagerly (and patiently) waiting for the new
MkIV reference method that allows arbitrary userdata, for example, for
including a sequence number for code blocks typeset on the same page of the
program documentation.

Thanks for your suggestion,

Kevin

On Fri, Jun 19, 2009 at 3:49 AM, Matthijs Kooijman <matthijs@stdin.nl>wrote:

> Hi Kevin,
>
> > A colleague and I are experimenting with strategies to implement a
> literate
> > programming module for ConTeXt, and we'd like to have something like
> Im not exactly sure what you're trying to achieve, but perhaps you could do
> this using a prettyprinter? A pretty printer gets passed each line in the
> \startfoo \stopfoo block and can change the line in any way it wants
> (including removing it). IIRC there is some minimal general preprocessing
> done, something with whitespace I think.
>
> > \startcodeblock[language=c,file=foo.c, etc.][blockname]
> > // This is the main routine...
> > int main()
> > {
> >    return 0;
> > }
> > \stopcodeblock
> Perhaps you could say a bit about what the above should output?
>
> Gr.
>
> Matthijs
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAko7XxgACgkQz0nQ5oovr7wedwCZAei/RBocOnmSUdFACNA+qMlU
> yvYAoKl/dtAEsa5ZF7S5dl/h6mQxS/kh
> =nPdm
> -----END PGP SIGNATURE-----
>
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : ntg-context@ntg.nl /
> http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive  : https://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
>
> ___________________________________________________________________________________
>
>

[-- Attachment #1.2: Type: text/html, Size: 3520 bytes --]

[-- Attachment #2: Type: text/plain, Size: 487 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-06-30 15:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-18 16:21 Example of passing unexpanded text between \startfoo ... \stopfoo into Lua? Kevin D. Robbins
2009-06-18 16:53 ` Wolfgang Schuster
2009-06-30 15:02   ` Kevin D. Robbins
2009-06-19  9:49 ` Matthijs Kooijman
2009-06-30 15:13   ` Kevin D. Robbins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).