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

Comments welcome #2140

Merged
merged 4 commits into from
Jul 4, 2023
Merged

Comments welcome #2140

merged 4 commits into from
Jul 4, 2023

Conversation

brucemiller
Copy link
Owner

This PR deals more consistently with comments, whether Tokens, digested or XML nodes, appearing in places we previously didn't expect them.

The function IsEmpty tests whether a tokens or list is empty, ignoring comments, and is generally preferred over scalar($x->unlist ); element_next($node), element_prev($node) are usually preferred over $node->previousSibling. Also, avoid splitting xml text nodes with comments, pushing them to the front.

Also, remove an obsolete form of DefMathLigature.

@brucemiller brucemiller requested a review from dginev July 3, 2023 17:04
my $prev;
while (($prev = $node->previousSibling) && ($prev->nodeType != XML_ELEMENT_NODE)) {
$node = $prev; }
return $prev; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Naming question: Given nextSibling and previousSibling have the naming scheme with the modifier in front and the kind of object second, I'd be tempted to suggest next_element and previous_element (which are in a way abbreviated forms of get_next_element and get_previous_element).

That's roughly how I've internalized the already existing element_nodes which seems to align with childNodes in the libxml wrapper.

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 guess at the time I was writing, I was emphasizing "element".

return 0 unless IsEmpty($thing->unlist); }
elsif ($ref eq 'LaTeXML::Core::Token') {
my $cc = $$thing[1];
return 0 if ($cc == CC_LETTER) || ($cc == CC_OTHER) || ($cc == CC_ACTIVE) || ($cc == CC_CS); }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, this seems incomplete? A T_BEGIN, T_END, T_MATH, T_ALIGN, T_PARAM aren't empty either. Maybe it's somewhat briefer to invert the condition:

return 0 unless ($cc == CC_COMMENT) || ($cc == CC_MARKER) || ($cc == CC_IGNORE);

Copy link
Collaborator

@dginev dginev Jul 3, 2023

Choose a reason for hiding this comment

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

though if this is meant to be used for a single Token, I'd also wonder if we shouldn't treat all tokens that have empty text as empty as well.

return 0 unless ($cc == CC_COMMENT) || ($cc == CC_MARKER) || ($cc == CC_IGNORE) 
  || (!length($$thing[0]));

Edit: Or indeed use the regex leveraged a little lower for non-space $$thing[0] !~ /^\s*$/

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 think you have the logic flipped; this line should short-circuit immediately returning "false" if we encounter a token that is not empty.
OTOH, your point is good: should we consider T_LETTER("") to be empty?
OTOOH, I expect this issue may have to be revisited to distinguish between truly empty, and just spacey things? Hopefully I can defer that concern?

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.

Read through the code, the IsEmpty consistency looks nice to have. Just the couple of minor comments.

@brucemiller
Copy link
Owner Author

You raise good questions, but with the refactors in this PR, it should be easy to find & revisit later if we want to.

@brucemiller brucemiller merged commit cb0194f into master Jul 4, 2023
26 checks passed
@brucemiller brucemiller deleted the comments-welcome branch July 4, 2023 01:00
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