Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trying with latest moonbit #3

Merged
merged 1 commit into from
Jul 23, 2024
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
5 changes: 4 additions & 1 deletion lib/moon.pkg.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"import": []
"import": [],
"test-import": [
"tiye/cirru-parser"
]
}
8 changes: 4 additions & 4 deletions lib/parser.mbt
Original file line number Diff line number Diff line change
@@ -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")
}
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion lib/parser_test.mbt
Original file line number Diff line number Diff line change
@@ -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!")
}
}
35 changes: 4 additions & 31 deletions lib/primes.mbt
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion moon.pkg.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"import": [{ "path": "tiye/cirru-parser/lib", "alias": "cirru" }]
"import": ["tiye/cirru-parser/lib"]
}
2 changes: 1 addition & 1 deletion top.mbt
Original file line number Diff line number Diff line change
@@ -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)
}
Expand Down
Loading