diff --git a/crates/codegen/src/top_level.rs b/crates/codegen/src/top_level.rs index 9927a11..bbe1490 100644 --- a/crates/codegen/src/top_level.rs +++ b/crates/codegen/src/top_level.rs @@ -338,6 +338,11 @@ impl GenRust for TopLevelKind { .or_insert(Vec::new()) .push(crate::Include::Use(vis.clone(), incl.clone())); } + Self::IncludeLocal(path) => { + cg.add("include!(\""); + cg.add(&path.replace(".mist", ".rs")); + cg.add("\");"); + } } } } diff --git a/crates/parser/src/ast/top_level.rs b/crates/parser/src/ast/top_level.rs index 707e8c9..2e95aed 100644 --- a/crates/parser/src/ast/top_level.rs +++ b/crates/parser/src/ast/top_level.rs @@ -30,6 +30,7 @@ pub enum TopLevelKind { Import(Visibility, Path), IncludeGlobal(Path), IncludeUse(Visibility, Path), + IncludeLocal(String), DeclareModule(Visibility, Identifier), ImplDecl(ImplDecl), StaticDecl(VarDeclStmt), diff --git a/crates/parser/src/grammar.pest b/crates/parser/src/grammar.pest index 8e7eeaf..24b188b 100644 --- a/crates/parser/src/grammar.pest +++ b/crates/parser/src/grammar.pest @@ -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)) } // ====================================================== diff --git a/crates/parser/src/parser/items/mod.rs b/crates/parser/src/parser/items/mod.rs index b0c1b38..4022024 100644 --- a/crates/parser/src/parser/items/mod.rs +++ b/crates/parser/src/parser/items/mod.rs @@ -138,6 +138,16 @@ impl<'a> TryFrom> 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), } }