From 1ecee352f5844b0809d7ae66df52e34f42b44c8e Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Thu, 6 Mar 2025 20:33:27 +1300 Subject: Rewrite entire assembler The language is now more general, the code is better structured, error reporting is more detailed, and many new language features have been implemented: - conditional blocks - first-class strings - more expression operators - binary literals - negative values - invocations in constant expressions --- src/parsers/packed_binary_literal.rs | 85 ------------------------------------ 1 file changed, 85 deletions(-) delete mode 100644 src/parsers/packed_binary_literal.rs (limited to 'src/parsers/packed_binary_literal.rs') diff --git a/src/parsers/packed_binary_literal.rs b/src/parsers/packed_binary_literal.rs deleted file mode 100644 index 18f8da7..0000000 --- a/src/parsers/packed_binary_literal.rs +++ /dev/null @@ -1,85 +0,0 @@ -use crate::*; - - -/// t is a Tokeniser over the characters of the PBL, excluding the leading hash. -pub fn parse_packed_binary_literal(mut t: Tokeniser, source: SourceSpan) -> PackedBinaryLiteral { - use PackedBinaryLiteralParseError as ParseError; - use PackedBinaryLiteralParseErrorVariant as ParseErrorVar; - - let mut value = 0; - let mut bits = 0; - let mut field_bits = 0; - let mut name = '\0'; - let mut fields: Vec = Vec::new(); - let mut errors: Vec = Vec::new(); - - macro_rules! push_field { - () => { - if fields.iter().any(|f| f.name == name) { - let variant = ParseErrorVar::DuplicateFieldName(name); - errors.push(ParseError { source: t.get_source(), variant }); - } else { - fields.push(BitField { name, source: t.get_source(), bits: field_bits, shift: 0 }); - } - }; - } - - while let Some(c) = t.eat_char() { - // Ignore underscores. - if c == '_' { - t.mark.undo(); - continue; - } - - // Add a bit to the value; - value <<= 1; - bits += 1; - for field in &mut fields { - field.shift += 1; - } - - // Extend the current field. - if c == name { - field_bits += 1; - continue; - } - - // Commit the current field. - if field_bits > 0 { - t.mark_end_prev(); - push_field!(); - field_bits = 0; - name = '\0'; - } - - // Parse bit literals. - if c == '0' { - continue; - } - if c == '1' { - value |= 1; - continue; - } - - t.mark_start_prev(); - if c.is_alphabetic() { - name = c; - field_bits = 1; - continue; - } else { - let source = t.get_source(); - let variant = ParseErrorVar::InvalidCharacter(c); - errors.push(ParseError { source, variant }); - } - } - - // Commit the final field. - for field in &mut fields { - field.shift += 1; - } - if field_bits > 0 { - push_field!(); - } - - PackedBinaryLiteral { source, bits, value, fields, errors } -} -- cgit v1.2.3-70-g09d2