diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-15 16:00:58 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-15 16:02:38 +0100 |
| commit | 88213ce95acf88a82cd446500dc7de730f4dd669 (patch) | |
| tree | 68b5226a6936336d88050b0cf0b97d73b3c24104 /lib | |
| parent | a11fd7b8fb7b1590defb692dcb17d9d7272aebe7 (diff) | |
| download | tools.nes-88213ce95acf88a82cd446500dc7de730f4dd669.tar.gz tools.nes-88213ce95acf88a82cd446500dc7de730f4dd669.zip | |
Move check for ASCII-only strings into the parser
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/xixanta/src/assembler.rs | 11 | ||||
| -rw-r--r-- | lib/xixanta/src/parser.rs | 4 |
2 files changed, 6 insertions, 9 deletions
diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs index 32d7c14..851f3c3 100644 --- a/lib/xixanta/src/assembler.rs +++ b/lib/xixanta/src/assembler.rs @@ -1659,15 +1659,8 @@ impl<'a> Assembler<'a> { let string = self.fetch_quoted_first_argument(node)?; for ch in string.chars() { - if !ch.is_ascii() { - return Err(Error { - line: node.value.line, - message: "string can only contain ASCII characters".to_string(), - source: self.source_for(node), - global: false, - }); - } - + // NOTE: the parser guarantees that a string literal only contains + // ASCII characters. self.push_bundle(Bundle::fill(ch as u8), node)?; } self.push_bundle(Bundle::fill(0x00), node)?; diff --git a/lib/xixanta/src/parser.rs b/lib/xixanta/src/parser.rs index d42ff12..524f7c2 100644 --- a/lib/xixanta/src/parser.rs +++ b/lib/xixanta/src/parser.rs @@ -902,6 +902,10 @@ impl Parser { // character (unless it was escaped through '\'). let mut prev = '"'; for ch in line.get(self.offset..).unwrap_or("").chars() { + if !ch.is_ascii() { + return Err(self.parser_error("using non-ASCII characters in a string")); + } + if ch == '"' && prev != '\\' { self.next(); |
