Documentation
¶
Overview ¶
Package spdxexpr parses SPDX 2.3 license expressions with a bounded grammar and a pinned license list. It preserves AND, OR, parentheses, and WITH exceptions as a tree; it never flattens an expression into a bag of names, never maps NOASSERTION/NONE/UNLICENSED or unknown identifiers to a license, and reports what it could not recognize.
Grammar (SPDX 2.3 Annex D):
expression := disjunction
disjunction := conjunction ( "OR" conjunction )*
conjunction := primary ( "AND" primary )*
primary := simple [ "WITH" exception ] | "(" expression ")"
simple := license-id [ "+" ] | "LicenseRef-" idstring | "DocumentRef-" idstring ":" "LicenseRef-" idstring
Index ¶
Constants ¶
const ListVersion = "3.27.0"
ListVersion is the pinned SPDX License List release embedded in this package. Recorded on every parsed evidence row so a list upgrade is a new resolver version, not a silent change.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Licenses ¶
type Licenses interface {
License(id string) (canonical string, deprecated, ok bool)
Exception(id string) (canonical string, deprecated, ok bool)
}
Licenses returns whether an identifier is on the pinned list, its canonical casing, and whether it is deprecated.
type Node ¶
type Node struct {
Kind Kind `json:"kind"`
// ID is the license identifier for KindLicense (canonical list casing),
// or the full LicenseRef-/DocumentRef- identifier for KindReference.
ID string `json:"id,omitempty"`
// OrLater is the "+" suffix on a license identifier.
OrLater bool `json:"or_later,omitempty"`
// Exception is the exception identifier for KindWith; Children[0] is the
// licensed term the exception applies to.
Exception string `json:"exception,omitempty"`
Children []*Node `json:"children,omitempty"`
// Known is false for KindLicense/KindWith identifiers that are not on the
// pinned list. It is always true for KindReference nodes.
Known bool `json:"known"`
// Deprecated marks identifiers the list marks deprecated (kept, flagged).
Deprecated bool `json:"deprecated,omitempty"`
}
Node is one node of the expression tree. Children is ordered as written.
type Result ¶
type Result struct {
Raw string
Status Status
Expression *Node
// Normalized is the canonical rendering (list casing, single spaces,
// minimal parentheses preserved as written). Empty unless Status is
// parsed or unknown_terms.
Normalized string
// UnknownTerms lists identifiers not on the pinned list, in order.
UnknownTerms []string
// References lists LicenseRef-/DocumentRef- identifiers, in order.
References []string
// Deprecated lists deprecated identifiers used, in order.
Deprecated []string
// Problem explains StatusInvalid without echoing more than a bounded
// prefix of the input.
Problem string
}
Result is the outcome of Parse.
type Status ¶
type Status string
Status classifies a raw license value before or after parsing.
const ( // StatusParsed: a syntactically valid expression whose every identifier // is on the pinned list (LicenseRef/DocumentRef identifiers are allowed // and reported separately). StatusParsed Status = "parsed" // StatusUnknownTerms: valid syntax with at least one identifier that is // not on the pinned list and not a LicenseRef. StatusUnknownTerms Status = "unknown_terms" // StatusNoAssertion: NOASSERTION (or empty): no claim was made. StatusNoAssertion Status = "no_assertion" // StatusNone: NONE: the producer asserts there is no license information. StatusNone Status = "none" // StatusUnlicensed: npm's UNLICENSED sentinel: use is not granted. StatusUnlicensed Status = "unlicensed" // StatusInvalid: the value is not an SPDX expression (free text, "SEE // LICENSE IN ...", unbalanced parentheses, bad operators). StatusInvalid Status = "invalid" )