Skip to content

Commit 4ac95a1

Browse files
committed
🚧 WIP on replace-first algorithm - GNU family
1 parent 5cd9a2d commit 4ac95a1

File tree

1 file changed

+19
-9
lines changed
  • src/lice_comb/impl/substitutions

1 file changed

+19
-9
lines changed

src/lice_comb/impl/substitutions/gnu.clj

+19-9
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
(s/ends-with? id "-only") :only
5252
(or (s/ends-with? id "+") (s/ends-with? id "-or-later")) :or-later)))
5353

54+
;####TODO: REMOVE THIS IF STANDARD REGEX MATCHING ISN'T NEEDED
55+
(comment
5456
(defn- gnu-id-comparator
5557
"Compares GNU family ids, by putting the `-only` variants first. This order
5658
is important as there are certain license name values that both the -only and
@@ -68,14 +70,16 @@
6870
[:or-later :only] 1
6971
[:or-later :or-later] 0) ; This can occur due to +/-or-later being equivalent
7072
(compare id1 id2))))
73+
)
7174

7275
; All GNU family license ids, including deprecated ones - we report that we match all GPL ids so that they're removed from lice-comb.impl.substitutions.others matching
7376
(def ids-d (delay (set (filter #(or (lcisu/agpl-license? %) (lcisu/lgpl-license? %) (lcisu/gpl-license? %)) (map :id @lcis/full-license-list-d)))))
7477

78+
;####TODO: REMOVE THIS IF STANDARD REGEX MATCHING ISN'T NEEDED
7579
; Undeprecated GNU family license ids (these ones are used for matching)
76-
(def ^:private agpl-license-ids-d (delay (sort gnu-id-comparator (map :id (filter #(and (lcisu/agpl-license? (:id %)) (not (:deprecated? %))) @lcis/full-license-list-d)))))
77-
(def ^:private lgpl-license-ids-d (delay (sort gnu-id-comparator (map :id (filter #(and (lcisu/lgpl-license? (:id %)) (not (:deprecated? %))) @lcis/full-license-list-d)))))
78-
(def ^:private gpl-license-ids-d (delay (sort gnu-id-comparator (map :id (filter #(and (lcisu/gpl-license? (:id %)) (not (:deprecated? %))) @lcis/full-license-list-d)))))
80+
;(def ^:private agpl-license-ids-d (delay (sort gnu-id-comparator (map :id (filter #(and (lcisu/agpl-license? (:id %)) (not (:deprecated? %))) @lcis/full-license-list-d)))))
81+
;(def ^:private lgpl-license-ids-d (delay (sort gnu-id-comparator (map :id (filter #(and (lcisu/lgpl-license? (:id %)) (not (:deprecated? %))) @lcis/full-license-list-d)))))
82+
;(def ^:private gpl-license-ids-d (delay (sort gnu-id-comparator (map :id (filter #(and (lcisu/gpl-license? (:id %)) (not (:deprecated? %))) @lcis/full-license-list-d)))))
7983

8084
(defn- match->ei
8185
"Construct an expression-info map from `m`, a map returned from a rencg regex
@@ -118,25 +122,27 @@
118122
(def ^:private gnu-words [#"\(?The" #"GNU" #"GPL" #"Genere?al" #"Pub?lic" #"Licen[cs]ed?(?:[\s\-–—]+Under)?" #"Open[\s\-–—]+Source" #"FOSS" #"OSS"])
119123

120124
; AGPL regexes
121-
(def ^:private fre-agpl-words (re/grp (apply re/alt (concat gnu-words ["AGPL" "Affero"]))))
125+
(def ^:private fre-agpl-words (re/grp (apply re/alt (concat gnu-words [#"\(?AGPL[\s\-–—v\d\.]*\)?" "Affero"]))))
122126
(def re-agpl (re/join #"(?iuUx)(?<!\w)" ; Only public for ease of testing
123127
"\n\n#### Leading word salad ####\n"
124128
(re/zom-grp fre-agpl-words lcir/fre-mws)
125129
"\n\n#### Matching words ####\n"
126130
(re/ncg "agpl" #"(?:A\s?GPL|Affero)")
127-
"\n\n#### Trailing word salad ####\n"
131+
"\n\n#### Pre-version word salad ####\n"
128132
(re/zom-grp lcir/fre-mws fre-agpl-words)
129133
"\n\n#### Version and version qualifier ####\n"
130134
(re/opt-grp lcir/fre-ows lcir/fre-version)
131135
(re/opt-grp lcir/fre-ows lcir/fre-only-or-later)
136+
"\n\n#### Post-version word salad ####\n"
137+
(re/zom-grp lcir/fre-mws fre-agpl-words)
132138
"\n\n#### Date ####\n"
133139
(re/opt-grp lcir/fre-mws lcir/fre-date)
134140
"\n\n#### Coda ####\n"
135141
#"(?!\w)"))
136142

137143
; LGPL regexes
138144
(def ^:private fre-lesser-or-library (re/or-grp "Lesser" "Library" (re/join lcir/fre-mws "or" lcir/fre-mws)))
139-
(def ^:private fre-lgpl-words (re/grp (apply re/alt (concat gnu-words ["LGPL" fre-lesser-or-library]))))
145+
(def ^:private fre-lgpl-words (re/grp (apply re/alt (concat gnu-words [#"\(?LGPL[\s\-–—v\d\.]*\)?" fre-lesser-or-library]))))
140146
(def re-lgpl (re/join #"(?iuUx)(?<!\w)" ; Only public for ease of testing
141147
"\n\n#### Leading word salad ####\n"
142148
(re/zom-grp fre-lgpl-words lcir/fre-mws)
@@ -145,28 +151,32 @@
145151
(re/alt #"L\s*GPL"
146152
(re/join #"(?:GNU|GPL)" lcir/fre-mws fre-lesser-or-library)
147153
(re/join fre-lesser-or-library lcir/fre-mws #"(?:GNU|GPL|General)")))
148-
"\n\n#### Trailing word salad ####\n"
154+
"\n\n#### Pre-version word salad ####\n"
149155
(re/zom-grp lcir/fre-mws fre-lgpl-words)
150156
"\n\n#### Version and version qualifier ####\n"
151157
(re/opt-grp lcir/fre-ows lcir/fre-version)
152158
(re/opt-grp lcir/fre-ows lcir/fre-only-or-later)
159+
"\n\n#### Post-version word salad ####\n"
160+
(re/zom-grp lcir/fre-mws fre-lgpl-words)
153161
"\n\n#### Date ####\n"
154162
(re/opt-grp lcir/fre-mws lcir/fre-date)
155163
"\n\n#### Coda ####\n"
156164
#"(?!\w)"))
157165

158166
; GPL regexes
159-
(def ^:private fre-gpl-words (re/grp (apply re/alt gnu-words))) ; GPL has no extra words
167+
(def ^:private fre-gpl-words (re/grp (apply re/alt (concat gnu-words [#"\(?GPL[\s\-–—v\d\.]*\)?"]))))
160168
(def re-gpl (re/join #"(?iuUx)(?<!\w)" ; Only public for ease of testing
161169
"\n\n#### Leading word salad ####\n"
162170
(re/zom-grp fre-gpl-words lcir/fre-mws)
163171
"\n\n#### Matching words ####\n"
164172
(re/ncg "gpl" #"(?:GNU|GPL|(?:Genere?al(?:[\s\-–—]+Pub?lic)?(?:[\s\-–—]+Licen[cs]e)?))")
165-
"\n\n#### Trailing word salad ####\n"
173+
"\n\n#### Pre-version word salad ####\n"
166174
(re/zom-grp lcir/fre-mws fre-gpl-words)
167175
"\n\n#### Version and version qualifier ####\n"
168176
(re/opt-grp lcir/fre-ows lcir/fre-version)
169177
(re/opt-grp lcir/fre-ows lcir/fre-only-or-later)
178+
"\n\n#### Post-version word salad ####\n"
179+
(re/zom-grp lcir/fre-mws fre-gpl-words)
170180
"\n\n#### Date ####\n"
171181
(re/opt-grp lcir/fre-mws lcir/fre-date)
172182
"\n\n#### Coda ####\n"

0 commit comments

Comments
 (0)