wip: use stateful buffer

This commit is contained in:
Jonathan Kelley 2022-06-27 13:36:41 -04:00
parent 79b475798d
commit a2a194ca40
4 changed files with 29 additions and 6 deletions

View file

@ -0,0 +1,17 @@
use std::fmt::Result;
struct Buffer {
buf: String,
cur_line: usize,
cur_indent: usize,
}
impl Buffer {
fn write_tabs(&mut self, num: usize) -> Result {
todo!()
}
fn new_line(&mut self) -> Result {
todo!()
}
}

View file

@ -1,12 +1,18 @@
use crate::{util::*, write_ident};
use dioxus_rsx::*;
use std::{fmt, fmt::Write};
use std::{fmt, fmt::Result, fmt::Write};
enum ShortOptimization {
// Special because we want to print the closing bracket immediately
Empty,
// Special optimization to put everything on the same line
Oneliner,
// Optimization where children flow but props remain fixed on top
PropsOnTop,
// The noisiest optimization where everything flows
NoOpt,
}
@ -20,9 +26,8 @@ pub fn write_element(
}: &Element,
buf: &mut String,
lines: &[&str],
node: &BodyNode,
indent: usize,
) -> fmt::Result {
) -> Result {
/*
1. Write the tag
2. Write the key
@ -157,7 +162,7 @@ fn write_attributes(
attributes: &[ElementAttrNamed],
sameline: bool,
indent: usize,
) -> fmt::Result {
) -> Result {
let mut attr_iter = attributes.iter().peekable();
while let Some(attr) = attr_iter.next() {
@ -178,7 +183,7 @@ fn write_attributes(
Ok(())
}
fn write_attribute(buf: &mut String, attr: &ElementAttrNamed, indent: usize) -> fmt::Result {
fn write_attribute(buf: &mut String, attr: &ElementAttrNamed, indent: usize) -> Result {
match &attr.attr {
ElementAttr::AttrText { name, value } => {
write!(buf, "{name}: \"{value}\"", value = value.value())?;

View file

@ -11,7 +11,7 @@ pub fn write_ident(
indent: usize,
) -> fmt::Result {
match node {
BodyNode::Element(el) => write_element(el, buf, lines, node, indent),
BodyNode::Element(el) => write_element(el, buf, lines, indent),
BodyNode::Component(component) => write_component(component, buf, indent, lines),
BodyNode::Text(text) => write_text(text, buf, indent),
BodyNode::RawExpr(exp) => write_raw_expr(exp, indent, lines, buf),

View file

@ -5,6 +5,7 @@ use proc_macro2::TokenStream as TokenStream2;
use quote::ToTokens;
mod block;
mod buffer;
mod children;
mod component;
mod element;