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

feat(lxp): Add parser option to disable attribute positions #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Omikhleia
Copy link

@Omikhleia Omikhleia commented Dec 6, 2024

This PR is a proposal to add an additional flag to disable the attribute positions in the attribute list passed on StartElement.

Rationale:
I understand attribute positions may be interesting in some use cases (e.g. to re-generate some other output respecting the same order), but for use cases where they are not needed, they take useless memory, and useless code if one wants to remove them.

Note:
I also fixed a small mistake in the example that was given in the "manual" (the position list consists in attribute names, not attribute value).

For reference:

@Omikhleia Omikhleia force-pushed the feat-option-disable-attribute-positions branch from 8c2b92f to 5dbfb96 Compare December 6, 2024 13:36
Copy link
Member

@Tieske Tieske left a comment

Choose a reason for hiding this comment

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

Can you please add some tests?

{[1] = "Ierusalimschy, Roberto",
[2] = "Programming in Lua",
{[1] = "author",
[2] = "title",
Copy link
Member

Choose a reason for hiding this comment

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

good catch!

@@ -144,13 +144,16 @@ <h4>Finishing parsing</h4>
<h4>Constructor</h4>

<dl class="reference">
<dt><strong>lxp.new(<em>callbacks [, separator[, merge_character_data]]</em>)</strong></dt>
<dt><strong>lxp.new(<em>callbacks [, separator[, merge_character_data, [attribute_position]]]</em>)</strong></dt>
Copy link
Member

Choose a reason for hiding this comment

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

should we change this function signature to an options table, instead of positional args?

Copy link
Member

Choose a reason for hiding this comment

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

That would probably be a more user friendly API, but it would also be a major breaking change. This way the change is non-breaking and people should be able to upgrade without a hitch. The option to change the signature at a later date when we're considering cutting a major release would still be open too. Or provide a new function name for the new signature. Whatever the long term API design would be I'd be in favor of a non-breaking change we can get through and widely distributed over a major version bump that breaks things with little motivation for people to take the dive.

Suggested change
<dt><strong>lxp.new(<em>callbacks [, separator[, merge_character_data, [attribute_position]]]</em>)</strong></dt>
<dt><strong>lxp.new(<em>callbacks [, separator[, merge_character_data[, attribute_position]]]</em>)</strong></dt>

Copy link
Member

Choose a reason for hiding this comment

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

No need to be breaking. Change the signature to new(callbacks[, options]), and just check if options is a string (old format, then also grab merge_character_data), or if it is a table, in which case the options are in the table.
This is probably easier done Lua side than C side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants