Skip to content

Commit 677cd59

Browse files
committed
experiment on "no drop"
1 parent 76fb390 commit 677cd59

File tree

3 files changed

+4
-80
lines changed

3 files changed

+4
-80
lines changed

calcit.cirru

Lines changed: 0 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compact.cirru

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,17 @@
6363
println "\"%%% test variable holding regex"
6464
let
6565
pattern $ re-pattern "\"\\d+"
66-
p2 $ re-pattern "\"\\w+"
6766
println "\"Pattern is:" pattern
6867
assert= true $ re-matches |2 pattern
6968
assert= true $ re-matches |23 pattern
7069
assert= false $ re-matches |qq pattern
7170
assert= "\"22" $ re-find |q22 pattern
7271
assert= ([] |1 |2 |3) (re-find-all |1q2q3 pattern)
7372
assert= |XabXcX $ re-replace-all |1ab22c333 pattern "\"X"
74-
w-log $ re-drop p2
75-
w-log $ re-drop pattern
76-
w-log $ re-drop pattern
7773
:ns $ %{} :CodeEntry (:doc |)
7874
:code $ quote
7975
ns regex.test $ :require
80-
regex.core :refer $ re-matches re-find-index re-find re-find-all re-split re-replace-all re-pattern re-drop
76+
regex.core :refer $ re-matches re-find-index re-find re-find-all re-split re-replace-all re-pattern
8177
regex.$meta :refer $ calcit-dirname calcit-filename
8278
|regex.util $ %{} :FileEntry
8379
:defs $ {}

src/lib.rs

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
use std::{
2-
cell::RefCell,
3-
sync::{Arc, Mutex},
4-
};
1+
use std::{cell::RefCell, sync::Arc};
52

63
use cirru_edn::{Edn, EdnAnyRef, EdnListView};
7-
use lazy_static::lazy_static;
84
use regex::Regex;
95

10-
lazy_static! {
11-
static ref PATTERNS: Mutex<Vec<EdnAnyRef>> = Mutex::from(vec![]);
12-
}
13-
146
#[no_mangle]
157
pub fn abi_version() -> String {
168
String::from("0.0.8")
@@ -23,11 +15,8 @@ pub fn re_pattern(args: Vec<Edn>) -> Result<Edn, String> {
2315
Edn::Str(s) => match Regex::new(s) {
2416
Ok(pattern) => {
2517
let p = Arc::from(RefCell::new(pattern));
26-
// push to PATTERNS
27-
let v = EdnAnyRef(p);
28-
let mut patterns = PATTERNS.lock().unwrap();
29-
patterns.push(v.to_owned());
30-
Ok(Edn::AnyRef(v))
18+
19+
Ok(Edn::AnyRef(EdnAnyRef(p)))
3120
}
3221
Err(e) => Err(format!("re-pattern failed, {}", e)),
3322
},
@@ -38,38 +27,6 @@ pub fn re_pattern(args: Vec<Edn>) -> Result<Edn, String> {
3827
}
3928
}
4029

41-
/// re_drop drops pattern from global PATTERNS
42-
#[no_mangle]
43-
pub fn re_drop(args: Vec<Edn>) -> Result<Edn, String> {
44-
if args.len() == 1 {
45-
match &args[0] {
46-
Edn::AnyRef(p) => {
47-
let mut patterns = PATTERNS.lock().unwrap();
48-
let mut i = 0;
49-
let mut found = false;
50-
println!("patterns size {}", patterns.len());
51-
for v in patterns.iter() {
52-
if v == p {
53-
found = true;
54-
break;
55-
}
56-
i += 1;
57-
}
58-
println!("re-drop found {} at {}\n", found, i);
59-
if found {
60-
patterns.remove(i);
61-
Ok(Edn::from(true))
62-
} else {
63-
Ok(Edn::from(false))
64-
}
65-
}
66-
_ => Err(format!("re-drop expect 1 pattern, got {:?}", args)),
67-
}
68-
} else {
69-
Err(format!("re-drop expect 1 pattern, got {:?}", args))
70-
}
71-
}
72-
7330
#[no_mangle]
7431
pub fn re_matches(args: Vec<Edn>) -> Result<Edn, String> {
7532
if args.len() == 2 {

0 commit comments

Comments
 (0)