From 67470aea034fd46f4bbcfe815c51ad3451043188 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Thu, 27 Feb 2025 14:53:21 +1300 Subject: Finish first working version of Torque This is a huge and messy commit, worked on piecemeal while traveling and while the language was still being designed. --- src/tokens/packed_binary_literal.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/tokens/packed_binary_literal.rs') diff --git a/src/tokens/packed_binary_literal.rs b/src/tokens/packed_binary_literal.rs index 1252398..a2720b7 100644 --- a/src/tokens/packed_binary_literal.rs +++ b/src/tokens/packed_binary_literal.rs @@ -2,17 +2,13 @@ use crate::*; pub struct PackedBinaryLiteral { + pub source: SourceSpan, pub value: usize, + pub bits: usize, pub fields: Vec, pub errors: Vec, } -impl PackedBinaryLiteral { - pub fn from_str(string: &str, parent: &Tokeniser) -> Self { - parse_packed_binary_literal(string, parent) - } -} - pub struct BitField { pub name: char, pub source: SourceSpan, @@ -40,7 +36,8 @@ impl std::fmt::Display for PackedBinaryLiteral { } else { let bitcount = (self.value.ilog2() + 1) as usize; 'bit: for i in (0..bitcount).rev() { - if (i+1) % 4 == 0 { + let is_first_bit = i+1 == bitcount; + if !is_first_bit && (i+1) % 4 == 0 { write!(f, "_")?; } for field in &self.fields { -- cgit v1.2.3-70-g09d2