mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-22 11:12:07 +00:00
Implement INCHARMAP function (#1184)
This commit is contained in:
@@ -187,6 +187,22 @@ void charmap_Add(char *mapping, uint8_t value)
|
||||
node->value = value;
|
||||
}
|
||||
|
||||
bool charmap_HasChar(char const *input)
|
||||
{
|
||||
struct Charmap const *charmap = *currentCharmap;
|
||||
struct Charnode const *node = &charmap->nodes[0];
|
||||
|
||||
for (; *input; input++) {
|
||||
size_t next = node->next[*input - 1];
|
||||
|
||||
if (!next)
|
||||
return false;
|
||||
node = &charmap->nodes[next];
|
||||
}
|
||||
|
||||
return node->isTerminal;
|
||||
}
|
||||
|
||||
size_t charmap_Convert(char const *input, uint8_t *output)
|
||||
{
|
||||
uint8_t *start = output;
|
||||
|
||||
@@ -206,6 +206,7 @@ static struct KeywordMapping {
|
||||
|
||||
{"CHARLEN", T_OP_CHARLEN},
|
||||
{"CHARSUB", T_OP_CHARSUB},
|
||||
{"INCHARMAP", T_OP_INCHARMAP},
|
||||
|
||||
{"INCLUDE", T_POP_INCLUDE},
|
||||
{"PRINT", T_POP_PRINT},
|
||||
@@ -571,7 +572,7 @@ struct KeywordDictNode {
|
||||
uint16_t children[0x60 - ' '];
|
||||
struct KeywordMapping const *keyword;
|
||||
// Since the keyword structure is invariant, the min number of nodes is known at compile time
|
||||
} keywordDict[365] = {0}; // Make sure to keep this correct when adding keywords!
|
||||
} keywordDict[370] = {0}; // Make sure to keep this correct when adding keywords!
|
||||
|
||||
// Convert a char into its index into the dict
|
||||
static uint8_t dictIndex(char c)
|
||||
|
||||
@@ -606,6 +606,7 @@ enum {
|
||||
|
||||
%token T_OP_CHARLEN "CHARLEN"
|
||||
%token T_OP_CHARSUB "CHARSUB"
|
||||
%token T_OP_INCHARMAP "INCHARMAP"
|
||||
|
||||
%token <symName> T_LABEL "label"
|
||||
%token <symName> T_ID "identifier"
|
||||
@@ -1608,6 +1609,9 @@ relocexpr_no_str : scoped_anon_id { rpn_Symbol(&$$, $1); }
|
||||
| T_OP_CHARLEN T_LPAREN string T_RPAREN {
|
||||
rpn_Number(&$$, charlenUTF8($3));
|
||||
}
|
||||
| T_OP_INCHARMAP T_LPAREN string T_RPAREN {
|
||||
rpn_Number(&$$, charmap_HasChar($3));
|
||||
}
|
||||
| T_LPAREN relocexpr T_RPAREN { $$ = $2; }
|
||||
;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user