feat: reactivityl; vdom; rhei; styles; fs; image element
This commit is contained in:
60
src/interpreter/types.rs
Normal file
60
src/interpreter/types.rs
Normal file
@@ -0,0 +1,60 @@
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
|
||||
use super::style::{ComputedStyle, StyleSheet};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Element {
|
||||
pub type_name: String,
|
||||
pub properties: HashMap<String, String>,
|
||||
pub children: Vec<Element>,
|
||||
pub computed_style: ComputedStyle,
|
||||
}
|
||||
|
||||
impl Element {
|
||||
pub fn new(type_name: String) -> Self {
|
||||
Self {
|
||||
type_name,
|
||||
properties: HashMap::new(),
|
||||
children: Vec::new(),
|
||||
computed_style: ComputedStyle::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ComponentDef {
|
||||
pub name: String,
|
||||
pub params: Vec<(String, String)>,
|
||||
pub children: Vec<Element>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Document {
|
||||
pub roots: Vec<Element>,
|
||||
pub components: HashMap<String, ComponentDef>,
|
||||
pub variables: HashMap<String, String>,
|
||||
pub rhei_scripts: Vec<String>,
|
||||
pub stylesheet: StyleSheet,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum InterpError {
|
||||
BadMagic,
|
||||
UnexpectedEof,
|
||||
InvalidUtf8,
|
||||
UnexpectedPop,
|
||||
}
|
||||
|
||||
impl fmt::Display for InterpError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::BadMagic => write!(f, "Bad magic bytes — not a .glbc file"),
|
||||
Self::UnexpectedEof => write!(f, "Unexpected end of bytecode"),
|
||||
Self::InvalidUtf8 => write!(f, "String is not valid UTF-8"),
|
||||
Self::UnexpectedPop => write!(f, "OP_ELEM_POP without matching OP_ELEM_PUSH"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for InterpError {}
|
||||
Reference in New Issue
Block a user