Minimal support for raw string literals
This commit is contained in:
parent
b75ea1161e
commit
1f76e7a846
@ -2183,13 +2183,22 @@ static void string(int type) {
|
||||
|
||||
int isBytes = (parser.previous.type == TOKEN_PREFIX_B);
|
||||
int isFormat = (parser.previous.type == TOKEN_PREFIX_F);
|
||||
int isRaw = (parser.previous.type == TOKEN_PREFIX_R);
|
||||
|
||||
int atLeastOne = 0;
|
||||
const char * lineBefore = krk_tellScanner().linePtr;
|
||||
size_t lineNo = krk_tellScanner().line;
|
||||
|
||||
if ((isBytes || isFormat) && !(match(TOKEN_STRING) || match(TOKEN_BIG_STRING))) {
|
||||
if ((isBytes || isFormat || isRaw) && !(match(TOKEN_STRING) || match(TOKEN_BIG_STRING))) {
|
||||
error("Expected string after prefix? (Internal error - scanner should not have produced this.)");
|
||||
return;
|
||||
}
|
||||
|
||||
if (isRaw) {
|
||||
emitConstant(OBJECT_VAL(krk_copyString(
|
||||
parser.previous.start + (parser.previous.type == TOKEN_BIG_STRING ? 3 : 1),
|
||||
parser.previous.length - (parser.previous.type == TOKEN_BIG_STRING ? 6 : 2))));
|
||||
return;
|
||||
}
|
||||
|
||||
/* This should capture everything but the quotes. */
|
||||
@ -2783,6 +2792,7 @@ ParseRule krk_parseRules[] = {
|
||||
RULE(TOKEN_BIG_STRING, string, NULL, PREC_NONE),
|
||||
RULE(TOKEN_PREFIX_B, string, NULL, PREC_NONE),
|
||||
RULE(TOKEN_PREFIX_F, string, NULL, PREC_NONE),
|
||||
RULE(TOKEN_PREFIX_R, string, NULL, PREC_NONE),
|
||||
RULE(TOKEN_NUMBER, number, NULL, PREC_NONE),
|
||||
RULE(TOKEN_AND, NULL, and_, PREC_AND),
|
||||
RULE(TOKEN_CLASS, NULL, NULL, PREC_NONE),
|
||||
|
@ -102,6 +102,7 @@ typedef enum {
|
||||
|
||||
TOKEN_PREFIX_B,
|
||||
TOKEN_PREFIX_F,
|
||||
TOKEN_PREFIX_R,
|
||||
|
||||
TOKEN_INDENTATION,
|
||||
|
||||
|
@ -252,7 +252,8 @@ static KrkTokenType identifierType() {
|
||||
case 'r': if (MORE(1)) switch (scanner.start[1]) {
|
||||
case 'e': return checkKeyword(2, "turn", TOKEN_RETURN);
|
||||
case 'a': return checkKeyword(2, "ise", TOKEN_RAISE);
|
||||
} break;
|
||||
} else if (scanner.start[1] == '\'' || scanner.start[1] == '"') return TOKEN_PREFIX_R;
|
||||
break;
|
||||
case 's': return checkKeyword(1, "uper", TOKEN_SUPER);
|
||||
case 't': return checkKeyword(1, "ry", TOKEN_TRY);
|
||||
case 'T': return checkKeyword(1, "rue", TOKEN_TRUE);
|
||||
|
Loading…
Reference in New Issue
Block a user