emit appropriate errors for BrokenComment and BrokenStringLiteral tokens

This commit is contained in:
Allen Webster
2021-06-30 15:50:31 -04:00
parent 1454f04265
commit 8c41bea434
2 changed files with 31 additions and 16 deletions
+2 -2
View File
@@ -5,8 +5,8 @@
//
// [x] unify string literal token kinds
// [x] simplify string literal flags (triple as a single flag)
// [ ] lexer detects broken comments
// [ ] lexer detects broken strings
// [x] lexer detects broken comments
// [x] lexer detects broken strings
// [x] tests for legal tag syntaxes
// [x] tests that ensure we don't accept labels when expecting symbols e.g. foo ":" b; foo: "(" )
// [ ] pass all tests
+29 -14
View File
@@ -1169,10 +1169,6 @@ MD_TokenFromString(MD_String8 string)
token.kind = MD_TokenKind_Comment;
chop_n = 2;
}
else
{
// TODO(allen): emit an error *from here*
}
}
}
if (token.kind == 0) goto symbol_lex;
@@ -1845,17 +1841,36 @@ MD_ParseOneNode(MD_String8 string, MD_u64 offset)
{
off += bad_token.outer_string.size;
// TODO(allen): tighten up with good integer <-> string helpers
MD_String8List bytes = {0};
for(int i_byte = 0; i_byte < bad_token.outer_string.size; ++i_byte)
{
MD_PushStringToList(&bytes, MD_PushStringF("0x%02X", bad_token.outer_string.str[i_byte]));
switch (bad_token.kind){
case MD_TokenKind_BadCharacter:
{
// TODO(allen): tighten up with good integer <-> string helpers
MD_String8List bytes = {0};
for(int i_byte = 0; i_byte < bad_token.outer_string.size; ++i_byte)
{
MD_PushStringToList(&bytes, MD_PushStringF("0x%02X", bad_token.outer_string.str[i_byte]));
}
MD_String8 byte_string = MD_JoinStringList(bytes, MD_S8Lit(" "));
MD_Error *error = MD_MakeTokenError(string, bad_token, MD_MessageKind_Error,
MD_PushStringF("Non-ASCII character \"%.*s\"", MD_StringExpand(byte_string)));
MD_PushErrorToList(&result.errors, error);
}break;
case MD_TokenKind_BrokenComment:
{
MD_Error *error = MD_MakeTokenError(string, bad_token, MD_MessageKind_Error,
MD_S8Lit("Unterminated comment"));
MD_PushErrorToList(&result.errors, error);
}break;
case MD_TokenKind_BrokenStringLiteral:
{
MD_Error *error = MD_MakeTokenError(string, bad_token, MD_MessageKind_Error,
MD_S8Lit("Unterminated string literal"));
MD_PushErrorToList(&result.errors, error);
}break;
}
MD_String8 byte_string = MD_JoinStringList(bytes, MD_S8Lit(" "));
MD_Error *error = MD_MakeTokenError(string, bad_token, MD_MessageKind_Error,
MD_PushStringF("Non-ASCII character \"%.*s\"", MD_StringExpand(byte_string)));
MD_PushErrorToList(&result.errors, error);
goto retry;
}
}