diff options
author | Ben Bridle <ben@derelict.engineering> | 2025-03-06 20:33:27 +1300 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2025-03-11 16:59:26 +1300 |
commit | 1ecee352f5844b0809d7ae66df52e34f42b44c8e (patch) | |
tree | 472b6fd57ff7f64ac3f8cd676cbe7a113ba01f05 /src/tokens/syntactic.rs | |
parent | f2ed89083f5326a7a6f0a1720033d3388aa431fb (diff) | |
download | torque-asm-1ecee352f5844b0809d7ae66df52e34f42b44c8e.zip |
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
Diffstat (limited to 'src/tokens/syntactic.rs')
-rw-r--r-- | src/tokens/syntactic.rs | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/src/tokens/syntactic.rs b/src/tokens/syntactic.rs deleted file mode 100644 index 780c950..0000000 --- a/src/tokens/syntactic.rs +++ /dev/null @@ -1,84 +0,0 @@ -use crate::*; - - -pub struct SyntacticToken { - pub source: SourceSpan, - pub variant: SyntacticTokenVariant, -} - -pub enum SyntacticTokenVariant { - LabelDefinition(String), - MacroDefinition(String), - MacroDefinitionTerminator, - - IntegerLiteral(isize), - PackedBinaryLiteral(PackedBinaryLiteral), - PinnedAddress(usize), - - Expression(Expression), - - String(TrackedString), - - BlockOpen, - BlockClose, - Separator, - - Symbol(String), - - 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, -} - - -impl std::fmt::Debug for SyntacticToken { - fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { - use SyntacticTokenVariant::*; - let start = &self.source.in_merged; - let name = match &self.variant { - LabelDefinition(name) => format!("LabelDefinition({name})"), - MacroDefinition(name) => format!("MacroDefinition({name})"), - MacroDefinitionTerminator => format!("MacroDefinitionTerminator"), - - IntegerLiteral(value) => format!("IntegerLiteral({value})"), - PackedBinaryLiteral(pbl) => format!("PackedBinaryLiteral({pbl})"), - PinnedAddress(value) => format!("PinnedAddress({value})"), - - Expression(expr) => format!("Expression({expr:?})"), - - String(string) => format!("String('{string}')"), - - BlockOpen => format!("BlockOpen"), - BlockClose => format!("BlockClose"), - Separator => format!("Separator"), - - Symbol(name) => format!("Symbol({name})"), - - Error(error) => format!("Error({error:?})"), - }; - - write!(f, "{start} {name}") - } -} |