Parse module function
This commit is contained in:
@@ -72,6 +72,10 @@ program = {
|
|||||||
SOI ~ top_level* ~ EOI
|
SOI ~ top_level* ~ EOI
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module_program = {
|
||||||
|
SOI ~ declare_module?
|
||||||
|
}
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
// MODIFIERS
|
// MODIFIERS
|
||||||
// ======================================================
|
// ======================================================
|
||||||
|
|||||||
@@ -56,6 +56,30 @@ pub fn parse<'a>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn parse_module<'a>(
|
||||||
|
source: &'a str,
|
||||||
|
) -> Result<Option<(Visibility, Identifier)>, ParseError<'a, Option<(Visibility, Identifier)>>> {
|
||||||
|
let mut pairs = MistParser::parse(Rule::module_program, source)?;
|
||||||
|
|
||||||
|
if let Some(v) = pairs
|
||||||
|
.next()
|
||||||
|
.unwrap()
|
||||||
|
.into_inner()
|
||||||
|
.next()
|
||||||
|
.map(TopLevel::try_from)
|
||||||
|
.transpose()
|
||||||
|
.get()?
|
||||||
|
{
|
||||||
|
if let TopLevelKind::DeclareModule(vis, name) = &v.0.item {
|
||||||
|
Ok(Some((vis.clone(), name.clone())))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! ast_ensure {
|
macro_rules! ast_ensure {
|
||||||
($pair:expr, $rule:expr $(, $rules:expr)* => $body:block) => {
|
($pair:expr, $rule:expr $(, $rules:expr)* => $body:block) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user