Skip to content

Commit f066a4e

Browse files
committed
upgrade edn
1 parent 56f5b9b commit f066a4e

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ crate-type = ["dylib"] # Creates dynamic lib
1313
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1414

1515
[dependencies]
16-
cirru_edn = "0.6.4-a2"
16+
cirru_edn = "0.6.4-a3"
1717
# cirru_edn = { path = "/Users/chenyong/repo/cirru/edn.rs" }
1818
cirru_parser = "0.1.29"
1919
regex = "1.10.4"

calcit.cirru

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

compact.cirru

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
:files $ {}
77
|regex.core $ %{} :FileEntry
88
:defs $ {}
9+
|re-drop $ %{} :CodeEntry (:doc |)
10+
:code $ quote
11+
defn re-drop (pattern)
12+
&call-dylib-edn (get-dylib-path "\"/dylibs/libcalcit_regex") "\"re_drop" pattern
913
|re-find $ %{} :CodeEntry (:doc |)
1014
:code $ quote
1115
defn re-find (s pattern)

src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::sync::Arc;
1+
use std::{cell::RefCell, sync::Arc};
22

33
use cirru_edn::{Edn, EdnAnyRef, EdnListView};
44
use regex::Regex;
@@ -14,7 +14,7 @@ pub fn re_pattern(args: Vec<Edn>) -> Result<Edn, String> {
1414
match &args[0] {
1515
Edn::Str(s) => match Regex::new(s) {
1616
Ok(pattern) => {
17-
let p = Arc::from(pattern);
17+
let p = Arc::from(RefCell::new(pattern));
1818
let p2 = p.to_owned();
1919
std::mem::forget(p);
2020
Ok(Edn::AnyRef(EdnAnyRef(p2)))
@@ -37,7 +37,7 @@ pub fn re_matches(args: Vec<Edn>) -> Result<Edn, String> {
3737
Err(e) => Err(format!("re-matches failed, {}", e)),
3838
},
3939
(Edn::Str(s), Edn::AnyRef(EdnAnyRef(p))) => {
40-
if let Some(pattern) = p.downcast_ref::<Regex>() {
40+
if let Some(pattern) = p.borrow().downcast_ref::<Regex>() {
4141
Ok(Edn::Bool(pattern.is_match(s)))
4242
} else {
4343
Err(format!("re-matches expected a regex, got {:?}", p))
@@ -64,7 +64,7 @@ pub fn re_find_index(args: Vec<Edn>) -> Result<Edn, String> {
6464
}
6565
}
6666
(Edn::Str(s), Edn::AnyRef(EdnAnyRef(p))) => {
67-
if let Some(pattern) = p.downcast_ref::<Regex>() {
67+
if let Some(pattern) = p.borrow().downcast_ref::<Regex>() {
6868
match pattern.find(s) {
6969
Some(matched) => Ok(Edn::Number(matched.start() as f64)),
7070
None => Ok(Edn::Number(-1.0)), // TODO maybe nil
@@ -98,7 +98,7 @@ pub fn re_find(args: Vec<Edn>) -> Result<Edn, String> {
9898
}
9999
}
100100
(Edn::Str(s), Edn::AnyRef(EdnAnyRef(p))) => {
101-
if let Some(pattern) = p.downcast_ref::<Regex>() {
101+
if let Some(pattern) = p.borrow().downcast_ref::<Regex>() {
102102
let mut matched = pattern.find_iter(s);
103103
match matched.next() {
104104
Some(v) => Ok(Edn::str(v.as_str().to_string())),
@@ -130,7 +130,7 @@ pub fn re_find_all(args: Vec<Edn>) -> Result<Edn, String> {
130130
Err(e) => Err(format!("re-find-all failed, {}", e)),
131131
},
132132
(Edn::Str(s), Edn::AnyRef(EdnAnyRef(p))) => {
133-
if let Some(pattern) = p.downcast_ref::<Regex>() {
133+
if let Some(pattern) = p.borrow().downcast_ref::<Regex>() {
134134
let mut ys: Vec<Edn> = vec![];
135135
for v in pattern.find_iter(s) {
136136
ys.push(Edn::Str(v.as_str().to_string().into()))
@@ -162,7 +162,7 @@ pub fn re_split(args: Vec<Edn>) -> Result<Edn, String> {
162162
Err(e) => Err(format!("re-split failed, {}", e)),
163163
},
164164
(Edn::Str(s), Edn::AnyRef(EdnAnyRef(p))) => {
165-
if let Some(pattern) = p.downcast_ref::<Regex>() {
165+
if let Some(pattern) = p.borrow().downcast_ref::<Regex>() {
166166
let mut ys: Vec<Edn> = vec![];
167167
for piece in pattern.split(s) {
168168
ys.push(Edn::str(piece));
@@ -188,7 +188,7 @@ pub fn re_replace_all(args: Vec<Edn>) -> Result<Edn, String> {
188188
Err(e) => Err(format!("re-replace-all failed, {}", e)),
189189
},
190190
(Edn::Str(s), Edn::AnyRef(EdnAnyRef(p)), Edn::Str(next)) => {
191-
if let Some(pattern) = p.downcast_ref::<Regex>() {
191+
if let Some(pattern) = p.borrow().downcast_ref::<Regex>() {
192192
Ok(Edn::str(pattern.replace_all(s, &**next).into_owned()))
193193
} else {
194194
Err(format!("re-replace-all expected a regex, got {:?}", p))

0 commit comments

Comments
 (0)