pmonks / clj-spdx

Clojure wrapper around spdx/Spdx-Java-Library
Apache License 2.0
2 stars 1 forks source link

Represent SPDX operator precedence in parse trees #25

Closed pmonks closed 10 months ago

pmonks commented 11 months ago

Currently the parse trees returned from spdx.expressions/parse don't represent the precedence order for AND and OR (as specified in Annex D of the SPDX specification). Rather than leaving this to users of clj-spdx, the library should explicitly represent operator precedence (i.e. by introducing grouping where it didn't exist in the original expression) to make it explicit.

For example, this SPDX expression:

GPL-3.0 OR MIT AND Apache-2.0

should be parsed to:

[{license-id "GPL-3.0-only"} :or [{license-id "MIT"} :and {license-id "Apache-2.0"}]]
pmonks commented 10 months ago

Fixed in rev ffcbd9b9144f6ac4032bda1521f5c58ce22b20e4, and released in v1.0.107.

Note: as part of this change, operators were made prefix in the parse tree, rather than infix (as was previously the case).

So the example above gets parsed to:

[:or {license-id "GPL-3.0-only"} [:and {license-id "MIT"} {license-id "Apache-2.0"}]]