From 30576a7229aad4e3134f06cd26a17c172824f57f Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Fri, 31 May 2013 05:54:16 +0000 Subject: [PATCH] Diagnostic tests for expected semicolon situations. --- parser.c | 7 ++++--- tests/diag/semicolon.qc | 3 +++ tests/diag/semicolon.tmpl | 7 +++++++ tests/diag/semienum.qc | 3 +++ tests/diag/semienum.tmpl | 8 ++++++++ 5 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 tests/diag/semicolon.qc create mode 100644 tests/diag/semicolon.tmpl create mode 100644 tests/diag/semienum.qc create mode 100644 tests/diag/semienum.tmpl diff --git a/parser.c b/parser.c index 063c6d2..d0aaf4a 100644 --- a/parser.c +++ b/parser.c @@ -3946,6 +3946,7 @@ static bool parse_enum(parser_t *parser) } if (!parser_next(parser) || parser->tok != ';') { + parser->diagnostic = DIAGNOSTIC_SEMICOLON; parseerror(parser, "expected semicolon after enumeration"); goto onerror; } @@ -6165,10 +6166,10 @@ static bool parser_compile(parser_t *parser) while (parser->tok != TOKEN_EOF && parser->tok < TOKEN_ERROR) { if (!parser_global_statement(parser)) { - if (parser->tok == TOKEN_EOF) + parser->diagnostic = DIAGNOSTIC_NULL; + if (parser->tok == TOKEN_EOF) { parseerror(parser, "unexpected eof"); - else if (compile_errors) { - parser->diagnostic = DIAGNOSTIC_NULL; + } else if (compile_errors) { parseerror(parser, "there have been errors, bailing out"); } lex_close(parser->lex); diff --git a/tests/diag/semicolon.qc b/tests/diag/semicolon.qc new file mode 100644 index 0000000..3f0b591 --- /dev/null +++ b/tests/diag/semicolon.qc @@ -0,0 +1,3 @@ +void foo() { + float a +} diff --git a/tests/diag/semicolon.tmpl b/tests/diag/semicolon.tmpl new file mode 100644 index 0000000..16c0b3b --- /dev/null +++ b/tests/diag/semicolon.tmpl @@ -0,0 +1,7 @@ +I: semicolon.qc +D: test diagnostics: expected semicolon +T: -diagnostic +C: -std=gmqcc +M: expected semicolon +M: 3: float a +M: ~^ diff --git a/tests/diag/semienum.qc b/tests/diag/semienum.qc new file mode 100644 index 0000000..143de80 --- /dev/null +++ b/tests/diag/semienum.qc @@ -0,0 +1,3 @@ +enum { + A, B +} diff --git a/tests/diag/semienum.tmpl b/tests/diag/semienum.tmpl new file mode 100644 index 0000000..954e257 --- /dev/null +++ b/tests/diag/semienum.tmpl @@ -0,0 +1,8 @@ +I: semienum.qc +D: test diagnostics: expected semicolon (enum) +T: -diagnostic +C: -std=gmqcc +M: expected semicolon after enumeration +M: 4: } +M: ~^ +M: unexpected eof -- 2.39.5