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

Expansions #2421

Merged
merged 10 commits into from
Sep 26, 2024
Merged

Expansions #2421

merged 10 commits into from
Sep 26, 2024

Conversation

brucemiller
Copy link
Owner

This PR improves clarity of when expansion is full or partial, and improves naming of utility functions and Parameter types. Reminder: partial expansion is what \edef does which defers expansion of \protected definitions, and the result of expanding \the.
Now the Expand() function fully expands, and there is a new ExpandPartially() function. Similarly, the Expanded and ExpandedPartially Parameter types expand fully or partially. Finally, a few commands have been corrected to the right versions, such as some pdfTeX commands have been updated to use XGeneralText (a partially expanding version of GeneralText).

@brucemiller brucemiller requested a review from dginev September 23, 2024 22:29
Copy link
Collaborator

@dginev dginev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice consistency upgrade and bug fixes!

I left some minor comments, but the PR is good to merge as-is (the new test is a big help).

my $autoclose = $toplevel; # Potentially, these should have distinct controls?
my $for_evaluation = $toplevel;
my $autoclose = $toplevel; # Potentially, these should have distinct controls?
# my $fully_expand = $toplevel;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some leftover comments for removal

$gullet->readBalanced(1, 0, 1); },
my $token = $gullet->readToken;
if (!$token->equals(T_BEGIN)) { # if non-brace, wrap the token in {}, to isolate it
$gullet->unread($token, T_END); }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scary coding pattern. unread T_END then invoke readBalanced with $require_open set to "false".

Not to say it is wrong. Just wondering if it is scary enough to get its own named subroutine readExpanded in Gullet. Which can then take the $expanded arg as an input arg.

I think this PR uses the technique 4 times, so maybe there's some value in naming it...

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was initially inclined to think that it should be (slightly) scary, rather than hidden away, since it's doing something rather peculiar. The use case is you're reading a "plain" argument, like #1, which would also accept a single token, and then asking it to be expanded. What if it's a macro expecting arguments?
Alternatively, it may want a helper function if there's a sensible (but likely convoluted) error recovery; At this point I don't know what that would be. (but see below)

@@ -899,17 +899,31 @@ sub generateID_nextid {
#
#======================================================================

# Return $tokens with all tokens expanded
# Return $tokens with all tokens fully expanded
our $T_EXPAND_END_CHECK = T_OTHER('END EXPANSION');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that be a T_MARKER ?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, yeah, but T_MARKER never make it out of Gullet. OTOH, perhaps if there's a helper function from within Gullet, something safer could be arranged? Either way, it's all about error recovery.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but if the T_OTHER makes it out of Gullet and encounters some processing in the Error realm, it may make it out into the final XML. Which we may appreciate, but I suspect the average user won't...

That said, the last time I used a magic token I invented my own catcode (CC_SMUGGLE_THE), so I don't really have a clear head on the topic. Your call, it works as-is.

…rtial; fully expanded); Use that for Expanded, ExpandedPartially ParameterTypes (slight update of POD)
@brucemiller
Copy link
Owner Author

Thanks for your comments; they caused me to rethink a couple of points, so please take another look and re-review.

@dginev dginev self-requested a review September 26, 2024 18:50
Copy link
Collaborator

@dginev dginev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new approach is quite elegant, very nice idea!

Looks good to merge in my eyes.

@brucemiller brucemiller merged commit 6167612 into master Sep 26, 2024
26 checks passed
@brucemiller brucemiller deleted the expansions branch September 26, 2024 21:09
teepeemm pushed a commit to teepeemm/LaTeXML that referenced this pull request Oct 29, 2024
* Adjust args to readXToken and readBalanced to support but fully and partially expanded variations

* Default state->lookupExpandable same as gullet->readXToken

* Make GeneralText, XGeneralText use gullet->skipFiller correctly; have Expanded be fully expanded, but introduce ExpandedPartially

* pdfTeX's \expanded, \pdfstrcmp should use XGeneralText parameter types

* Make Expand() expand fully; add ExpandPartially defers \protected,\the

* Use partial expansion for unit type arguments

* Add test case distinguishing fully vs partially expanded cases

* Clarifying comments

* Simplify Expand(),ExpandPartially(), probably more robust, if slightly less efficient

* For gullet->readArg Add optional expanded argument (0,1,2 for not; partial; fully expanded); Use that for Expanded, ExpandedPartially ParameterTypes (slight update of POD)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants