Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul include/preamble semantics (and lots of plumbing for the instantiation / run cycle) #1373

Merged
merged 48 commits into from
Jul 19, 2022

Conversation

alerque
Copy link
Member

@alerque alerque commented Apr 18, 2022

Closes #653
Closes #798
Closes #1092
Closes #1413
Lays groundwork for #1438


BREAKING CHANGE: The -I / --include option whose use was overloaded for more than one purpose is deprecated in favor of more specific replacements: -r / --require for loading code into SILE before input processing, -p / --preamble for processing content prior to a document and -P / --postamble for processing content after a document.

c.f. especially my latest romment

Having reviewed this a bit further, I don't think the -I option is even fixable. It tries to be too smart and as a result can't easily be manipulated to do any specific thing.

  • Does it load Lua code? or process SILE content?
  • Does it run before loading the parser or after?
  • Does it search for files relative to the PWD? Or the input document? Or the Lua search path?

Some of these combinations are mutually exclusive and guessing can lead to breakable. I propose deprecating it entirely in favor of more specific and predictable alternatives.

@alerque
Copy link
Member Author

alerque commented Apr 18, 2022

I haven't actually implemented this change yet, just updated the CLI hints and man page for what I am proposing. This draft PR is a request for comment, especially from @simoncozens.

Here is what the new bits of man page would be:

       -I, --include=filename
              Deprecated, will be removed.  Please use --require, --preamble, or --postamble.

       -r, --require=module
              Require a class, package, or other code to be loaded before processing the main
              input.  The value should be a loadable module name without a file extension and
              will be loaded using SILE's module search path.  This is particularly useful if
              the input file is in a non-native XML or other format and  requires  loading  a
              class or other code that extends SILE to understand how to read and process the
              input document.  May be specified more than once.

       -p, --preamble=filename
              Include a SILE, XML, or other content file  before  the  input  document.   The
              value  should  be  a  full  filename with a path relative to PWD or an absolute
              path.  May be specified more than once.

       -P, --postamble=filename
              Include a SILE, XML, or other content file after the input document.  The value
              should be a full filename with a path relative to PWD or an absolute path.  May
              be specified more than once.

@alerque
Copy link
Member Author

alerque commented Apr 18, 2022

A couple more notes:

  • We could expand the -r option to be able to read SIL files using the Lua search path (and hence finding things in the SILE installation rather than the current project) but I don't really see the point. We can rewrite the docbook class in Lua, and I haven't come up with other use cases for this that really make sense. Yet.

  • We currently have something internally called "preamble", but it isn't actually handled as a preamble. I would suggest the actual --preamble content be handled after processing the document declaration from the main input AST, but before diving any farther into the AST. This seems like it would be more utilitarian than doing anything with it before we even know the papersize or class.

@alerque alerque changed the title Overhaul include/preamble semantics RFC: Overhaul include/preamble semantics Apr 19, 2022
@alerque alerque added this to the v0.14.0 milestone May 21, 2022
@Omikhleia
Copy link
Member

Omikhleia commented Jun 29, 2022

We currently have something internally called "preamble", but it isn't actually handled as a preamble. I would suggest the actual --preamble content be handled after processing the document declaration from the main input AST, but before diving any farther into the AST. This seems like it would be more utilitarian than doing anything with it before we even know the papersize or class.

Erm, maybe I did not fully understand the point, but for many XML cases, I feel that the current "preamble" is actually what is needed: a document that will define the papersize, class and other settings or options, before processing the XML content.
For non-XML cases, this would still be valid, e.g. by using a "preamble" before a document, I can have a generic one, say, for book-size paper, high resolution, etc. and another for other purposes (A4 size, other options), as an easy generic switch.

EDIT: Or maybe the above is covered by your -r now?

@alerque
Copy link
Member Author

alerque commented Jun 29, 2022

