Added use include
This commit is contained in:
@@ -26,10 +26,15 @@ pub trait GetRust {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum Include {
|
||||||
|
Glob(Path),
|
||||||
|
Use(Visibility, Path),
|
||||||
|
}
|
||||||
|
|
||||||
pub struct RustCodegen {
|
pub struct RustCodegen {
|
||||||
output: String,
|
output: String,
|
||||||
indent: usize,
|
indent: usize,
|
||||||
pub crates: HashMap<Identifier, Vec<Path>>,
|
pub crates: HashMap<Identifier, Vec<Include>>,
|
||||||
pub mapping: Mapping,
|
pub mapping: Mapping,
|
||||||
position: RustMap,
|
position: RustMap,
|
||||||
}
|
}
|
||||||
@@ -101,8 +106,17 @@ impl RustCodegen {
|
|||||||
|
|
||||||
for item in items {
|
for item in items {
|
||||||
self.add_indented("pub use ");
|
self.add_indented("pub use ");
|
||||||
item.gen_rust(&mut ctx, self);
|
match item {
|
||||||
self.addln("::*;");
|
Include::Glob(item) => {
|
||||||
|
item.gen_rust(&mut ctx, self);
|
||||||
|
self.add("::*");
|
||||||
|
}
|
||||||
|
Include::Use(vis, item) => {
|
||||||
|
vis.gen_rust(&mut ctx, self);
|
||||||
|
item.gen_rust(&mut ctx, self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.addln(";");
|
||||||
}
|
}
|
||||||
|
|
||||||
self.indent -= 1;
|
self.indent -= 1;
|
||||||
|
|||||||
@@ -330,7 +330,13 @@ impl GenRust for TopLevelKind {
|
|||||||
cg.crates
|
cg.crates
|
||||||
.entry(incl.0[0].clone())
|
.entry(incl.0[0].clone())
|
||||||
.or_insert(Vec::new())
|
.or_insert(Vec::new())
|
||||||
.push(incl.clone());
|
.push(crate::Include::Glob(incl.clone()));
|
||||||
|
}
|
||||||
|
Self::IncludeUse(vis, incl) => {
|
||||||
|
cg.crates
|
||||||
|
.entry(incl.0[0].clone())
|
||||||
|
.or_insert(Vec::new())
|
||||||
|
.push(crate::Include::Use(vis.clone(), incl.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ pub enum TopLevelKind {
|
|||||||
ModAttribute,
|
ModAttribute,
|
||||||
Import(Visibility, Path),
|
Import(Visibility, Path),
|
||||||
IncludeGlobal(Path),
|
IncludeGlobal(Path),
|
||||||
|
IncludeUse(Visibility, Path),
|
||||||
DeclareModule(Visibility, Identifier),
|
DeclareModule(Visibility, Identifier),
|
||||||
ImplDecl(ImplDecl),
|
ImplDecl(ImplDecl),
|
||||||
StaticDecl(VarDeclStmt),
|
StaticDecl(VarDeclStmt),
|
||||||
|
|||||||
@@ -262,6 +262,10 @@ include_global = {
|
|||||||
"#" ~ "include" ~ "<" ~ identifier ~ ("/" ~ identifier)* ~ ">"
|
"#" ~ "include" ~ "<" ~ identifier ~ ("/" ~ identifier)* ~ ">"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
include_use_global = {
|
||||||
|
visibility? ~ "#" ~ "use" ~ static_path ~ semicolon
|
||||||
|
}
|
||||||
|
|
||||||
import = {
|
import = {
|
||||||
visibility? ~ "use" ~ static_path ~ semicolon
|
visibility? ~ "use" ~ static_path ~ semicolon
|
||||||
}
|
}
|
||||||
@@ -388,7 +392,7 @@ type_alias = { "type" ~ identifier ~ generics_decl? ~ "=" ~ type_expr ~ ";" }
|
|||||||
|
|
||||||
top_level = {
|
top_level = {
|
||||||
mod_attribute
|
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))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
|
|||||||
@@ -129,7 +129,14 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TopLevelKind {
|
|||||||
ty: inner.next().unwrap().try_into()?,
|
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),
|
_ => AstError::bug_unimplemented(pair),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user