Dear Bryan,
Thanks for the extensive example, that is very helpful. I've been thinking
about this one since we last discussed it.
You've set a rather high bar. You explicitly want your file/program to *not* be
XML. But then you want lots of XML inside it. So you'll need to recover all
that XML, as XML, not text.
1. You can xi:include the file, but you *must* use parse="text" since your
file cannot have an overall XML root element. Your previous comments suggested
the include would indicate some structure. It can't. File structure is immaterial.
2. I suggest surrounding the include with
<program language="bash" literate="yes">
(a) There is no support for bash yet (I don't think) but we will want to add to
the languages table the character used for a comment. Just experiment with "#"
hard-coded in a variable for now.
(b) We already have a version of literate programming. So this needs some other
moniker to avoid confusion (sorry, early bird gets the worm). So do not use
@literate. Do use yes/no.
(c) This can be your playground - nobody else is using this attribute, so
nothing you do will impact other parts of PreTeXt once you do the following.
3. The pretext-assembly.xsl stylesheet is the pre-processor. It has several
passes. Add a new template in the "representations" pass that matches on
program[@literate='yes']
4. Your goal is to parse the text/program (a recursive template to go
line-by-line?) and create XML. Both XML to guide your later conversion to LaTeX
and HTML, and to recover/convert the PreTeXt XML into *actual* XML (i.e. nodes,
not characters). You can use unofficial ad-hoc XML here, perhaps namespaced
with the "pi" prefix, to make it harder for authors to abuse.
Almost certainly, you will want to use the exsl:node-set() function to convert
a Result Tree Fragment (text that *looks* like XML) into nodes you can output in
the XML-to-XML conversion that this stylesheet does. Do not use
"disable-output-escaping" - that is a red flag.
5. The pretext/pretext script (not the CLI) has a format "assembly-static"
which you can use for testing. Getting any PreTeXt XML out of the program's
comments and into this output is the first big step. Aligning indentation in
output formats feels like the other big step.
As always, we can chat during Drop-In (but not tomorrow).
Rob
On 7/20/22 20:44, Jones, Bryan wrote:
> All,
>
> Per my conversation with Rob, the code below provides an example of a (semi-)
> literate programming syntax [1] I'd like PreTeXt to support. I've applied it to
> a script used to build a proposal that I just wrote with some of the PreTeXt
> community. (It takes a programmer to convert a simple task into a complex
> program...)
>
> The text and attached file is a bash script; hence, comments begin with a #.
> Here is my suggested approach:
>
> 1. Comments in lines which contain a mix of code and comment, such as:
> mv foo.txt bar.txt # The frobulator expects only bars!
> are not interpreted as PreTeXt.
> 2. Comments which lack a space after the comment character, such as:
> #!/usr/bin/env bash
> are not interpreted as PreTeXt.
> 3. All other comments are interpreted as PreTeXt. Leading spaces before the
> comment character must be preserved, so that comments line up with the
> surrounding code.
>
> For an example of these principles in action, see SourceClassifier.py - a module
> to lex source code
> <
https://codechat.readthedocs.io/en/master/CodeChat/SourceClassifier.py.html>;
> in this instance, the underlying Python source code
> <
https://codechat.readthedocs.io/en/master/_sources/CodeChat/SourceClassifier.py> contained
> comments in ReStructuredText/Sphinx (Runestone's previous markup). I'd like to
> be able to do the same thing, but use PreTeXt as the underlying markup language.
>
> *My questions:*
>
> 1. I would appreciate ideas/thoughts/feedback on this approach.
> 2. What's the next step -- shall I suggest detailed PreTeXt markup that this
> <
https://pretextbook.org/doc/guide/html/topic-literate-programming.html>), I
>
http://www.ece.msstate.edu/~bjones <
http://www.ece.msstate.edu/~bjones>
> bjones AT ece DOT msstate DOT edu
> voice
662-325-3149
> fax
662-325-2298
>
> Our Master, Jesus Christ, is on his way. He'll show up right on
> time, his arrival guaranteed by the Blessed and Undisputed Ruler,
> High King, High God.
> - 1 Tim. 6:14b-15 (The Message)
>
> --
> You received this message because you are subscribed to the Google Groups
> "PreTeXt development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to
pretext-dev...@googlegroups.com
> <mailto:
pretext-dev...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/pretext-dev/CAHhYbD-Mq%3DQGyOw2OPf1SxKwK1UbFrL6EL2cyaZrmJz7vjt%3D1g%40mail.gmail.com
> <
https://groups.google.com/d/msgid/pretext-dev/CAHhYbD-Mq%3DQGyOw2OPf1SxKwK1UbFrL6EL2cyaZrmJz7vjt%3D1g%40mail.gmail.com?utm_medium=email&utm_source=footer>.