From e38f108921c61e1e66d65a368f2a67a763d61e69 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Sat, 6 May 2023 16:19:15 +1200 Subject: About to refactor parser to be a struct with a method for each stage --- src/syntactic_token.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/syntactic_token.rs (limited to 'src/syntactic_token.rs') diff --git a/src/syntactic_token.rs b/src/syntactic_token.rs new file mode 100644 index 0000000..ee473e2 --- /dev/null +++ b/src/syntactic_token.rs @@ -0,0 +1,43 @@ +use crate::*; + +pub enum SyntacticTokenType { + Reference(String), + + LabelDefinition(String), + MacroDefinition(String), + MacroTerminator, + + Pad(u16), + Byte(u8), + Short(u16), + Instruction(u8), + + Comment, +} + +pub struct SyntacticToken { + pub r#type: SyntacticTokenType, + pub source_location: SourceLocation, + pub error: Option, +} + +impl SyntacticToken { + // Call when this token is found inside a macro definition. + pub fn use_in_macro_body(&mut self) { + match self.r#type { + SyntacticTokenType::LabelDefinition(..) | + SyntacticTokenType::MacroDefinition(..) => { + self.set_error(Error::InvalidTypeInMacroDefinition) + } + _ => (), + }; + } + + pub fn set_error(&mut self, error: Error) { + self.error = Some(error); + } + + pub fn is_macro_terminator(&self) -> bool { + if let SyntacticTokenType::MacroTerminator = self.r#type {true} else {false} + } +} -- cgit v1.2.3-70-g09d2