diff --git a/src/main.rs b/src/main.rs index 813a30b..8f1134e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release +use web_lisp::node::Node; use web_lisp::{ lexer::{self, Token}, parser, @@ -17,29 +18,40 @@ fn main() { ); } -use eframe::egui; +use eframe::egui::{self, Label, RichText, TextEdit}; struct MyApp { + omnibar: String, tokens: Vec, + root_node: Node, } impl MyApp { fn new(tokens: Vec) -> Self { - Self { tokens } + let mut root_node = Node::default(); + root_node.text = "hi".to_string(); + root_node.size = Some(30.0); + Self { + omnibar: "".to_string(), + tokens, + root_node, + } } } impl eframe::App for MyApp { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { egui::CentralPanel::default().show(ctx, |ui| { - for token in &self.tokens { - match token { - Token::Tag(tag) => { - ui.heading(tag); - } - _ => {} - } - } + _frame.set_window_title("title"); + ui.text_edit_singleline(&mut self.omnibar); + ui.separator(); + + let rn = &self.root_node; + let tx = RichText::new(rn.text.clone()) + .size(rn.size.unwrap_or(12.0)) + .underline(); + + ui.add(Label::new(tx)); }); } } diff --git a/src/node.rs b/src/node.rs index f702fbd..abf17dc 100644 --- a/src/node.rs +++ b/src/node.rs @@ -1,14 +1,26 @@ use std::fmt::Display; + #[derive(Debug)] -pub struct Node<'a> { - pub text: Option<&'a str>, - pub children: Vec>, +pub struct Node { + pub text: String, + pub size: Option, + pub children: Vec, } -impl Display for Node<'_> { +impl Display for Node { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{:#?}", self)?; Ok(()) } } + +impl Default for Node { + fn default() -> Self { + Self { + text: Default::default(), + size: Default::default(), + children: Default::default(), + } + } +} diff --git a/src/parser.rs b/src/parser.rs index f894fea..929e834 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -4,61 +4,18 @@ use crate::{ }; pub enum ParserError {} -pub fn parse_vec(mut tokens: &[Token]) { - let mut nodes: Node = Node { - text: Some("Root"), - children: vec![], - }; - - let mut current_token: Option = None; - let mut kwargs: Vec<&Kwarg> = vec![]; - let mut strin = &String::new(); - - let mut expr_finished = false; - // let mut +pub fn parse_vec(mut tokens: &[Token]) -> Node { + let mut nodes: Node = Node::default(); for i in 1..tokens.len() - 1 { let token = &tokens[i]; match token { - Token::Tag(ref tag) => match tag.as_str() { - "text" => { - current_token = Some(Token::Tag(tag.to_string())); - } - "title" => {} - _ => {} - }, - Token::Kwarg(kwarg) => kwargs.push(kwarg), - Token::Strg(strg) => { - let st = strg; - strin = st - } - Token::EndParen => expr_finished = true, - /* - Token::Quote => todo!(), - Token::StartParen => todo!(), - Token::Num(_) => todo!(), - Token::Float(_) => todo!(), - Token::HexaDec(_) => todo!(), - Token::Error => todo!(), - */ _ => {} } - - if expr_finished { - // panic!() - println!("text finished"); - expr_finished = false; - - let node = Node { - text: Some(&strin), - children: vec![], - }; - - nodes.children.push(node) - } } println!("{}", nodes); + nodes } pub enum TagTypes { diff --git a/web_lisp_src/hello_world.wisp b/web_lisp_src/hello_world.wisp index acb6947..2c873f2 100644 --- a/web_lisp_src/hello_world.wisp +++ b/web_lisp_src/hello_world.wisp @@ -1,9 +1,3 @@ (wisp - (metadata (title "Web Lisp")) - (onload (code '())) - (on-update (code '())) (document - (style :id "abc" :style '()) - (text :style "abc" "Smol paragraph!!") - (button (lambda '())) - (image :id 1))) \ No newline at end of file + (text "Hello, World!"))) \ No newline at end of file