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")]
// 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<Token>,
root_node: Node,
}
impl MyApp {
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 {
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));
});
}
}

View file

@ -1,14 +1,26 @@
use std::fmt::Display;
#[derive(Debug)]
pub struct Node<'a> {
pub text: Option<&'a str>,
pub children: Vec<Node<'a>>,
pub struct Node {
pub text: String,
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 {
write!(f, "{:#?}", self)?;
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 fn parse_vec(mut tokens: &[Token]) {
let mut nodes: Node = Node {
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
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 {

View file

@ -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)))
(text "Hello, World!")))