Skip to content

Commit e83100d

Browse files
authored
Merge pull request #8 from Cirru/update
reduce dir; try using syntax
2 parents cb09af3 + 64e42df commit e83100d

File tree

18 files changed

+51
-44
lines changed

18 files changed

+51
-44
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ moon install tiye/cirru-edn
88

99
import it as `edn`:
1010

11+
```js
12+
"import": [{ "path": "tiye/cirru-edn", "alias": "edn" }],
13+
```
14+
1115
```moonbit
12-
typealias @edn.Edn
13-
match Edn::parse?(demo) {
16+
using @edn {type Edn}
17+
match (try? Edn::parse(demo)) {
1418
Ok(x) => {
1519
println(x.to_string())
1620
println(x.format?(use_inline=false).unwrap())
@@ -22,7 +26,7 @@ match Edn::parse?(demo) {
2226
Or parse with `@strconv.parse!`:
2327

2428
```moonbit
25-
let parsed : Edn = @strconv.parse!("atom 1")
29+
let parsed : Edn = try! @strconv.from_str("atom 1")
2630
2731
parsed.format?(use_inline=false).unwrap() // "atom 1"
2832
```

moon.mod.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "tiye/cirru-edn",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"deps": {
5-
"tiye/cirru-parser": "0.1.1"
5+
"tiye/cirru-parser": "0.2.0"
66
},
77
"readme": "README.md",
88
"repository": "https://github.com/Cirru/cirru-edn.mbt",
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/edn_test.mbt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
///|
2+
test "atom inside edn" {
3+
let edn = @cirru_edn.Edn::Atom(Number(1.0))
4+
assert_eq(edn.format(use_inline=true).trim(char_set="\n"), "atom 1")
5+
let parsed : Edn = @strconv.from_str("atom 1")
6+
assert_eq(parsed, @cirru_edn.Atom(Number(1.0)))
7+
}

src/lib/lib.mbt renamed to src/lib.mbt

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
///|
2-
typealias @cirru_parser.Cirru
2+
using @cirru_parser {type Cirru}
33

44
///|
55
pub(all) suberror EdnCommonError String derive(Eq, Hash, Default, Show)
66

77
///|
8-
pub impl @strconv.FromStr for Edn with from_string(s) {
9-
Edn::parse(s)
8+
pub impl @strconv.FromStr for Edn with from_str(s) {
9+
Edn::parse(s.to_string())
1010
}
1111

1212
///|
@@ -39,11 +39,12 @@ fn extract_cirru_edn(
3939
"" => raise @strconv.StrConvError("empty string is invalid for edn")
4040
s1 =>
4141
match s1.get_char(0).unwrap() {
42-
'\'' => Symbol(s1.substring(start=1))
43-
':' => Tag(s1.substring(start=1))
44-
'"' | '|' => Str(s1.substring(start=1))
42+
'\'' => Symbol(try! s1[1:].to_string())
43+
':' => Tag(try! s1[1:].to_string())
44+
'"' | '|' => Str(try! s1[1:].to_string())
4545
_ =>
46-
match (try? @strconv.parse_double(s1.trim(" ").to_string())) {
46+
match
47+
(try? @strconv.parse_double(s1.trim(char_set=" ").to_string())) {
4748
Ok(f) => Number(f)
4849
Err(e) =>
4950
match e {
@@ -176,7 +177,8 @@ fn extract_cirru_edn(
176177
"%{}" =>
177178
if xs.length() >= 3 {
178179
let name = match xs[1] {
179-
Leaf(s) => EdnTag::new(s.trim_start(":").to_string())
180+
Leaf(s) =>
181+
EdnTag::new(s.trim_start(char_set=":").to_string())
180182
List(e) =>
181183
raise @strconv.StrConvError(
182184
"expected record name in string: " + e.to_string(),
@@ -197,7 +199,12 @@ fn extract_cirru_edn(
197199
match (ys[0], try? extract_cirru_edn(ys[1])) {
198200
(Leaf(s), Ok(v)) =>
199201
entries.push(
200-
(EdnTag::new(s.trim_start(":").to_string()), v),
202+
(
203+
EdnTag::new(
204+
s.trim_start(char_set=":").to_string(),
205+
),
206+
v,
207+
),
201208
)
202209
(Leaf(s), Err(e)) =>
203210
raise @strconv.StrConvError(
@@ -378,14 +385,11 @@ fn assemble_cirru_node(data : Edn) -> @cirru_parser.Cirru raise EdnCommonError {
378385
/// generate Cirru code from Edn
379386
pub fn Edn::format(
380387
data : Self,
381-
use_inline? : Bool,
388+
use_inline? : Bool = false,
382389
) -> String raise EdnCommonError {
383-
let options : @cirru_parser.CirruWriterOptions = {
384-
use_inline: use_inline.unwrap_or(false),
385-
}
386390
let ret = match assemble_cirru_node(data) {
387-
Leaf(s) => try? Cirru::format([List([Leaf("do"), Leaf(s)])], options)
388-
List(xs) => try? Cirru::format([List(xs)], options)
391+
Leaf(s) => try? Cirru::format([List([Leaf("do"), Leaf(s)])], use_inline~)
392+
List(xs) => try? Cirru::format([List(xs)], use_inline~)
389393
}
390394
match ret {
391395
Ok(s) => s

src/lib/edn_test.mbt

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/lib/moon.pkg.json

Lines changed: 0 additions & 3 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)