From dba769e13ca5029643c6068e53fa34ae0fea8421 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Fri, 28 Feb 2025 13:23:20 +1300 Subject: Implement string literals String literals are treated as integers. If a string is passed as an integer argument to a packed binary literal, a new instance of the packed binary literal is invoked for every character in the string, with each character being passed to the packed binary literal as a Unicode character value. --- src/tokens/syntactic.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/tokens/syntactic.rs') diff --git a/src/tokens/syntactic.rs b/src/tokens/syntactic.rs index eb33806..780c950 100644 --- a/src/tokens/syntactic.rs +++ b/src/tokens/syntactic.rs @@ -17,6 +17,8 @@ pub enum SyntacticTokenVariant { Expression(Expression), + String(TrackedString), + BlockOpen, BlockClose, Separator, @@ -26,12 +28,26 @@ pub enum SyntacticTokenVariant { Error(SyntacticParseError), } +#[derive(Clone)] +pub struct TrackedString { + pub source: SourceSpan, + pub string: String, + pub chars: Vec>, +} + +impl std::fmt::Display for TrackedString { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { + self.string.fmt(f) + } +} + #[derive(Debug)] pub enum SyntacticParseError { InvalidHexadecimalLiteral(String), InvalidDecimalLiteral(String), InvalidSymbolIdentifier(String), UnterminatedComment, + UnterminatedString, UnterminatedExpression, LabelInMacroDefinition, } @@ -52,6 +68,8 @@ impl std::fmt::Debug for SyntacticToken { Expression(expr) => format!("Expression({expr:?})"), + String(string) => format!("String('{string}')"), + BlockOpen => format!("BlockOpen"), BlockClose => format!("BlockClose"), Separator => format!("Separator"), -- cgit v1.2.3-70-g09d2