Attribute parsing and ast

This commit is contained in:
2026-05-05 03:17:33 +02:00
parent d9c20467a4
commit f4a14789c3
3 changed files with 114 additions and 24 deletions
+22 -11
View File
@@ -20,22 +20,20 @@ pub enum TypePostfix {
#[derive(Debug, Clone, Serialize)]
pub struct Attribute {
pub path: StaticPath,
pub args: Vec<AttributeArg>,
pub kind: MetaItemKind,
}
#[derive(Debug, Clone, Serialize)]
pub enum AttributeArg {
Named(String, Literal),
Positional(Literal),
pub enum MetaItemKind {
Word,
NameValue(Literal),
List(Vec<NestedMetaItem>),
}
#[derive(Debug, Clone, Serialize)]
pub enum Literal {
String(String),
Int(i64),
Float(f64),
Bool(bool),
Tuple(Vec<Expression>),
pub enum NestedMetaItem {
Literal(Literal),
MetaItem(Attribute),
}
#[derive(Debug, Clone, Serialize)]
@@ -67,7 +65,10 @@ pub enum BinaryOp {
}
#[derive(Debug, Clone, Serialize)]
pub enum TopLevel {
pub struct TopLevel(pub TopLevelKind, pub Vec<Attribute>);
#[derive(Debug, Clone, Serialize)]
pub enum TopLevelKind {
Include(StaticPath),
StructDecl {
export: bool,
@@ -81,6 +82,7 @@ pub enum TopLevel {
return_type: TypeExpr,
body: Block,
},
EOI,
}
#[derive(Debug, Clone, Serialize)]
@@ -166,3 +168,12 @@ pub enum Expression {
postfixes: Vec<Postfix>,
},
}
#[derive(Debug, Clone, Serialize)]
pub enum Literal {
String(String),
Int(i64),
Float(f64),
Bool(bool),
Tuple(Vec<Expression>),
}