I think (still playing with exactly which option does what) you would still be able to use a pre-document-document roughly like you are now, but with the new arguments I would envision you loading up a class using sile -r classes.mything document.xml. I actually have a POC over here with that working, but I'm not quite sure where class options should go any more. It is redundant to also send a preamble to set the class, but it does make it more obvious how to set options. It also crossed my mind we could do it with a more specific semantic such as sile --class mything --options papersize=a6 document.xml.

@Omikhleia
Copy link
Member

Omikhleia commented Jun 29, 2022

Ah I see the idea.

In the cases I consider, it could perhaps be the same class, with different class options, but also:

  • other commands (possibly via additional packages, e.g. my "print" preamble could load my experimental printoptions package to fix image resolution and rasterize vectors; while my "preprint" version could do none of this, but load cropmarks and set the target paper to A4, etc.
  • other settings (e.g. a "review" version could be on full A4 with larger font and huge base line skips for annotations)

For an actual use case, e.g. my XML lexicon is multi-lingual, my current preambles selects the main language and related options (e.g. the English version skips all French elements, the French version skips most of the English but keeps some of it such as glosses, since the definition come (more or less) from the English author. Currently it the same class, and the preambles (one for "fr", one for "en") just enables different settings for the specific output. Of course in that case, I could have maybe used class options rather than settings, but that could make a lot of them... And having to remember all those to pass as command line argument is also a bit unsatisfying.

That is to say, I am unsure requiring a class only and playing with CLI options is the way to go. But I am not certain the above makes full sense either!

@alerque
Copy link
Member Author

alerque commented Jun 29, 2022

I don't see any reason you couldn't mix and match. What you are doing is fine if that's what you want and I don't see any reason to change it. The issue I have is that there are things the current system will not let you accomplish. It also has weird gotchas like not being able to include SIL things that happen to have the same name as a Lua thing (or vise versa). There just isn't enough control currently.

@alerque alerque force-pushed the fix-includes branch 3 times, most recently from 684dd78 to 560b991 Compare July 1, 2022 23:03
alerque added 11 commits July 2, 2022 23:50
BREAKING CHANGE: The `-I` / `--include` option was overloaded for more
than one purpose and is now deprecated in favor of more specific
replacements: `-r` / `--require` for loading code into SILE before input
processing, `-p` / `--preamble` for processing content prior to
a document and `-P` / `--postamble` for processing content after
a document.
I started trying to fix the SILE.inputs table to make room for new
things coming from the CLI—only to discover later that was for something
else. That let to a yack shave and I decided the best thing to do was
refactor some of the core libraries sooner rather than later to start
cleaning up the name space.

This let to a yack shave where I couldn't move some bits without doing
it all at once, so I just blew it all up and put it back together again.
All tests should pass before *and* after this commit with no changes to
what is being tested.

BREAKING CHANGE: Some internal files and APIs got renamed with more
structured name spaces. In particular the inputter, shaper, and
outputter libraries all have a common naming scheme now and sensible
inheritance chains. No functionality was harmed, but if you are
overriding undocumented internal Lua methods you might have to update
your name spaces to match.
Previous versions of SILE created output files even if they were going
to crash hard before writing anything into it. Current iterations wait
until we at least do a few things like instantiate the class, so now we
have a chance to fail before writing anything.
The output file and meta data is not instantiated later *after* we know
what final paper size is. Previous versions started the PDF at one size
and then changed it out from under the meta data.
@alerque alerque force-pushed the fix-includes branch 2 times, most recently from 607ff97 to ac9c111 Compare July 2, 2022 21:05
@alerque alerque marked this pull request as ready for review July 16, 2022 22:54
@alerque alerque requested review from a team and simoncozens as code owners July 16, 2022 22:54
@alerque alerque added the enhancement Software improvement or feature request label Jul 19, 2022
@alerque alerque merged commit 22becc1 into master Jul 19, 2022
@alerque alerque deleted the fix-includes branch July 19, 2022 10:41
@alerque
Copy link
Member Author

alerque commented Jul 19, 2022

I realize there is more work to be done along these lines but testing and reasoning about all the changes in context with other developments was starting to get too hard in a branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Software improvement or feature request
Projects
2 participants