diff --git a/.editorconfig b/.editorconfig index 71c40829..b0e4dabd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -19,3 +19,7 @@ indent_size = 3 [tests/syntax_error/indentation_not4.jou] indent_size = 2 + +[tests/should_succeed/newline_and_space_at_eof.jou] +trim_trailing_whitespace = false +indent_size = unset diff --git a/self_hosted/tokenizer.jou b/self_hosted/tokenizer.jou index 7edc1fa3..001bc310 100644 --- a/self_hosted/tokenizer.jou +++ b/self_hosted/tokenizer.jou @@ -276,6 +276,7 @@ class Tokenizer: if c == '\\': after_backslash = self->read_byte() if after_backslash == '\0' or after_backslash == '\n': + self->location.lineno-- fail(self->location, "missing ' to end the byte literal") elif after_backslash == 'n': c = '\n' diff --git a/src/tokenize.c b/src/tokenize.c index c7d6cbed..c744617c 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -126,7 +126,6 @@ static int read_indentation_level_for_newline_token(struct State *st) consume_rest_of_line(st); else if (c == '\0') { // Ignore newline+spaces at end of file. Do not validate 4 spaces. - // TODO: test case return 0; } else { unread_byte(st, c); @@ -295,7 +294,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 +319,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/src/typecheck.c b/src/typecheck.c index 2f3069c7..a7d034e3 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -87,7 +87,6 @@ static const char *short_type_description(const Type *t) case TYPE_ARRAY: return "an array type"; case TYPE_BOOL: - // TODO: Is it possible to get this in an error message? return "the built-in bool type"; } } diff --git a/tests/already_exists_error/bool.jou b/tests/already_exists_error/bool.jou new file mode 100644 index 00000000..38f92a5d --- /dev/null +++ b/tests/already_exists_error/bool.jou @@ -0,0 +1,2 @@ +def foo() -> None: + x = True.asdf() # Error: type bool does not have any methods because it is the built-in bool type, not a class diff --git a/tests/should_succeed/newline_and_space_at_eof.jou b/tests/should_succeed/newline_and_space_at_eof.jou new file mode 100644 index 00000000..5a847337 --- /dev/null +++ b/tests/should_succeed/newline_and_space_at_eof.jou @@ -0,0 +1,3 @@ +def main() -> int: + return 0 + \ No newline at end of file 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..3483fa58 --- /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..991f6b74 --- /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..925e19d4 --- /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 6: missing " to end the string +def main() -> int: + a = "\ + asdf + printf(a) + return 0