diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-02-02 23:13:57 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-02-02 23:22:47 +0100 |
| commit | 31dd071e927ab4375db6c408c08ab776e4a5c655 (patch) | |
| tree | 36a2d892bcd3162e8cf2ae875ed834cb50431432 /lib/xixanta/src/parser.rs | |
| parent | 6ab4d0aa58928bf9a5bc0b60d216e1cebaf9a5a8 (diff) | |
| download | tools.nes-31dd071e927ab4375db6c408c08ab776e4a5c655.tar.gz tools.nes-31dd071e927ab4375db6c408c08ab776e4a5c655.zip | |
Change .fallthrough to __fallthrough__
Implementing it as a control statement has the bad thing that it's
impossible to be compatible with other assemblers such as ca65, as you
cannot create dummy control statements or something like that in
there. Instead of that, we define it with the special underscores which
are still valid for identifiers, and give a "compiler-specific thingie"
flair to it.
This also has the benefit that the parser can be a bit more strict.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'lib/xixanta/src/parser.rs')
| -rw-r--r-- | lib/xixanta/src/parser.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/xixanta/src/parser.rs b/lib/xixanta/src/parser.rs index 7a7e3f0..e2e31dc 100644 --- a/lib/xixanta/src/parser.rs +++ b/lib/xixanta/src/parser.rs @@ -766,9 +766,12 @@ impl Parser { // Parse statements which are neither an instruction nor an assignment. This // includes stuff like control statements or macro calls. fn parse_other(&mut self, line: &str, id: PString) -> Result<(), Vec<Error>> { - // This is either a control statement (i.e. starts with '.') or a macro call. + // This is either a control statement (i.e. starts with '.'), a + // __fallthrough__, or a macro call. let node = if id.value.starts_with('.') { self.parse_control(id, line, 0)? + } else if id.value == "__fallthrough__" { + self.parse_fallthrough(line)? } else { let args = self.parse_arguments(line, 0)?; PNode { @@ -1642,6 +1645,29 @@ impl Parser { }) } + // Parse a fallthrough statement. + fn parse_fallthrough(&mut self, line: &str) -> Result<PNode, Error> { + // Skip whitespaces and fetch the identifier. + self.skip_whitespace(line); + let identifier = self.parse_identifier(line, false)?.0; + + // If there was something else other than the identifier, it's a parsing + // error. + let rest = line.get(self.offset..).unwrap_or("").trim(); + if !rest.is_empty() { + return Err(self.parser_error("too many arguments for __fallthrough__")); + } + + Ok(PNode { + node_type: NodeType::Fallthrough, + value: identifier, + left: None, + right: None, + args: None, + source: self.current_source, + }) + } + // Returns a NodeType::Literal node with whatever could be parsed // considering the given `line` which starts with the given `symbol`. The // recursivity `level` is also provided as it will call again |
