diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-08-18 16:44:27 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-08-18 16:44:27 +0200 |
| commit | 34339ecae6c4d3284a099d34f09674b4c8bdfd62 (patch) | |
| tree | b6f1db84f34e05b2b60541895e6a5b268889aba6 /lib | |
| parent | 6cb4215f55876a7fffb1fd33f2bd061283d2389f (diff) | |
| download | tools.nes-34339ecae6c4d3284a099d34f09674b4c8bdfd62.tar.gz tools.nes-34339ecae6c4d3284a099d34f09674b4c8bdfd62.zip | |
Do not mark some valid identifiers as invalid
Some identifiers like "@aa" were marked as invalid as "aa" is a
potentially hexadecimal value, but the "@" symbol actually disambiguates
this situation. Hence, if a non-alphanumeric character (that the parser
liked) is actually found, ensure it cannot be considered as an
hexadecimal value.
Provide also a test of is_valid_identifier(). The list is certainly not
exhaustive, but it should be good enough coupled with end-to-end tests.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/xixanta/src/node.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/xixanta/src/node.rs b/lib/xixanta/src/node.rs index 357b9e0..dac131a 100644 --- a/lib/xixanta/src/node.rs +++ b/lib/xixanta/src/node.rs @@ -69,6 +69,8 @@ impl PString { if c > 'f' && c <= 'z' { valid_hex = false; } + } else { + valid_hex = false; } } @@ -512,4 +514,29 @@ mod tests { assert_eq!(is_asan_friendly_name(&string), expect); } } + + #[test] + fn is_valid_identifier() { + let tests = vec![ + ("", false), + ("valid", true), + ("invalid::scoped", false), + ("x", false), + ("aaaa", false), + ("123", false), + ("@aa", true), + ]; + + for (name, expect) in tests { + let ps = PString { + value: name.to_string(), + line: 0, + start: 0, + end: 0, + }; + + let res = ps.is_valid_identifier(false).is_ok(); + assert_eq!(res, expect); + } + } } |
