Skip to content

Commit 951e1eb

Browse files
authored
Merge pull request #14 from Cirru/update
reduce dir; try using syntax
2 parents 98e6cfc + 989dcb7 commit 951e1eb

File tree

12 files changed

+63
-37
lines changed

12 files changed

+63
-37
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,23 @@ Docs: https://mooncakes.io/docs/#/tiye/cirru-parser/lib/members
66
moon add tiye/cirru-parser
77
```
88

9+
import in `moon.pkg.json`:
10+
11+
```js
12+
{
13+
"path": "tiye/cirru-parser",
14+
"alias": "cirru_parser"
15+
}
16+
```
17+
918
```moonbit
10-
typealias @cirru_parser.Cirru
19+
using @cirru_parser {type Cirru}
1120
1221
// parse Cirru code
13-
Cirru::parse(code: String) : Array[Cirru]!CirruParseError
22+
Cirru::parse(code: String) : Array[Cirru] raise CirruParseError
1423
1524
// format Cirru code
16-
Cirru::format(cirru: Array[Cirru], {use_inline: false}) : String!FormatCirruError
25+
Cirru::format(cirru: Array[Cirru], use_inline=false) : String raise FormatCirruError
1726
```
1827

1928
### License

moon.mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tiye/cirru-parser",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"deps": {},
55
"readme": "README.md",
66
"repository": "https://github.com/Cirru/parser.mbt",

src/lib/moon.pkg.json

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

src/main/main.mbt

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

44
///|
55
pub fn main_parser() -> Unit {
@@ -38,7 +38,7 @@ pub fn main_writer() -> Unit {
3838
for item in tree {
3939
println(item.to_json().stringify())
4040
}
41-
let ret = (try? Cirru::format(tree, { use_inline: false })).unwrap()
41+
let ret = (try? Cirru::format(tree, use_inline=false)).unwrap()
4242
println("Generated:")
4343
println(ret)
4444
println("Expected:")

src/main/moon.pkg.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"is-main": true,
3-
"import": ["tiye/cirru-parser/lib"],
3+
"import": [
4+
{
5+
"path": "tiye/cirru-parser",
6+
"alias": "lib"
7+
}
8+
],
49
"test-import": []
510
}

src/moon.pkg.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"import": [],
3+
"test-import": [
4+
{
5+
"path": "tiye/cirru-parser",
6+
"alias": "lib"
7+
}
8+
]
9+
}
File renamed without changes.
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///|
2-
typealias @lib.Cirru
2+
using @lib {type Cirru}
33

44
///|
55
test "parser" {
@@ -20,9 +20,7 @@ test "existed demos" {
2020
let defined = (try? @json.parse(json_file)).unwrap()
2121
let defined_str = defined.stringify()
2222
assert_eq(tree, defined_str)
23-
let formatted = Cirru::format(@json.from_json(defined), {
24-
use_inline: false,
25-
})
23+
let formatted = Cirru::format(@json.from_json(defined), use_inline=false)
2624
let ret = (try? Cirru::parse(formatted)).unwrap().to_json().stringify()
2725
assert_eq(ret, defined_str)
2826
}
File renamed without changes.
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn format_to_lisp(xs : Array[Cirru]) -> String raise FormatError {
1414
///|
1515
/// format single expression to Lisp-like code
1616
fn format_lispy_expr(self : Cirru, indent : Int) -> String raise FormatError {
17-
let emptySpace = " "
17+
let empty_space = " "
1818
match self {
1919
List(xs) =>
2020
if xs.length() > 0 && xs[0].is_comment() {
@@ -26,17 +26,17 @@ fn format_lispy_expr(self : Cirru, indent : Int) -> String raise FormatError {
2626
}
2727

2828
// chunk = format!("{}{}", chunk.trim_end(), gen_newline(indent));
29-
chunk = "\{chunk.trim_end(emptySpace)}\{gen_newline(indent)}"
29+
chunk = "\{chunk.trim_end(char_set=empty_space)}\{gen_newline(indent)}"
3030
chunk
3131
} else {
3232
let mut chunk = "("
3333
for idx, x in xs {
3434
if x.is_nested() {
35-
chunk = "\{chunk.trim_end(emptySpace)}\{gen_newline(indent + 1)}"
35+
chunk = "\{chunk.trim_end(char_set=empty_space)}\{gen_newline(indent + 1)}"
3636
}
3737
let next = x.format_lispy_expr(indent + 1)
3838
if next.has_prefix("\n") {
39-
chunk = "\{chunk.trim_end(emptySpace)}\{next}"
39+
chunk = "\{chunk.trim_end(char_set=empty_space)}\{next}"
4040
} else {
4141
chunk = "\{chunk}\{next}"
4242
}
@@ -53,7 +53,8 @@ fn format_lispy_expr(self : Cirru, indent : Int) -> String raise FormatError {
5353
} else {
5454
let s0 = token[0]
5555
if s0 == '|' || s0 == '"' {
56-
"\"" + escape_string(token.substring(start=1)) + "\""
56+
let sliced = (try? token[1:]).unwrap().to_string()
57+
"\"" + escape_string(sliced) + "\""
5758
} else if token.contains(" ") ||
5859
token.contains("\n") ||
5960
token.contains("\"") {

0 commit comments

Comments
 (0)