use crate::*; use SemanticTokenVariant as SemVar; pub struct SemanticToken { pub source: SourceSpan, pub bytecode: BytecodeSpan, pub variant: SemanticTokenVariant, } pub enum SemanticTokenVariant { LabelDefinition(LabelDefinition), MacroDefinition(MacroDefinition), /// Pointer to the matching label definition. LabelReference(usize), /// Pointer to the matching macro definition. MacroInvocation(usize), Literal(Value), Padding(Value), Instruction(Instruction), Comment(String), String(Vec), /// Pointer to the matching block close. BlockOpen(usize), /// Pointer to the matching block open. BlockClose(usize), MarkOpen, MarkClose, Error(SemanticParseError), } impl std::fmt::Debug for SemanticToken { fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { match &self.variant { SemVar::LabelDefinition(def) => write!(f, "LabelDefinition({})", def.name), SemVar::MacroDefinition(def) => write!(f, "MacroDefinition({})", def.name), SemVar::LabelReference(pointer) => write!(f, "LabelReference(*{pointer})"), SemVar::MacroInvocation(pointer) => write!(f, "MacroInvocation(*{pointer})"), SemVar::Literal(value) => write!(f, "Literal({value})"), SemVar::Padding(value) => write!(f, "Padding({value})"), SemVar::Instruction(instr) => write!(f, "Instruction(0x{:02x})", instr.value), SemVar::Comment(comment) => write!(f, "Comment({comment})"), SemVar::String(string) => write!(f, "String({})", String::from_utf8_lossy(&string)), SemVar::BlockOpen(_) => write!(f, "BlockOpen"), SemVar::BlockClose(_) => write!(f, "BlockClose"), SemVar::MarkOpen => write!(f, "MarkOpen"), SemVar::MarkClose => write!(f, "MarkClose"), SemVar::Error(_) => write!(f, "Error"), } } } pub struct LabelDefinition { /// The absolute name of the label or sublabel. pub name: String, /// List of pointers to label reference tokens. pub references: Vec, } pub struct MacroDefinition { pub name: String, pub references: Vec, pub body_tokens: Vec, } pub enum SemanticParseError { LabelDefinitionInMacroDefinition, MacroDefinitionInMacroDefinition, StrayMacroTerminator, StrayBlockClose, UnclosedBlock, UndefinedSymbol(String), RedefinedSymbol((String, SourceSpan)), MacroInvocationBeforeDefinition((String, SourceSpan)), SyntaxError(SyntacticParseError) }