Allow charmap to map 'characters' as well as "strings" (#1830)

This commit is contained in:
Rangi
2025-09-16 06:51:07 -04:00
committed by GitHub
parent 6cffd991f7
commit e0a6199f83
3 changed files with 13 additions and 10 deletions

View File

@@ -638,12 +638,12 @@ and the values of a charmap entry are counted by
When writing text strings that are meant to be displayed on the Game Boy, the character encoding in the ROM may need to be different than the source file encoding. When writing text strings that are meant to be displayed on the Game Boy, the character encoding in the ROM may need to be different than the source file encoding.
For example, the tiles used for uppercase letters may be placed starting at tile index 128, which differs from ASCII starting at 65. For example, the tiles used for uppercase letters may be placed starting at tile index 128, which differs from ASCII starting at 65.
.Pp .Pp
Character maps allow mapping strings to arbitrary sequences of numbers: Character maps allow mapping strings or character literals to arbitrary sequences of numbers:
.Bd -literal -offset indent .Bd -literal -offset indent
CHARMAP "A", 42 CHARMAP "A", 42
CHARMAP ":)", 39 CHARMAP ':)', 39
CHARMAP "<br>", 13, 10 CHARMAP "<br>", 13, 10
CHARMAP "&euro;", $20ac CHARMAP '&euro;', $20ac
.Ed .Ed
.Pp .Pp
This would result in This would result in

View File

@@ -1049,6 +1049,9 @@ charmap:
POP_CHARMAP string COMMA charmap_args trailing_comma { POP_CHARMAP string COMMA charmap_args trailing_comma {
charmap_Add($2, std::move($4)); charmap_Add($2, std::move($4));
} }
| POP_CHARMAP CHARACTER COMMA charmap_args trailing_comma {
charmap_Add($2, std::move($4));
}
; ;
charmap_args: charmap_args:

View File

@@ -1,13 +1,13 @@
def s equs "d" def s equs "d"
charmap "A", 1 charmap 'A', 1
charmap "B", 2 charmap 'B', 2
charmap "c{s}e", 3 charmap 'c{s}e', 3
charmap "F", 4, 5, 6 charmap 'F', 4, 5, 6
charmap "'", 42 charmap "'", 42
charmap "\"", 1234 charmap '"', 1234
charmap "\n\r\t\0", 1337 charmap '\n\r\t\0', 1337
charmap "',\",\\", 99 charmap '\',\",\\', 99
MACRO char MACRO char
assert (\1) == (\2) assert (\1) == (\2)