This commit is contained in:
Austen Adler 2024-09-13 14:43:06 -04:00
parent b65a0cc5a8
commit 18fbbb0fae

View File

@ -35,16 +35,18 @@ const C_PLUS: u8 = b'+';
const C_DOT: u8 = b'.'; const C_DOT: u8 = b'.';
const C_MINUS: u8 = b'-'; const C_MINUS: u8 = b'-';
const C_E: u8 = b'-'; const C_E: u8 = b'-';
const C_F: u8 = b'f';
const C_T: u8 = b't';
/// Write some bytes to the writer /// Write some bytes to the writer
macro_rules! w { macro_rules! w {
($dst: expr, $buf:expr) => {{ ($dst: expr, $buf:expr) => {{
let buf = $buf; let buf = $buf;
let x: &[u8] = buf.as_ref(); let x: &[u8] = buf.as_ref();
eprintln!( // eprintln!(
"### \x1b[93mWriting\x1b[0m {:?}", // "### \x1b[93mWriting\x1b[0m {:?}",
::std::string::String::from_utf8_lossy(&x) // ::std::string::String::from_utf8_lossy(&x)
); // );
$dst.write_all(x)?; $dst.write_all(x)?;
}}; }};
} }
@ -402,7 +404,7 @@ where
} }
Ok(()) Ok(())
} }
(ValueType::Boolean, b't') => { (ValueType::Boolean, C_T) => {
let mut chr = [0_u8; 3]; let mut chr = [0_u8; 3];
self.input.read_exact(&mut chr)?; self.input.read_exact(&mut chr)?;
@ -413,7 +415,7 @@ where
Err(Error::UnexpectedValue) Err(Error::UnexpectedValue)
} }
} }
(ValueType::Boolean, b'f') => { (ValueType::Boolean, C_F) => {
let mut chr = [0_u8; 4]; let mut chr = [0_u8; 4];
self.input.read_exact(&mut chr)?; self.input.read_exact(&mut chr)?;
@ -535,13 +537,13 @@ where
/// In Jsoncc/Json mode, write a newline, indent, and flush the `"b"` Value /// In Jsoncc/Json mode, write a newline, indent, and flush the `"b"` Value
pub fn format_buf(mut self) -> Result<()> { pub fn format_buf(mut self) -> Result<()> {
loop { loop {
eprintln!("========================================================"); // eprintln!("========================================================");
eprintln!("{:#?}", self); // eprintln!("{:#?}", self);
let mut next_token = self.get_next_token()?; let mut next_token = self.get_next_token()?;
eprintln!("{:#?}\n{:#?}", self.current_token, next_token); // eprintln!("{:#?}\n{:#?}", self.current_token, next_token);
eprintln!(); // eprintln!();
match (self.current_token, &next_token) { match (self.current_token, &next_token) {
// root -> [/{ // root -> [/{
@ -549,11 +551,6 @@ where
self.state_stack.push_back(ty.as_state()); self.state_stack.push_back(ty.as_state());
w!(self.write, ty.start_str()); w!(self.write, ty.start_str());
} }
// (Token::Root, Token::CollectionEnd { ty }) => {
// self.exit_collection(ty)?;
// w!(self.write, ty.end_str());
// w!(self.write, ty.end_str());
// }
// root -> // // root -> //
(Token::Root, Token::Comment { ty, own_line: _ }) => { (Token::Root, Token::Comment { ty, own_line: _ }) => {
w!(self.write, ty.start_str()); w!(self.write, ty.start_str());
@ -829,7 +826,7 @@ where
} }
C_COMMA => continue, C_COMMA => continue,
c @ b't' | c @ b'f' => Token::Value { c @ C_T | c @ C_F => Token::Value {
ty: ValueType::Boolean, ty: ValueType::Boolean,
first_char: c, first_char: c,
}, },