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
+5
View File
@@ -338,6 +338,11 @@ impl GenRust for TopLevelKind {
.or_insert(Vec::new()) .or_insert(Vec::new())
.push(crate::Include::Use(vis.clone(), incl.clone())); .push(crate::Include::Use(vis.clone(), incl.clone()));
} }
Self::IncludeLocal(path) => {
cg.add("include!(\"");
cg.add(&path.replace(".mist", ".rs"));
cg.add("\");");
}
} }
} }
} }
+1
View File
@@ -30,6 +30,7 @@ pub enum TopLevelKind {
Import(Visibility, Path), Import(Visibility, Path),
IncludeGlobal(Path), IncludeGlobal(Path),
IncludeUse(Visibility, Path), IncludeUse(Visibility, Path),
IncludeLocal(String),
DeclareModule(Visibility, Identifier), DeclareModule(Visibility, Identifier),
ImplDecl(ImplDecl), ImplDecl(ImplDecl),
StaticDecl(VarDeclStmt), StaticDecl(VarDeclStmt),
+5 -1
View File
@@ -266,6 +266,10 @@ include_use_global = {
visibility? ~ "#" ~ "use" ~ static_path ~ semicolon visibility? ~ "#" ~ "use" ~ static_path ~ semicolon
} }
include_local = {
"#" ~ "include" ~ string_lit
}
import = { import = {
visibility? ~ "use" ~ static_path ~ semicolon visibility? ~ "use" ~ static_path ~ semicolon
} }
@@ -392,7 +396,7 @@ type_alias = { "type" ~ identifier ~ generics_decl? ~ "=" ~ type_expr ~ ";" }
top_level = { top_level = {
mod_attribute 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())?, 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), _ => AstError::bug_unimplemented(pair),
} }
} }