From 9bd88483c46e9903756d11ae6d46a9384710bb40 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 3 Dec 2024 18:46:21 -0500 Subject: [PATCH] Fix token display and update README.md --- README.md | 2 +- dust-cli/src/main.rs | 4 ++-- dust-lang/src/token.rs | 16 +++++++++++----- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 18698e7..283488c 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Dust is still in development. This list may change as the language evolves. - CLI - [X] Run source - [X] Compile to chunk and show disassembly - - [ ] Tokenize using the lexer and show token list + - [X] Tokenize using the lexer and show token list - [ ] Format using the formatter and display the output - [ ] Compile to and run from intermediate formats - [ ] JSON diff --git a/dust-cli/src/main.rs b/dust-cli/src/main.rs index 872084b..4acea19 100644 --- a/dust-cli/src/main.rs +++ b/dust-cli/src/main.rs @@ -42,7 +42,7 @@ enum CliMode { global_arguments: GlobalArguments, /// Style the disassembly output - #[arg(short, long)] + #[arg(short, long, default_value = "true")] style: bool, }, @@ -53,7 +53,7 @@ enum CliMode { global_arguments: GlobalArguments, /// Style the disassembly output - #[arg(short, long)] + #[arg(short, long, default_value = "true")] style: bool, }, } diff --git a/dust-lang/src/token.rs b/dust-lang/src/token.rs index 4d3e48c..ef15b9d 100644 --- a/dust-lang/src/token.rs +++ b/dust-lang/src/token.rs @@ -9,20 +9,26 @@ use serde::{Deserialize, Serialize}; use crate::Span; -pub fn write_token_list(tokens: &[(Token, Span)], styled: bool, writer: &mut W) { +pub fn write_token_list(tokens: &[(Token, Span)], style: bool, writer: &mut W) { const HEADER: [&str; 2] = [" TOKEN POSITION ", "------------- ----------"]; - writeln!(writer, "{}", HEADER[0]).unwrap(); - writeln!(writer, "{}", HEADER[1]).unwrap(); + if style { + writeln!(writer, "{}", HEADER[0].bold()).unwrap(); + writeln!(writer, "{}", HEADER[1].bold()).unwrap(); + } else { + writeln!(writer, "{}", HEADER[0]).unwrap(); + writeln!(writer, "{}", HEADER[1]).unwrap(); + } for (token, position) in tokens { - let token = if styled { + let token = if style { format!("{:^13}", token.to_string().bold()) } else { format!("{token:^13}") }; + let position = position.to_string(); - writeln!(writer, "{token} {position:<10}").unwrap(); + writeln!(writer, "{token:^13} {position:^10}").unwrap(); } }