Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion moon.mod.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "tiye/cirru-parser",
"version": "0.1.0",
"version": "0.1.1",
"deps": {},
"readme": "README.md",
"repository": "https://github.com/Cirru/parser.mbt",
"license": "Apache-2.0",
"keywords": ["Cirru"],
"source": "src",
"preferred-target": "js",
"description": "parser for Cirru Syntax"
}
6 changes: 3 additions & 3 deletions src/lib/parser_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ test "existed demos" {
for demo in demos {
let demo_file = fsReadSync("./test/cirru/\{demo}.cirru")
let json_file = fsReadSync("./test/data/\{demo}.json")
let tree = Cirru::parse?(demo_file).unwrap().to_json().stringify()
let defined = @json.parse?(json_file).unwrap()
let tree = (try? Cirru::parse(demo_file)).unwrap().to_json().stringify()
let defined = (try? @json.parse(json_file)).unwrap()
let defined_str = defined.stringify()
assert_eq(tree, defined_str)
let formatted = Cirru::format(@json.from_json(defined), {
use_inline: false,
})
let ret = Cirru::parse?(formatted).unwrap().to_json().stringify()
let ret = (try? Cirru::parse(formatted)).unwrap().to_json().stringify()
assert_eq(ret, defined_str)
}
}
Expand Down
15 changes: 5 additions & 10 deletions src/lib/primes.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ pub impl @json.FromJson for Cirru with from_json(json, path) {
}
}

///|
impl Default for Cirru with default() -> Cirru {
List(Array::new())
}

///|
pub impl Show for Cirru with output(self : Cirru, logger : &Logger) -> Unit {
match self {
Expand Down Expand Up @@ -98,7 +93,7 @@ pub impl Compare for Cirru with compare(self, other) -> Int {
match (self, other) {
(Leaf(a), Leaf(b)) => a.compare(b)
(List(xs), List(ys)) => {
let size = @math.minimum(xs.length(), ys.length())
let size = @cmp.minimum(xs.length(), ys.length())
for i = 0; i < size; i = i + 1 {
let x = xs[i]
let y = ys[i]
Expand Down Expand Up @@ -149,7 +144,7 @@ pub fn Cirru::is_nested(self : Cirru) -> Bool {
///|
pub fn Cirru::is_comment(self : Cirru) -> Bool {
match self {
Leaf(s) => s.char_at(0) == ';'
Leaf(s) => s.length() > 0 && s[0] == ';'
_ => false
}
}
Expand All @@ -167,7 +162,7 @@ priv enum CirruLexState {
Indent
/// Working on a string
Str
} derive(Show)
}

///|
/// lexer is a simpler state machine to tokenize Cirru code
Expand Down Expand Up @@ -201,7 +196,7 @@ fn CirruLexItem::is_normal_str(tok : String) -> Bool {
}
let mut i = 0
while i < size {
let c = tok.char_at(i)
let c = tok[i]
match c {
'A'..='Z' => ()
'a'..='z' => ()
Expand Down Expand Up @@ -239,7 +234,7 @@ fn escape_cirru_leaf(s : String) -> String {
let size = s.length()
let mut i = 0
while i < size {
let c = s.char_at(i)
let c = s[i]
match c {
'\n' => out += "\\n"
'\t' => out += "\\t"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/s_expr.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn format_lispy_expr(self : Cirru, indent : Int) -> String raise FormatError {
if token.is_empty() {
raise FormatError("empty string is invalid")
} else {
let s0 = token.char_at(0)
let s0 = token[0]
if s0 == '|' || s0 == '"' {
"\"" + escape_string(token.substring(start=1)) + "\""
} else if token.contains(" ") ||
Expand Down
10 changes: 5 additions & 5 deletions src/main/main.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ pub fn main_parser() -> Unit {

let demo_file = fsReadSync("./test/cirru/unfolding.cirru")
let json_file = fsReadSync("./test/data/unfolding.json")
let tree = Cirru::parse?(demo_file)
let tree = try? Cirru::parse(demo_file)
match tree {
Ok(tree) => {
println(tree.to_json().stringify())
match @json.parse?(json_file) {
match (try? @json.parse(json_file)) {
Ok(json) => println(json.stringify())
Err(err) => println(err.to_string())
}
Expand All @@ -32,13 +32,13 @@ pub fn main_writer() -> Unit {
let demo = "unfolding"
let demo_file = fsReadSync("./test/cirru/\{demo}.cirru")
let json_file = fsReadSync("./test/data/\{demo}.json")
let defined = @json.parse?(json_file).unwrap()
let tree : Array[Cirru] = @json.from_json?(defined).unwrap()
let defined = (try? @json.parse(json_file)).unwrap()
let tree : Array[Cirru] = (try? @json.from_json(defined)).unwrap()
println("TREE:")
for item in tree {
println(item.to_json().stringify())
}
let ret = Cirru::format?(tree, { use_inline: false }).unwrap()
let ret = (try? Cirru::format(tree, { use_inline: false })).unwrap()
println("Generated:")
println(ret)
println("Expected:")
Expand Down