Parser and parsing utilities for the Gleam programming language in MoonBit
Dependencies
inspect(
@gleam.format("pub fn main(){\n io.println( \"hi\" )\n}\n"),
content="pub fn main() {\n io.println(\"hi\")\n}\n",
)test {
let r = @gleam.parse_text("import gleam/io\n\npub fn main() {\n io.println(\"hi\")\n}\n")
inspect(r.module_.definitions.length(), content="2")
inspect(r.has_errors(), content="false")
}test {
let tree = @gleam.Tree::new(@gleam.parse_text("pub fn add(a, b) {\n a + b\n}\n"))
// Byte 25 is the `b` in `a + b`.
let b = tree.node_at(25).unwrap()
inspect("\{b.category()}/\{b.kind()}", content="expression/var")
inspect(tree.node_path(b).unwrap(), content="definitions[0].body[0].expression[0].right[0]")
}moon add moonrockz/gleam-parserimport {
"moonrockz/gleam-parser" @gleam,
}fn diagnostic_description(code : String) -> String?test {
inspect(@gleam.format("const x = 1\n"), content="const x = 1\n")
}fn parse_float_value(value : String) -> Double?test {
let r = @gleam.parse_text("pub fn main() {\n io.println(\"hi\")\n}\n")
inspect(r.module_.definitions.length(), content="1")
inspect(r.has_errors(), content="false")
}fn version() -> Stringtest {
inspect(@gleam.version().split(".").count(), content="3")
}test {
let root = @gleam.NodeRef::of_result(
@gleam.parse_text("pub fn f(x) {\n x\n}\n"),
)
let kinds = []
@gleam.walk(root, n => {
kinds.push(n.kind())
Continue
})
inspect(kinds.join(" "), content="module function arg expression var")
}Install
Download zipParser and parsing utilities for the Gleam programming language in MoonBit
Dependencies