Skip to content

Commit

Permalink
Be more explicit on empty identifiers
Browse files Browse the repository at this point in the history
If the programmer only wrote a single special character for an
identifier, then we will consider it empty to avoid shenanigans.

Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed Jan 21, 2025
1 parent 183ad31 commit 98a0845
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/xixanta/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,7 @@ impl Parser {
line: self.line,
global: false,
source: self.sources[self.current_source].clone(),
message: format!(
"{} relative label can only have '{}' characters",
msg, next
),
message: format!("{} relative label can only have '{}' characters", msg, next),
});
}
self.next();
Expand All @@ -359,7 +356,7 @@ impl Parser {
// The value of the identifier is whatever we have picked up
// along the parsing.
let value = String::from(line.get(base_offset..self.offset).unwrap_or("").trim());
if value == "." {
if value == "." || value == "@" || value == "_" {
return Err(self.parser_error("empty identifier"));
}

Expand Down Expand Up @@ -392,7 +389,7 @@ impl Parser {
// The line is merely the identifier (e.g. instruction with implied
// addressing).
let id = String::from(line.get(base_offset..).unwrap_or_default().trim());
if id == "." {
if id == "." || id == "@" || id == "_" {
return Err(self.parser_error("empty identifier"));
}
Ok((
Expand Down

0 comments on commit 98a0845

Please sign in to comment.