summaryrefslogtreecommitdiff
path: root/src/tokens/syntactic.rs
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2025-02-28 13:23:20 +1300
committerBen Bridle <ben@derelict.engineering>2025-02-28 13:34:23 +1300
commitdba769e13ca5029643c6068e53fa34ae0fea8421 (patch)
tree47b45ecddaf08bcef19de29ad65206c34af85f53 /src/tokens/syntactic.rs
parent1a810d036195395c182f6cd6e011b8fb868d9872 (diff)
downloadtorque-asm-dba769e13ca5029643c6068e53fa34ae0fea8421.zip
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.
Diffstat (limited to 'src/tokens/syntactic.rs')
-rw-r--r--src/tokens/syntactic.rs18
1 files changed, 18 insertions, 0 deletions
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<Tracked<char>>,
+}
+
+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"),