Fix token display and update README.md
This commit is contained in:
parent
38380001ca
commit
9bd88483c4
@ -27,7 +27,7 @@ Dust is still in development. This list may change as the language evolves.
|
|||||||
- CLI
|
- CLI
|
||||||
- [X] Run source
|
- [X] Run source
|
||||||
- [X] Compile to chunk and show disassembly
|
- [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
|
- [ ] Format using the formatter and display the output
|
||||||
- [ ] Compile to and run from intermediate formats
|
- [ ] Compile to and run from intermediate formats
|
||||||
- [ ] JSON
|
- [ ] JSON
|
||||||
|
@ -42,7 +42,7 @@ enum CliMode {
|
|||||||
global_arguments: GlobalArguments,
|
global_arguments: GlobalArguments,
|
||||||
|
|
||||||
/// Style the disassembly output
|
/// Style the disassembly output
|
||||||
#[arg(short, long)]
|
#[arg(short, long, default_value = "true")]
|
||||||
style: bool,
|
style: bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ enum CliMode {
|
|||||||
global_arguments: GlobalArguments,
|
global_arguments: GlobalArguments,
|
||||||
|
|
||||||
/// Style the disassembly output
|
/// Style the disassembly output
|
||||||
#[arg(short, long)]
|
#[arg(short, long, default_value = "true")]
|
||||||
style: bool,
|
style: bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -9,20 +9,26 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use crate::Span;
|
use crate::Span;
|
||||||
|
|
||||||
pub fn write_token_list<W: Write>(tokens: &[(Token, Span)], styled: bool, writer: &mut W) {
|
pub fn write_token_list<W: Write>(tokens: &[(Token, Span)], style: bool, writer: &mut W) {
|
||||||
const HEADER: [&str; 2] = [" TOKEN POSITION ", "------------- ----------"];
|
const HEADER: [&str; 2] = [" TOKEN POSITION ", "------------- ----------"];
|
||||||
|
|
||||||
writeln!(writer, "{}", HEADER[0]).unwrap();
|
if style {
|
||||||
writeln!(writer, "{}", HEADER[1]).unwrap();
|
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 {
|
for (token, position) in tokens {
|
||||||
let token = if styled {
|
let token = if style {
|
||||||
format!("{:^13}", token.to_string().bold())
|
format!("{:^13}", token.to_string().bold())
|
||||||
} else {
|
} else {
|
||||||
format!("{token:^13}")
|
format!("{token:^13}")
|
||||||
};
|
};
|
||||||
|
let position = position.to_string();
|
||||||
|
|
||||||
writeln!(writer, "{token} {position:<10}").unwrap();
|
writeln!(writer, "{token:^13} {position:^10}").unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user