diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/locators/source.rs | 6 | ||||
-rw-r--r-- | src/print.rs | 12 | ||||
-rw-r--r-- | src/translators/symbols_generator.rs | 3 |
3 files changed, 11 insertions, 10 deletions
diff --git a/src/locators/source.rs b/src/locators/source.rs index 2f10bd9..20542e3 100644 --- a/src/locators/source.rs +++ b/src/locators/source.rs @@ -11,6 +11,12 @@ pub struct SourceSpan { pub in_source: Option<SourceLocation>, } +impl SourceSpan { + pub fn location(&self) -> &SourceLocation { + self.in_source.as_ref().unwrap_or(&self.in_merged) + } +} + #[derive(Clone)] pub struct SourceLocation { diff --git a/src/print.rs b/src/print.rs index 0c81c07..b2c2ba8 100644 --- a/src/print.rs +++ b/src/print.rs @@ -71,14 +71,10 @@ fn get_message_for_semantic_error(error: &SemanticParseError) -> String { format!("Block was not closed, add a '}}' character to close"), SemErr::UndefinedSymbol(name) => format!("Undefined symbol, no label or macro has been defined with the name '{name}'"), - SemErr::RedefinedSymbol((_, source)) => { - let location = source.in_source.as_ref().unwrap_or(&source.in_merged); - format!("Redefined symbol, first defined at {location}") - } - SemErr::MacroInvocationBeforeDefinition((_, source)) => { - let location = source.in_source.as_ref().unwrap_or(&source.in_merged); - format!("Macro used before definition, definition is at {location}") - } + SemErr::RedefinedSymbol((_, source)) => + format!("Redefined symbol, first defined at {}", source.location()), + SemErr::MacroInvocationBeforeDefinition((_, source)) => + format!("Macro used before definition, definition is at {}", source.location()), SemErr:: SyntaxError(syntax_error) => match syntax_error { SynErr::UnterminatedComment => format!("Unclosed comment, add a ')' character to close"), diff --git a/src/translators/symbols_generator.rs b/src/translators/symbols_generator.rs index 6db1d46..d30facd 100644 --- a/src/translators/symbols_generator.rs +++ b/src/translators/symbols_generator.rs @@ -11,8 +11,7 @@ pub fn generate_symbols_file(semantic_tokens: &[SemanticToken]) -> String { let address = token.bytecode.location.address; if address > 0xffff { break; } let name = &definition.name; - let location = token.source.in_source.as_ref() - .unwrap_or(&token.source.in_merged); + let location = token.source.location(); symbols.push_str(&format!("{address:04x} {name} {location}\n")); } } |