Top level attributes
This commit is contained in:
@@ -62,6 +62,7 @@ pub struct TopLevel(pub TopLevelKind, pub Vec<Attribute>);
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub enum TopLevelKind {
|
pub enum TopLevelKind {
|
||||||
|
ModAttribute,
|
||||||
Include(Path),
|
Include(Path),
|
||||||
StructDecl {
|
StructDecl {
|
||||||
export: bool,
|
export: bool,
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ attribute = {
|
|||||||
"#" ~ "[" ~ meta ~ "]"
|
"#" ~ "[" ~ meta ~ "]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod_attribute = {
|
||||||
|
"#" ~ "!" ~ "[" ~ meta ~ "]"
|
||||||
|
}
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
static_path ~ ("=" ~ primary | "(" ~ meta_list? ~ ")")?
|
static_path ~ ("=" ~ primary | "(" ~ meta_list? ~ ")")?
|
||||||
}
|
}
|
||||||
@@ -33,7 +37,7 @@ meta_list = {
|
|||||||
|
|
||||||
attributes = { attribute* }
|
attributes = { attribute* }
|
||||||
|
|
||||||
top_level = { attributes ~ (import | function_decl | struct_decl) }
|
top_level = { (attributes ~ (import | function_decl | struct_decl)) | mod_attribute }
|
||||||
|
|
||||||
import = { sharp ~ "include" ~ "<" ~ static_path ~ ">" }
|
import = { sharp ~ "include" ~ "<" ~ static_path ~ ">" }
|
||||||
|
|
||||||
|
|||||||
+8
-4
@@ -84,9 +84,7 @@ impl From<pest::iterators::Pair<'_, Rule>> for TypeExprKind {
|
|||||||
impl From<pest::iterators::Pair<'_, Rule>> for Path {
|
impl From<pest::iterators::Pair<'_, Rule>> for Path {
|
||||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
||||||
match pair.as_rule() {
|
match pair.as_rule() {
|
||||||
Rule::static_path => {
|
Rule::static_path => Path(pair.into_inner().map(|i| i.as_str().to_string()).collect()),
|
||||||
Path(pair.into_inner().map(|i| i.as_str().to_string()).collect())
|
|
||||||
}
|
|
||||||
_ => unimplemented!("{pair:#?}"),
|
_ => unimplemented!("{pair:#?}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,7 +186,13 @@ impl From<pest::iterators::Pair<'_, Rule>> for TopLevel {
|
|||||||
.map(Attribute::from)
|
.map(Attribute::from)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
TopLevel(TopLevelKind::from(inner.next().unwrap()), attributes)
|
TopLevel(
|
||||||
|
inner
|
||||||
|
.next()
|
||||||
|
.map(TopLevelKind::from)
|
||||||
|
.unwrap_or(TopLevelKind::ModAttribute),
|
||||||
|
attributes,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-2
@@ -228,8 +228,17 @@ impl ToRust for Block {
|
|||||||
|
|
||||||
impl ToRust for TopLevel {
|
impl ToRust for TopLevel {
|
||||||
fn to_rust(&self, cg: &mut RustCodegen) {
|
fn to_rust(&self, cg: &mut RustCodegen) {
|
||||||
for attr in &self.1 {
|
match &self.0 {
|
||||||
cg.addln(&format!("#[{}]", attr.get_rust()));
|
TopLevelKind::ModAttribute => {
|
||||||
|
for attr in &self.1 {
|
||||||
|
cg.addln(&format!("#![{}]", attr.get_rust()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
for attr in &self.1 {
|
||||||
|
cg.addln(&format!("#[{}]", attr.get_rust()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.0.to_rust(cg);
|
self.0.to_rust(cg);
|
||||||
@@ -261,6 +270,7 @@ impl GetRust for Attribute {
|
|||||||
impl ToRust for TopLevelKind {
|
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::Include(path) => {
|
Self::Include(path) => {
|
||||||
cg.addln(&format!("use {};", path.get_rust()));
|
cg.addln(&format!("use {};", path.get_rust()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#![allow(unused_mut)]
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
public struct ApiCall {
|
public struct ApiCall {
|
||||||
i32 x,
|
i32 x,
|
||||||
|
|||||||
Reference in New Issue
Block a user