mirror of
https://github.com/autc04/Retro68.git
synced 2024-11-26 06:49:33 +00:00
Rez: string literal concatenation, hex strings
This commit is contained in:
parent
2b5c415db3
commit
2b64cb707d
@ -198,7 +198,7 @@ RezSymbol RezLexer::nextToken()
|
||||
KEYWORD(BITSTRING, "bitstring"),
|
||||
|
||||
KEYWORD(INTEGER, "int"),
|
||||
|
||||
KEYWORD(DOLLAR, "$")
|
||||
};
|
||||
|
||||
std::string s = tok.get_value().c_str();
|
||||
|
@ -39,7 +39,7 @@
|
||||
%token OR "|";
|
||||
%token XOR "^";
|
||||
%token COMPL "~";
|
||||
|
||||
%token DOLLAR "$";
|
||||
|
||||
%token TYPE "type";
|
||||
%token RESOURCE "resource";
|
||||
@ -119,6 +119,37 @@
|
||||
{
|
||||
std::cerr << loc << ": " << err << std::endl;
|
||||
}
|
||||
|
||||
static std::string fromHex(std::string hex)
|
||||
{
|
||||
std::string bin;
|
||||
int nibble;
|
||||
bool haveNibble = false;
|
||||
for(std::string::iterator p = hex.begin(); p != hex.end(); ++p)
|
||||
{
|
||||
if(std::isspace(*p))
|
||||
continue;
|
||||
assert(isdigit(*p) || (tolower(*p) >= 'a' && tolower(*p) <= 'f'));
|
||||
int digit;
|
||||
if(isdigit(*p))
|
||||
digit = *p - '0';
|
||||
else
|
||||
digit = tolower(*p) - 'a' + 0xA;
|
||||
|
||||
if(haveNibble)
|
||||
{
|
||||
bin += (char) ((nibble << 4) | digit);
|
||||
haveNibble = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
nibble = digit;
|
||||
haveNibble = true;
|
||||
}
|
||||
}
|
||||
return bin;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
%%
|
||||
@ -278,9 +309,17 @@ switch_case : "case" IDENTIFIER ":"
|
||||
}
|
||||
;
|
||||
|
||||
%type <std::string> string onestring;
|
||||
string : onestring { $$ = $1; }
|
||||
| string onestring { $$ = $1 + $2; }
|
||||
;
|
||||
onestring : STRINGLIT { $$ = $1; }
|
||||
| DOLLAR STRINGLIT { $$ = fromHex($2); }
|
||||
;
|
||||
|
||||
value : expression { $$ = $1; }
|
||||
| "{" resource_body "}" { $$ = $2; }
|
||||
| STRINGLIT { $$ = std::make_shared<StringExpr>($1); }
|
||||
| string { $$ = std::make_shared<StringExpr>($1); }
|
||||
;
|
||||
|
||||
expression : expression1 { $$ = $1; }
|
||||
|
Loading…
Reference in New Issue
Block a user