Debian Codegraph @

spdxexp/scan.go

raw symbols SCIP
1 package spdxexpscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/
2
3 /* Translation to Go from javascript code: https://github.com/clearlydefined/spdx-expression-parse.js/blob/master/scan.js */
4
5 import (
6 "errorsscip-go gomod github.com/golang/go/src go1.24 errors/"
7 "fmtscip-go gomod github.com/golang/go/src go1.24 fmt/"
8 "regexpscip-go gomod github.com/golang/go/src go1.24 regexp/"
9 "stringsscip-go gomod github.com/golang/go/src go1.24 strings/"
10 )
11
12 type expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream# struct {
13 expressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#expression. string
14 indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index. int
15 errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err. error
16 }
17
18 type tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# struct {
19 rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role. tokenrolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/tokenrole#
20 valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value. string
21 }
22
23 type tokenrolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/tokenrole# uint8
24
25 const (
26 operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken. tokenrolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/tokenrole# = iota
27 documentRefTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/documentRefToken.
28 licenseRefTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseRefToken.
29 licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken.
30 exceptionTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/exceptionToken.
31 )
32
33 // Scan scans a string expression gathering valid SPDX expression tokens. Returns error if any tokens are invalid.
34 func scanscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/scan().(expression string) ([]tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#, error) {
35 var tokens []tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#
36 var token *tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#
37
38 exp := &expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#{expressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#expression.: expression, indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.: 0, errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err.: nil}
39
40 for exp.hasMorescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#hasMore().() {
41 exp.skipWhitespacescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#skipWhitespace().()
42 if !exp.hasMorescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#hasMore().() {
43 break
44 }
45
46 token = exp.parseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#parseToken().()
47 if exp.errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err. != nil {
48 // stop processing at first error and return
49 return nil, exp.errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err.
50 }
51
52 if token == nil {
53 // TODO: shouldn't happen ???
54 return nil, errorsscip-go gomod github.com/golang/go/src go1.24 errors/.Newscip-go gomod github.com/golang/go/src go1.24 errors/New().("got nil token when expecting more")
55 }
56
57 tokens = append(tokens, *token)
58 }
59 return tokens, nil
60 }
61
62 // Determine if expression has more to process.
63 func (exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#) hasMorescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#hasMore().() bool {
64 return exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index. < len(exp.expressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#expression.)
65 }
66
67 // Try to read the next token starting at index. Returns error if no token is recognized.
68 func (exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#) parseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#parseToken().() *tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# {
69 // Ordering matters
70 op := exp.readOperatorscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readOperator().()
71 if exp.errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err. != nil {
72 return nil
73 }
74 if op != nil {
75 return op
76 }
77
78 dref := exp.readDocumentRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readDocumentRef().()
79 if exp.errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err. != nil {
80 return nil
81 }
82 if dref != nil {
83 return dref
84 }
85
86 lref := exp.readLicenseRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readLicenseRef().()
87 if exp.errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err. != nil {
88 return nil
89 }
90 if lref != nil {
91 return lref
92 }
93
94 identifier := exp.readLicensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readLicense().()
95 if exp.errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err. != nil {
96 return nil
97 }
98 if identifier != nil {
99 return identifier
100 }
101
102 errmsg := fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Sprintf().("unexpected '%c' at offset %d", exp.expressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#expression.[exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.], exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.)
103 exp.errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err. = errorsscip-go gomod github.com/golang/go/src go1.24 errors/.Newscip-go gomod github.com/golang/go/src go1.24 errors/New().(errmsg)
104 return nil
105 }
106
107 // Read more from expression if the next substring starting at index matches the regex pattern.
108 func (exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#) readRegexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readRegex().(pattern string) string {
109 expressionSlice := exp.expressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#expression.[exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.:]
110
111 r, _ := regexpscip-go gomod github.com/golang/go/src go1.24 regexp/.Compilescip-go gomod github.com/golang/go/src go1.24 regexp/Compile().(pattern)
112 i := r.FindStringIndexscip-go gomod github.com/golang/go/src go1.24 regexp/Regexp#FindStringIndex().(expressionSlice)
113 if i != nil && i[1] > 0 && i[0] == 0 {
114 // match found in expression at index
115 exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index. += i[1]
116 return expressionSlice[0:i[1]]
117 }
118 return ""
119 }
120
121 // Read more from expression if the substring starting at index is the next expected string.
122 func (exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#) readscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#read().(next string) string {
123 expressionSlice := exp.expressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#expression.[exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.:]
124
125 if stringsscip-go gomod github.com/golang/go/src go1.24 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.24 strings/HasPrefix().(expressionSlice, next) {
126 // next found in expression at index
127 exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index. += len(next)
128 return next
129 }
130 return ""
131 }
132
133 // Skip whitespace in expression starting at index
134 func (exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#) skipWhitespacescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#skipWhitespace().() {
135 exp.readRegexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readRegex().("[ ]*")
136 }
137
138 // Read operator in expression starting at index if it exists
139 func (exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#) readOperatorscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readOperator().() *tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# {
140 possibilities := []string{"WITH", "AND", "OR", "(", ")", ":", "+"}
141
142 var op string
143 for _, p := range possibilities {
144 op = exp.readscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#read().(p)
145 if len(op) > 0 {
146 break
147 }
148 }
149 if len(op) == 0 {
150 // not an error if an operator isn't found
151 return nil
152 }
153
154 if op == "+" && exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index. > 1 && exp.expressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#expression.[exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.-2:exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.-1] == " " {
155 exp.errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err. = errorsscip-go gomod github.com/golang/go/src go1.24 errors/.Newscip-go gomod github.com/golang/go/src go1.24 errors/New().("unexpected space before +")
156 exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.--
157 return nil
158 }
159
160 return &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: op}
161 }
162
163 // Get id from expression starting at index. Raise error if id not found.
164 func (exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#) readIDscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readID().() string {
165 id := exp.readRegexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readRegex().("[A-Za-z0-9-.]+")
166 if len(id) == 0 {
167 errmsg := fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Sprintf().("expected id at offset %d", exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.)
168 exp.errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err. = errorsscip-go gomod github.com/golang/go/src go1.24 errors/.Newscip-go gomod github.com/golang/go/src go1.24 errors/New().(errmsg)
169 return ""
170 }
171 return id
172 }
173
174 // Read DocumentRef in expression starting at index if it exists. Raise error if found and id doesn't follow.
175 func (exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#) readDocumentRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readDocumentRef().() *tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# {
176 ref := exp.readscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#read().("DocumentRef-")
177 if len(ref) == 0 {
178 // not an error if a DocumentRef isn't found
179 return nil
180 }
181
182 id := exp.readIDscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readID().()
183 if exp.errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err. != nil {
184 return nil
185 }
186 return &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: documentRefTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/documentRefToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: id}
187 }
188
189 // Read LicenseRef in expression starting at index if it exists. Raise error if found and id doesn't follow.
190 func (exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#) readLicenseRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readLicenseRef().() *tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# {
191 ref := exp.readscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#read().("LicenseRef-")
192 if len(ref) == 0 {
193 // not an error if a LicenseRef isn't found
194 return nil
195 }
196
197 id := exp.readIDscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readID().()
198 if exp.errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err. != nil {
199 return nil
200 }
201 return &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseRefTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseRefToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: id}
202 }
203
204 // Read a LICENSE/EXCEPTION in expression starting at index if it exists. Raise error if found and id doesn't follow.
205 func (exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#) readLicensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readLicense().() *tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# {
206 // because readID matches broadly, save the index so it can be reset if an actual license is not found
207 index := exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.
208
209 license := exp.readIDscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readID().()
210 if exp.errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err. != nil {
211 return nil
212 }
213
214 if token := exp.normalizeLicensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#normalizeLicense().(license); token != nil {
215 return token
216 }
217
218 // license not found in indices, need to reset index since readID advanced it
219 exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index. = index
220 errmsg := fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Sprintf().("unknown license '%s' at offset %d", license, exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.)
221 exp.errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err. = errorsscip-go gomod github.com/golang/go/src go1.24 errors/.Newscip-go gomod github.com/golang/go/src go1.24 errors/New().(errmsg)
222 return nil
223 }
224
225 // Generate a token using the normalized form of the license name.
226 //
227 // License name can be in the form:
228 // - a_license-2.0, a_license, a_license-ab - there is variability in the form of the base license. a_license-2.0 is used for these
229 // examples, but any base license form can have the suffixes described.
230 // - a_license-2.0-only - normalizes to a_license-2.0 if the -only form is not specifically in the set of licenses
231 // - a_license-2.0-or-later - normalizes to a_license-2.0+ if the -or-later form is not specifically in the set of licenses
232 // - a_license-2.0+ - normalizes to a_license-2.0-or-later if the -or-later form is specifically in the set of licenses
233 func (exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#) normalizeLicensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#normalizeLicense().(license string) *tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# {
234 if token := licenseLookupscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseLookup().(license); token != nil {
235 // checks active and exception license lists
236 // deprecated list is checked at the end to avoid a deprecated license being used for +
237 // (example: GPL-1.0 is on the deprecated list, but GPL-1.0+ should become GPL-1.0-or-later)
238 return token
239 }
240
241 lenLicense := len(license)
242 if stringsscip-go gomod github.com/golang/go/src go1.24 strings/.HasSuffixscip-go gomod github.com/golang/go/src go1.24 strings/HasSuffix().(license, "-only") {
243 adjustedLicense := license[0 : lenLicense-5]
244 if token := licenseLookupscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseLookup().(adjustedLicense); token != nil {
245 // no need to remove the -only from the expression stream; it is ignored
246 return token
247 }
248 }
249 if exp.hasMorescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#hasMore().() && exp.expressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#expression.[exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.:exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.+1] == "+" {
250 adjustedLicense := license[0:lenLicense] + "-or-later"
251 if token := licenseLookupscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseLookup().(adjustedLicense); token != nil {
252 // need to consume the + to avoid a + operator token being added
253 exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.++
254 return token
255 }
256 }
257 if stringsscip-go gomod github.com/golang/go/src go1.24 strings/.HasSuffixscip-go gomod github.com/golang/go/src go1.24 strings/HasSuffix().(license, "-or-later") {
258 adjustedLicense := license[0 : lenLicense-9]
259 if token := licenseLookupscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseLookup().(adjustedLicense); token != nil {
260 // replace `-or-later` with `+`
261 newExpression := exp.expressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#expression.[0:exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.-len("-or-later")] + "+"
262 if exp.hasMorescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#hasMore().() {
263 newExpression += exp.expressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#expression.[exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.+1:]
264 }
265 exp.expressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#expression. = newExpression
266 // update index to remove `-or-later`; now pointing at the `+` operator
267 exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index. -= len("-or-later")
268
269 return token
270 }
271 }
272
273 return deprecatedLicenseLookupscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/deprecatedLicenseLookup().(license)
274 }
275
276 // Lookup license identifier in active and exception lists to determine if it is a supported SPDX id
277 func licenseLookupscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseLookup().(license string) *tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# {
278 active, preferredLicense := activeLicensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/activeLicense().(license)
279 if active {
280 return &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: preferredLicense}
281 }
282 exception, preferredLicense := exceptionLicensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/exceptionLicense().(license)
283 if exception {
284 return &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: exceptionTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/exceptionToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: preferredLicense}
285 }
286 return nil
287 }
288
289 // Lookup license identifier in deprecated list to determine if it is a supported SPDX id
290 func deprecatedLicenseLookupscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/deprecatedLicenseLookup().(license string) *tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# {
291 deprecated, preferredLicense := deprecatedLicensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/deprecatedLicense().(license)
292 if deprecated {
293 return &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: preferredLicense}
294 }
295 return nil
296 }