Fixed mod attributes
This commit is contained in:
@@ -343,8 +343,7 @@ function_decl = {
|
||||
// ======================================================
|
||||
|
||||
top_level = {
|
||||
(attributes ~ (import | impl_for_decl | impl_decl | trait_decl | struct_decl | enum_decl | class_decl | declare_module | function_decl))
|
||||
| mod_attribute
|
||||
mod_attribute | (attributes ~ (import | impl_for_decl | impl_decl | trait_decl | struct_decl | enum_decl | class_decl | declare_module | function_decl))
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
|
||||
@@ -16,12 +16,15 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TopLevel {
|
||||
type Error = AstError<'a, Self>;
|
||||
|
||||
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||
let mut inner = pair.into_inner();
|
||||
let mut inner = pair.clone().into_inner();
|
||||
|
||||
let attributes = collect_recovered(inner.next().unwrap().into_inner());
|
||||
|
||||
ast_expr!(TopLevel(
|
||||
inner.next().map(Spanned::try_from).unwrap(),
|
||||
inner
|
||||
.next()
|
||||
.map(Spanned::try_from)
|
||||
.unwrap_or_else(move || Ok(Spanned::new_pair(pair, TopLevelKind::ModAttribute))),
|
||||
attributes,
|
||||
))
|
||||
}
|
||||
|
||||
@@ -28,6 +28,18 @@ pub fn consume_rule<'a>(
|
||||
if consumed { pairs.next() } else { None }
|
||||
}
|
||||
|
||||
impl<T> Spanned<T> {
|
||||
fn new_pair(pair: pest::iterators::Pair<'_, Rule>, item: T) -> Self {
|
||||
let span = pair.as_span().start_pos().line_col();
|
||||
|
||||
Self {
|
||||
line: span.0,
|
||||
column: span.1,
|
||||
item,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: TryFrom<pest::iterators::Pair<'a, Rule>, Error = AstError<'a, T>>>
|
||||
TryFrom<pest::iterators::Pair<'a, Rule>> for Spanned<T>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user