This commit is contained in:
able 2022-07-03 17:55:19 -05:00
parent 436ebea1a7
commit d1f5d18a42
4 changed files with 42 additions and 67 deletions

View file

@ -1,6 +1,7 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
// hide console window on Windows in release // hide console window on Windows in release
use web_lisp::node::Node;
use web_lisp::{ use web_lisp::{
lexer::{self, Token}, lexer::{self, Token},
parser, parser,
@ -17,29 +18,40 @@ fn main() {
); );
} }
use eframe::egui; use eframe::egui::{self, Label, RichText, TextEdit};
struct MyApp { struct MyApp {
omnibar: String,
tokens: Vec<Token>, tokens: Vec<Token>,
root_node: Node,
} }
impl MyApp { impl MyApp {
fn new(tokens: Vec<Token>) -> Self { fn new(tokens: Vec<Token>) -> 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 { impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default().show(ctx, |ui| {
for token in &self.tokens { _frame.set_window_title("title");
match token { ui.text_edit_singleline(&mut self.omnibar);
Token::Tag(tag) => { ui.separator();
ui.heading(tag);
} 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));
}); });
} }
} }

View file

@ -1,14 +1,26 @@
use std::fmt::Display; use std::fmt::Display;
#[derive(Debug)] #[derive(Debug)]
pub struct Node<'a> { pub struct Node {
pub text: Option<&'a str>, pub text: String,
pub children: Vec<Node<'a>>, pub size: Option<f32>,
pub children: Vec<Node>,
} }
impl Display for Node<'_> { impl Display for Node {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:#?}", self)?; write!(f, "{:#?}", self)?;
Ok(()) Ok(())
} }
} }
impl Default for Node {
fn default() -> Self {
Self {
text: Default::default(),
size: Default::default(),
children: Default::default(),
}
}
}

View file

@ -4,61 +4,18 @@ use crate::{
}; };
pub enum ParserError {} pub enum ParserError {}
pub fn parse_vec(mut tokens: &[Token]) { pub fn parse_vec(mut tokens: &[Token]) -> Node {
let mut nodes: Node = Node { let mut nodes: Node = Node::default();
text: Some("Root"),
children: vec![],
};
let mut current_token: Option<Token> = None;
let mut kwargs: Vec<&Kwarg> = vec![];
let mut strin = &String::new();
let mut expr_finished = false;
// let mut
for i in 1..tokens.len() - 1 { for i in 1..tokens.len() - 1 {
let token = &tokens[i]; let token = &tokens[i];
match token { 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); println!("{}", nodes);
nodes
} }
pub enum TagTypes { pub enum TagTypes {

View file

@ -1,9 +1,3 @@
(wisp (wisp
(metadata (title "Web Lisp"))
(onload (code '()))
(on-update (code '()))
(document (document
(style :id "abc" :style '()) (text "Hello, World!")))
(text :style "abc" "Smol paragraph!!")
(button (lambda '()))
(image :id 1)))