diff --git a/lib/moon.pkg.json b/lib/moon.pkg.json index b4cd689..432ac05 100644 --- a/lib/moon.pkg.json +++ b/lib/moon.pkg.json @@ -1,3 +1,6 @@ { - "import": [] + "import": [], + "test-import": [ + "tiye/cirru-parser" + ] } diff --git a/lib/parser.mbt b/lib/parser.mbt index 4952bc0..50890c7 100644 --- a/lib/parser.mbt +++ b/lib/parser.mbt @@ -1,6 +1,6 @@ fn build_exprs( - tokens : @vec.Vec[CirruLexItem] -) -> Result[@vec.Vec[Cirru], String] { + tokens : Array[CirruLexItem] +) -> Result[Array[Cirru], String] { let a = [1, 2, 3] Result::Err("TODO") } @@ -27,8 +27,8 @@ fn parse_indentation(size : Int) -> Result[CirruLexItem, String] { } } -fn lex(initial_code : String) -> Result[@vec.Vec[CirruLexItem], String] { - let acc : @vec.Vec[CirruLexItem] = @vec.Vec::new() +fn lex(initial_code : String) -> Result[Array[CirruLexItem], String] { + let acc = [] let mut state = CirruLexState::Indent let mut buffer = "" let code = initial_code.to_array() diff --git a/lib/parser_test.mbt b/lib/parser_test.mbt index 0c93abc..50bc94d 100644 --- a/lib/parser_test.mbt +++ b/lib/parser_test.mbt @@ -1,5 +1,5 @@ test "parser" { - if parse("demo文字demo") != Ok(Cirru::Leaf("TODO...")) { + if @lib.parse("demo文字demo") != Ok(@lib.Cirru::Leaf("TODO...")) { abort("parsed wrong!") } } diff --git a/lib/primes.mbt b/lib/primes.mbt index ad48171..ea98fe1 100644 --- a/lib/primes.mbt +++ b/lib/primes.mbt @@ -1,13 +1,13 @@ /// Cirru uses nested Vecters and Strings as data structure -enum Cirru { +pub enum Cirru { /// Leaf node, with a string Leaf(String) /// List node, with a list of children - List(@vec.Vec[Cirru]) -} + List(Array[Cirru]) +} derive(Eq) fn Cirru::default() -> Cirru { - Cirru::List(@vec.Vec::new()) + Cirru::List(Array::new()) } fn to_string(self : Cirru) -> String { @@ -44,33 +44,6 @@ pub fn debug_write(self : Cirru, buffer : Buffer) -> Unit { } } -fn op_equal(self : Cirru, other : Cirru) -> Bool { - match self { - Cirru::Leaf(a) => - match other { - Cirru::Leaf(b) => a == b - _ => false - } - Cirru::List(xs) => - match other { - Cirru::List(ys) => { - if xs.length() != ys.length() { - return false - } - let size = xs.length() - let mut i = 0 - while i <= size { - if xs[i] != ys[i] { - return false - } - i = i + 1 - } - return true - } - _ => false - } - } -} pub fn length(self : Cirru) -> Int { match self { diff --git a/moon.pkg.json b/moon.pkg.json index ace1ddf..9f59897 100644 --- a/moon.pkg.json +++ b/moon.pkg.json @@ -1,3 +1,3 @@ { - "import": [{ "path": "tiye/cirru-parser/lib", "alias": "cirru" }] + "import": ["tiye/cirru-parser/lib"] } diff --git a/top.mbt b/top.mbt index cacc1e5..9028e57 100644 --- a/top.mbt +++ b/top.mbt @@ -1,5 +1,5 @@ pub fn demo_parser() -> Unit { - match @cirru.parse("DEMO") { + match @lib.parse("DEMO") { Ok(tree) => debug(tree) Err(err) => debug(err) }