Added use include

This commit is contained in:
2026-07-08 10:44:09 +02:00
parent bb006c1ba2
commit c564fc3e90
5 changed files with 38 additions and 6 deletions
+1
View File
@@ -29,6 +29,7 @@ pub enum TopLevelKind {
ModAttribute,
Import(Visibility, Path),
IncludeGlobal(Path),
IncludeUse(Visibility, Path),
DeclareModule(Visibility, Identifier),
ImplDecl(ImplDecl),
StaticDecl(VarDeclStmt),
+5 -1
View File
@@ -262,6 +262,10 @@ include_global = {
"#" ~ "include" ~ "<" ~ identifier ~ ("/" ~ identifier)* ~ ">"
}
include_use_global = {
visibility? ~ "#" ~ "use" ~ static_path ~ semicolon
}
import = {
visibility? ~ "use" ~ static_path ~ semicolon
}
@@ -388,7 +392,7 @@ type_alias = { "type" ~ identifier ~ generics_decl? ~ "=" ~ type_expr ~ ";" }
top_level = {
mod_attribute
| (attributes ~ (include_global | import | impl_for_decl | impl_decl | trait_decl | struct_decl | enum_decl | class_decl | declare_module | function_decl | const_decl | static_decl | type_alias))
| (attributes ~ (include_global | include_use_global | import | impl_for_decl | impl_decl | trait_decl | struct_decl | enum_decl | class_decl | declare_module | function_decl | const_decl | static_decl | type_alias))
}
// ======================================================
+8 -1
View File
@@ -129,7 +129,14 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TopLevelKind {
ty: inner.next().unwrap().try_into()?,
}),
Rule::include_global => Ok(TopLevelKind::IncludeGlobal(Path(collect_recovered(&mut inner)?))),
Rule::include_global => Ok(TopLevelKind::IncludeGlobal(Path(collect_recovered(
&mut inner,
)?))),
Rule::include_use_global => Ok(TopLevelKind::IncludeUse(
Visibility::try_from(&mut inner)?,
Path::try_from(inner.next().unwrap())?,
)),
_ => AstError::bug_unimplemented(pair),
}