moonrockz/krueger/cst does not have a README file
pub(all) enum DeclarationCst {
Function(FunctionCst)
TypeAlias(TypeAliasCst)
UnionType(UnionTypeCst)
} derive(Eq, Debug)test {
let source = @scanner.SourceText::new(
(
#|module Shapes exposing (Shape(..), area)
#|
#|import Html exposing (text)
#|
#|type Shape a = Circle a | Square a
#|
#|type alias Size = Float
#|
#|area : Shape Float -> Float
#|area shape = 0
),
)
let result = @parser.parse_module(source, @scanner.DefaultScanner::new())
guard result.cst is Some(module_cst) else { fail("no CST") }
debug_inspect(
module_cst.header.map(h => (h.module_name, h.exposing)),
content="Some((Some(\"Shapes\"), [\"Shape\", \"area\"]))",
)
debug_inspect(
module_cst.imports.map(i => (i.module_name, i.exposing)),
content="[(\"Html\", Some([\"text\"]))]",
)
let declarations = module_cst.declarations.map(d => {
match d {
Function(f) => ("function", f.name, f.args)
TypeAlias(a) => ("alias", a.name, a.type_params)
UnionType(t) => ("type", t.name, t.type_params)
}
})
debug_inspect(
declarations,
content=(
#|[
#| ("type", "Shape", ["a"]),
#| ("alias", "Size", []),
#| ("function", "area", ["shape"]),
#|]
),
)
// The function covers its signature and its definition.
guard module_cst.declarations[2] is Function(area) else { fail("no area") }
inspect(area.tokens[0].lexeme, content="area")
debug_inspect((area.span.start.line, area.span.end.line), content="(9, 10)")
}test {
let text = "module Main exposing (..)\r\n\r\n-- note\r\nx = 1\r\n"
let result = @parser.parse_module(
@scanner.SourceText::new(text),
@scanner.DefaultScanner::new(),
)
debug_inspect(
result.cst.map(c => c.to_source() == text),
content="Some(true)",
)
}Install
Download zipParser and parsing utilities for Elm and Elm-like dialects (e.g. Morphir) in MoonBit
Dependencies