diff --git a/src/tokenize.c b/src/tokenize.c index 3e6b53f1..47411b23 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -45,7 +45,7 @@ static char read_byte(struct State *st) { // Use the zero byte to represent end of file. if (c == '\0') - fail_with_error(st->location, "source file contains a zero byte"); // TODO: test this + fail_with_error(st->location, "source file contains a zero byte"); if (c == EOF) { assert(!ferror(st->f)); return '\0'; @@ -220,9 +220,10 @@ static bool is_keyword(const char *s) // - self-hosted compiler // - syntax documentation "import", "def", "declare", "class", "union", "enum", "global", - "return", "if", "elif", "else", "while", "for", "pass", "break", "continue", - "True", "False", "None", "NULL", "void", "noreturn", - "and", "or", "not", "self", "as", "sizeof", "assert", + "return", "if", "elif", "else", "while", "for", "break", "continue", + "True", "False", "NULL", "self", + "and", "or", "not", "as", "sizeof", "assert", "pass", + "void", "noreturn", "bool", "byte", "short", "int", "long", "float", "double", }; for (const char **kw = &keywords[0]; kw < &keywords[sizeof(keywords)/sizeof(keywords[0])]; kw++) @@ -295,7 +296,6 @@ static char *read_string(struct State *st, char quote, int *len) case '\n': // \ at end of line, string continues on next line if (quote == '\'') { - // TODO: tests st->location.lineno--; // to get error at the correct line number goto missing_end_quote; } @@ -321,7 +321,6 @@ static char *read_string(struct State *st, char quote, int *len) return result.ptr; missing_end_quote: - // TODO: tests if (quote == '"') fail_with_error(st->location, "missing \" to end the string"); else diff --git a/tests/other_errors/source_file_contain_zero_byte.jou b/tests/other_errors/source_file_contain_zero_byte.jou new file mode 100644 index 00000000..c8259c7c Binary files /dev/null and b/tests/other_errors/source_file_contain_zero_byte.jou differ diff --git a/tests/syntax_error/missing_end_quote_in_byte.jou b/tests/syntax_error/missing_end_quote_in_byte.jou new file mode 100644 index 00000000..52fe3caf --- /dev/null +++ b/tests/syntax_error/missing_end_quote_in_byte.jou @@ -0,0 +1,6 @@ +import "stdlib/io.jou" + +# Output: compiler error in file "tests/syntax_error/missing_end_quote_in_byte.jou", line 5: missing ' to end the byte literal +def main() -> int: + printf('?) + return 0 diff --git a/tests/syntax_error/missing_end_quote_in_string.jou b/tests/syntax_error/missing_end_quote_in_string.jou new file mode 100644 index 00000000..a860da4c --- /dev/null +++ b/tests/syntax_error/missing_end_quote_in_string.jou @@ -0,0 +1,6 @@ +import "stdlib/io.jou" + +# Output: compiler error in file "tests/syntax_error/missing_end_quote_in_string.jou", line 5: missing " to end the string +def main() -> int: + printf("Hello) + return 0 diff --git a/tests/syntax_error/string_continue_on_next_line.jou b/tests/syntax_error/string_continue_on_next_line.jou new file mode 100644 index 00000000..c9fc5d5d --- /dev/null +++ b/tests/syntax_error/string_continue_on_next_line.jou @@ -0,0 +1,8 @@ +import "stdlib/io.jou" + +# Output: compiler error in file "tests/syntax_error/string_continue_on_next_line.jou", line 5: missing ' to end the byte literal +def main() -> int: + a = '\ + 't\'' + printf(a) + return 0