Skip to content

Commit bb023b1

Browse files
committed
🚧 WIP on replace-first algorithm - usr more non-capturing groups
1 parent 7294c19 commit bb023b1

File tree

7 files changed

+13
-11
lines changed

7 files changed

+13
-11
lines changed

src/lice_comb/impl/substitutions/bsd.clj

+3-4
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@
257257
#"(?<afterSystemics>Systemics(?<afterW3works>[\s\-–—]+W3Works)?)"
258258
#"(?<afterAMPAS>AMPAS|Academy[\s\-–—]+of[\s\-–—]+Motion[\s\-–—]+Picture[\s\-–—]+Arts[\s\-–—]+(?:and|&)[\s\-–—]+Sciences)"))
259259

260-
(def re (re/join #"(?iuUx)(?<!\w)(The[\s\-–—]+)?" ; Only public for ease of testing
260+
(def re (re/join #"(?iuUx)(?<!\w)(?:The[\s\-–—]+)?" ; Only public for ease of testing
261261
"\n\n#### Prefix ####\n"
262262
(re/opt-grp (re-prefix-clauses) lcir/fre-mws)
263263
"\n\n#### Leading clause ####\n"
@@ -266,20 +266,19 @@
266266
(re/opt (re/alt-grp (re/ncg "beforeFreeBSD" "Free")
267267
(re/ncg "beforeNetBSD" "Net")))
268268
"BSD"
269-
(re/opt-grp #"[\s\-–—]*(style|like)")
269+
(re/opt-grp #"[\s\-–—]*(?:style|like)")
270270
"\n\n#### Trailing clause ####\n"
271271
(re/opt-grp lcir/fre-mws (re-bsd-any-clause "after"))
272272
"\n\n#### Suffix ####\n"
273273
(re/opt-grp lcir/fre-mws (re-suffix-clauses))
274274
"\n\n#### Random dingleberries ####\n"
275-
(re/zom-grp lcir/fre-mws #"(variant|(Pub?lic[\s\-–—]+)?licen[cs]e)")
275+
(re/zom-grp lcir/fre-mws #"(?:variant|(?:Pub?lic[\s\-–—]+)?licen[cs]e)")
276276
(re/opt-grp lcir/fre-version)
277277
"\n\n#### Coda ####\n"
278278
#"(?!\w)"))
279279

280280
(def ^:private pairs-d (delay (concat [
281281
[re match->ei]])))
282-
; (lcisu/spdx-match-pairs @ids-d)))) ;####TODO: confirm generic name/id matching is redundant for BSD
283282

284283
(defn sub
285284
"Substitutes any BSD licenses found in the strings in `coll` with an

src/lice_comb/impl/substitutions/cc.clj

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
without notice."
1616
(:require [clojure.string :as s]
1717
[clojure.set :as set]
18+
[wreck.api :as re]
19+
[spdx.licenses :as sl]
20+
[spdx.expressions :as sexp]
1821
[lice-comb.impl.spdx :as lcis]
22+
[lice-comb.impl.regexes :as lcir]
1923
[lice-comb.impl.utils :as lciu]
20-
[lice-comb.impl.parsing-utils :as lcipu]
2124
[lice-comb.impl.substitutions.utils :as lcisu]))
2225

2326
;####TODO: IMPLEMENT ME!!!!

src/lice_comb/impl/substitutions/cpe.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
(def ^:private pairs-d (delay (concat
2424
(lcisu/spdx-match-pairs @ids-d) ; Generic license regexes handle most cases, except...
25-
[[(re/join #"(?iuU)(GNU[\s\-–—]*)?(?:CPE|Classpath[\s\-–—]+exception)") ; ...when no version is provided (and note that exceptions can't have "only", "+", "or later", etc.)
25+
[[(re/join #"(?iuU)(?:GNU[\s\-–—]*)?(?:CPE|Classpath[\s\-–—]+exception)") ; ...when no version is provided (and note that exceptions can't have "only", "+", "or later", etc.)
2626
(fn [m]
2727
{:id "Classpath-exception-2.0"
2828
:type :concluded

src/lice_comb/impl/substitutions/custom.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
(def ^:private pairs-d (delay [
2323
; Proprietary / commercial
24-
[#"(?i)(?<!\w)(Propriet[aoe]ry|Commercial|(Copyright\s+.{0,20})?All[\s\-–—]+Rights[\s\-–—]+Reserved|Private)([\s\-–—]+Licen?[cs]e)?[\s\-–—\.]*(?!\w)" ; We consume - and . so that replacement doesn't leave them in and cause problems later on
24+
[#"(?i)(?<!\w)(?:Propriet[aoe]ry|Commercial|(?:Copyright\s+.{0,20})?All[\s\-–—]+Rights[\s\-–—]+Reserved|Private)(?:[\s\-–—]+Licen?[cs]e)?[\s\-–—\.]*(?!\w)" ; We consume - and . so that replacement doesn't leave them in and cause problems later on
2525
(fn [m]
2626
{:id (lcis/proprietary-commercial)
2727
:type :concluded

src/lice_comb/impl/substitutions/gnu.clj

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
[id confidence confidence-explanations]
107107
[(str variant "-" default-version "-or-later") ; Note: on the advice of SPDX technical team, default to "or later" variant if version not valid
108108
:low
109-
(set/union #{:invalid-version-for-variant} confidence-explanations)])]
109+
(set/union #{:invalid-version} confidence-explanations)])]
110110
(merge {:id (lcisu/assert-listed-id id)
111111
:type :concluded
112112
:confidence confidence
@@ -161,7 +161,7 @@
161161
"\n\n#### Leading word salad ####\n"
162162
(re/zom-grp fre-gpl-words lcir/fre-mws)
163163
"\n\n#### Matching words ####\n"
164-
(re/ncg "gpl" #"(?:GNU|GPL|(Genere?al(?:[\s\-–—]+Pub?lic)?([\s\-–—]+Licen[cs]e)?))")
164+
(re/ncg "gpl" #"(?:GNU|GPL|(?:Genere?al(?:[\s\-–—]+Pub?lic)?(?:[\s\-–—]+Licen[cs]e)?))")
165165
"\n\n#### Trailing word salad ####\n"
166166
(re/zom-grp lcir/fre-mws fre-gpl-words)
167167
"\n\n#### Version and version qualifier ####\n"

src/lice_comb/impl/substitutions/hippocratic.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
(def ^:private pairs-d (delay (concat
2525
(lcisu/spdx-match-pairs @ids-d) ; Generic license regexes handle most cases, except...
26-
[[(re/join #"(?iuU)Hippocratic([\s\-–—]+Licen?[cs]e)?" (re/opt-grp lcir/fre-ows lcir/fre-only-or-later)) ; ...when no version is provided
26+
[[(re/join #"(?iuU)Hippocratic(?:[\s\-–—]+Licen?[cs]e)?" (re/opt-grp lcir/fre-ows lcir/fre-only-or-later)) ; ...when no version is provided
2727
(fn [m]
2828
{:id (str "Hippocratic-2.1" (when (get m "orLater") "+"))
2929
:type :concluded

src/lice_comb/impl/substitutions/mpl.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
(def ^:private pairs-d (delay (concat
2525
(lcisu/spdx-match-pairs @ids-d) ; Generic license regexes handle most cases, except...
26-
[[(re/join #"(?iuU)(?:MPL|Mozilla([\s\-–—]+Public)?([\s\-–—]+Licen?[cs]e)?)" (re/opt-grp lcir/fre-ows lcir/fre-only-or-later)) ; ...when no version is provided
26+
[[(re/join #"(?iuU)(?:MPL|Mozilla(?:[\s\-–—]+Public)?(?:[\s\-–—]+Licen?[cs]e)?)" (re/opt-grp lcir/fre-ows lcir/fre-only-or-later)) ; ...when no version is provided
2727
(fn [m]
2828
{:id (str "MPL-2.0" (when (get m "orLater") "+"))
2929
:type :concluded

0 commit comments

Comments
 (0)