Local include
This commit is contained in:
@@ -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("\");");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ pub enum TopLevelKind {
|
||||
Import(Visibility, Path),
|
||||
IncludeGlobal(Path),
|
||||
IncludeUse(Visibility, Path),
|
||||
IncludeLocal(String),
|
||||
DeclareModule(Visibility, Identifier),
|
||||
ImplDecl(ImplDecl),
|
||||
StaticDecl(VarDeclStmt),
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user