refactored import syntax
This commit is contained in:
+1
-1
@@ -67,7 +67,7 @@ pub struct TopLevel(pub TopLevelKind, pub Vec<Attribute>);
|
|||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub enum TopLevelKind {
|
pub enum TopLevelKind {
|
||||||
ModAttribute,
|
ModAttribute,
|
||||||
Include(Path),
|
Import(Path),
|
||||||
StructDecl {
|
StructDecl {
|
||||||
visibility: Visibility,
|
visibility: Visibility,
|
||||||
name: String,
|
name: String,
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ static_path = { identifier ~ ("::" ~ identifier)* }
|
|||||||
|
|
||||||
export = { "public" }
|
export = { "public" }
|
||||||
mutable = { "mut" }
|
mutable = { "mut" }
|
||||||
sharp = _{ "#" }
|
|
||||||
var = { "var" }
|
var = { "var" }
|
||||||
var_decl = { (var | type_expr) ~ mutable? ~ identifier }
|
var_decl = { (var | type_expr) ~ mutable? ~ identifier }
|
||||||
semicolon = _{ ";" }
|
semicolon = _{ ";" }
|
||||||
@@ -58,7 +57,7 @@ meta_list = {
|
|||||||
|
|
||||||
attributes = { attribute* }
|
attributes = { attribute* }
|
||||||
|
|
||||||
import = { sharp ~ "include" ~ "<" ~ static_path ~ ">" }
|
import = { "use" ~ "<" ~ static_path ~ ">" ~ semicolon }
|
||||||
|
|
||||||
field_list = { field ~ ("," ~ field)* ~ ","? }
|
field_list = { field ~ ("," ~ field)* ~ ","? }
|
||||||
field = { export? ~ type_expr ~ identifier }
|
field = { export? ~ type_expr ~ identifier }
|
||||||
|
|||||||
+1
-1
@@ -229,7 +229,7 @@ impl From<pest::iterators::Pair<'_, Rule>> for TopLevelKind {
|
|||||||
let mut inner = pair.clone().into_inner();
|
let mut inner = pair.clone().into_inner();
|
||||||
|
|
||||||
match rule {
|
match rule {
|
||||||
Rule::import => TopLevelKind::Include(Path::from(inner.next().unwrap())),
|
Rule::import => TopLevelKind::Import(Path::from(inner.next().unwrap())),
|
||||||
|
|
||||||
Rule::function_decl => TopLevelKind::FunctionDecl(FunctionDecl::from(pair)),
|
Rule::function_decl => TopLevelKind::FunctionDecl(FunctionDecl::from(pair)),
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -308,7 +308,7 @@ impl ToRust for TopLevelKind {
|
|||||||
fn to_rust(&self, cg: &mut RustCodegen) {
|
fn to_rust(&self, cg: &mut RustCodegen) {
|
||||||
match self {
|
match self {
|
||||||
Self::ModAttribute => {}
|
Self::ModAttribute => {}
|
||||||
Self::Include(path) => {
|
Self::Import(path) => {
|
||||||
cg.addln(&format!("use {};", path.get_rust()));
|
cg.addln(&format!("use {};", path.get_rust()));
|
||||||
}
|
}
|
||||||
Self::FunctionDecl(decl) => decl.to_rust(cg),
|
Self::FunctionDecl(decl) => decl.to_rust(cg),
|
||||||
|
|||||||
Reference in New Issue
Block a user