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

Decide if nested optional and alt tags should be allowed and update schema and/or tools appropriately #462

Closed
goneall opened this issue Oct 27, 2017 · 12 comments

Comments

@goneall
Copy link
Member

goneall commented Oct 27, 2017

As noted by @wking in issue #457 (comment), the schema currently allows for nested optional tags. The SPDX tools currently disallows any nesting of alt or optional tags.

Either the schema or the tools should be updated once we decide if this should be allowed.

@wking
Copy link
Contributor

wking commented Oct 27, 2017 via email

@goneall
Copy link
Member Author

goneall commented Oct 28, 2017

Although the nested alt and optional tags was part of the discussion for issue #393 , I would like to separate out the issue of allowing formatting and allowing nested optional and alt tags.

I do not understand the expected behavior of the above example. What is the expected behavior of a nested alt text inside an optional block? How is it to be used in a matching scenario.?

@wking
Copy link
Contributor

wking commented Oct 28, 2017 via email

@goneall
Copy link
Member Author

goneall commented Oct 28, 2017

@wking Thanks for the description. Makes sense. Challenging to implement in the tools, however. I'll investigate the effort to support, but I believe it will be difficult to add support in the SPDX tools prior to release. Of course, contributions to the SPDX tools to implement are welcome.

@goneall goneall changed the title Fix schema to disallow nested optional tags Decide if nested optional and alt tags should be allowed and update schema and/or tools appropriately Oct 30, 2017
@goneall
Copy link
Member Author

goneall commented Oct 30, 2017

The tools implementation to support nesting of optional and var would be quite involved and may even be impractical.

The challenge is that most of the regexes are "greedy" and would normally consume the rest of the license text.

To solve for this, in the SPDX tools, I search for remaining text that matches the license template and narrow down the text used in the regex to only the code not already matched.

Adding nested optional and var tags would significantly complicate this and make some pretty complex and somewhat ugly code even uglier.

wking added a commit to wking/license-list-XML that referenced this issue Nov 1, 2017
By differentiating between formattedAltText..., which may contain
<alt> and <optional>, and formattedFixedText..., which may not.  The
optionalType is using formattedAltTextGroup, because nesting variable
content inside an optional element can be useful [1,2].  The <alt>
element, on the other hand, specifies all the variable options in its
match attribute, so there's no need for nesting variable elements
inside the alt body.

[1]: spdx#393
[2]: spdx#462
@wking
Copy link
Contributor

wking commented Nov 1, 2017 via email

@wking wking mentioned this issue Nov 3, 2017
@goneall
Copy link
Member Author

goneall commented Nov 5, 2017

We also need to update the template language to support any nesting we agree on.

Adding nesting to the <<beginOptional>> ... <<endOptional>> looks straight forward, but adding nesting to the <<var ...>> constructs is a bit more challenging.

The example above has nesting inside the <optional> elements, but does not include any nesting inside of the <alt> elements. Are there any scenarios we can think of where we would support nesting in the <alt> element? It would seem it would almost always be easier to include the optional in the regex using the ?(optionaltext) construct.

@wking
Copy link
Contributor

wking commented Nov 5, 2017

Are there any scenarios we can think of where we would support nesting in the <alt> element?

I don't think so, and this is what #475 is about.

wking added a commit to wking/license-list-XML that referenced this issue Nov 6, 2017
By differentiating between formattedAltText..., which may contain
<alt> and <optional>, and formattedFixedText..., which may not.  The
optionalType is using formattedAltTextGroup, because nesting variable
content inside an optional element can be useful [1,2].  The <alt>
element, on the other hand, specifies all the variable options in its
match attribute, so there's no need for nesting variable elements
inside the alt body.

Also require fixed text for <notes>, since those aren't templates.
And drop the unused notesType, since they're vanilla formatted text.

We almost certainly want to drop titleText and copyrightText fro the
formatted*TextGroup choices, but I'm leaving that for [3].

[1]: spdx#393
[2]: spdx#462
[3]: spdx#452
@goneall
Copy link
Member Author

goneall commented Nov 11, 2017

Can you provide more details on this? It seems like you could
approach this recursively by replacing any optional element with a .*
regexp, regardless of whether an optional tag contained optional or
alt children.

Doing a recursive matching would be a good approach, but would require some significant design and code changes in the current implementation.

The current matching code can be found at https://github.com/spdx/tools/blob/a1d1fb79e78ca4ee737b104e9f8174908e99d0fb/src/org/spdx/compare/LicenseCompareHelper.java#L508

The license template parser is implemented using an interface ILicenseTemplateOutputHandler. This interface assumes that optional text is just text and does not have an internal structure. If we changed the design of the interface, all other implementations of this interface would also have to change.

This type of change is certainly possible, but I would estimate about a week's worth of work to make the changes and properly test.

@goneall
Copy link
Member Author

goneall commented Nov 24, 2017

The SPDX tools have now been updated to support nested optional.

Based on the discussions and email threads, no one seems to object to changing the spec to allow var and optional tags inside optional tags.

Pull request made to the spec Allow embedded rules for rule type optional for license templates to make this change.

Closing this as resolved.

@wking
Copy link
Contributor

wking commented Dec 29, 2017

Closing this as resolved.

Now that this is settled, we can probably remove the “Nested Optional” label from our label list. That makes it easier to find the label you need when labelling new issues.

@goneall
Copy link
Member Author

goneall commented Dec 29, 2017

Now that this is settled, we can probably remove the “Nested Optional” label from our label list. That makes it easier to find the label you need when labelling new issues.

Good suggestion - it is now removed

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

No branches or pull requests

2 participants