Local include

This commit is contained in:
2026-07-08 11:23:36 +02:00
parent 44ac3c365d
commit 8198b8d5cb
4 changed files with 21 additions and 1 deletions
+1
View File
@@ -30,6 +30,7 @@ pub enum TopLevelKind {
Import(Visibility, Path),
IncludeGlobal(Path),
IncludeUse(Visibility, Path),
IncludeLocal(String),
DeclareModule(Visibility, Identifier),
ImplDecl(ImplDecl),
StaticDecl(VarDeclStmt),
+5 -1
View File
@@ -266,6 +266,10 @@ include_use_global = {
visibility? ~ "#" ~ "use" ~ static_path ~ semicolon
}
include_local = {
"#" ~ "include" ~ string_lit
}
import = {
visibility? ~ "use" ~ static_path ~ semicolon
}
@@ -392,7 +396,7 @@ type_alias = { "type" ~ identifier ~ generics_decl? ~ "=" ~ type_expr ~ ";" }
top_level = {
mod_attribute
| (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))
| (attributes ~ (include_global | include_local | 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))
}
// ======================================================
+10
View File
@@ -138,6 +138,16 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TopLevelKind {
Path::try_from(inner.next().unwrap())?,
)),
Rule::include_local => Ok(TopLevelKind::IncludeLocal(
inner
.next()
.unwrap()
.into_inner()
.next()
.unwrap()
.to_string(),
)),
_ => AstError::bug_unimplemented(pair),
}
}