Kaydet (Commit) 756344d9 authored tarafından SiegeLord's avatar SiegeLord

Rust: Parse character literals.

These were omitted by mistake. Caused bugs like '"' being interpreted as a
start/end of a string, '}' as the end of a block etc.
üst fba9d19e
......@@ -292,6 +292,41 @@ static void scanRawString (lexerState *lexer)
}
}
/* This deals with character literals: 'n', '\n', '\uFFFF'; and lifetimes:
* 'lifetime. We'll use this approximate regexp for the literals:
* \' \\ [^']+ \' or \' [^'] \' or \' \\ \' \'. Either way, we'll treat this
* token as a string, so it gets preserved as is for function signatures with
* lifetimes. */
static void scanCharacterOrLifetime (lexerState *lexer)
{
vStringClear(lexer->token_str);
advanceAndStoreChar(lexer);
if (lexer->cur_c == '\\')
{
advanceAndStoreChar(lexer);
/* The \' \\ \' \' (literally '\'') case */
if (lexer->cur_c == '\'' && lexer->next_c == '\'')
{
advanceAndStoreChar(lexer);
advanceAndStoreChar(lexer);
}
/* The \' \\ [^']+ \' case */
else
{
while (lexer->cur_c != EOF && lexer->cur_c != '\'')
advanceAndStoreChar(lexer);
}
}
/* The \' [^'] \' case */
else if (lexer->cur_c != '\'' && lexer->next_c == '\'')
{
advanceAndStoreChar(lexer);
advanceAndStoreChar(lexer);
}
/* Otherwise it is malformed, or a lifetime */
}
/* Advances the parser one token, optionally skipping whitespace
* (otherwise it is concatenated and returned as a single whitespace token).
* Whitespace is needed to properly render function signatures. Unrecognized
......@@ -334,6 +369,11 @@ static int advanceToken (lexerState *lexer, boolean skip_whitspace)
scanRawString(lexer);
return lexer->cur_token = TOKEN_STRING;
}
else if (lexer->cur_c == '\'')
{
scanCharacterOrLifetime(lexer);
return lexer->cur_token = TOKEN_STRING;
}
else if (isIdentifierStart(lexer->cur_c))
{
scanIdentifier(lexer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment