ableos_userland/programs/aidl/src/ast.rs

102 lines
1.5 KiB
Rust

//! **note** the order of fields is the order of parsing.
use std::collections::HashMap;
/// An IDL module.
///
/// Parsing order:
/// - use declarations,
/// - items
#[derive(Debug)]
pub struct IDLModule {
// why: only allow use before other items
// parser will error if use is present in any other place
pub uses: Vec<UseDecl>,
pub items: Vec<Item>,
}
#[derive(Debug)]
pub enum Item {
_Interface(ItemInterface),
Alias(ItemAlias),
Constant(ItemConstant),
}
#[derive(Debug)]
pub struct Function {
pub name: String,
pub takes: Vec<Type>,
pub returns: Type
}
// why
pub type Type = String;
#[derive(Debug)]
pub struct ItemInterface {
pub name: String,
pub functions: Vec<Function>,
}
#[derive(Debug)]
pub struct ItemAlias {
pub name: String,
pub referree: String,
}
#[derive(Debug)]
pub struct ItemConstant {
pub name: String,
pub expr: Expr
}
#[derive(Debug)]
pub struct UseDecl {
pub module: ModulePath,
}
#[derive(Debug)]
pub enum Expr {
Literal(Literal),
_IdentAccess(String),
Make(Box<ExprMake>)
}
#[derive(Debug)]
pub struct ExprMake {
pub name: String,
pub params: HashMap<String, Expr>
}
#[derive(Debug)]
pub enum Literal {
String(String),
Number(NumberLiteral),
Char(char)
}
#[derive(Debug)]
pub enum NumberLiteral {
Ptr(usize),
U8(u8),
I8(i8),
U16(u16),
I16(i16),
U32(u32),
I32(i32),
U64(u64),
I64(i64),
Infer(i64),
}
/// seg1.seg2.seg3.segN
#[derive(Debug)]
pub struct ModulePath {
pub segments: Vec<String>,
}