]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
Added another diagnostic and test, also fixed alginment in testsuite.
authorDale Weiler <killfieldengine@gmail.com>
Fri, 31 May 2013 06:48:40 +0000 (06:48 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Fri, 31 May 2013 06:48:40 +0000 (06:48 +0000)
diag.c
gmqcc.h
parser.c
test.c
tests/diag/expend.qc [new file with mode: 0644]
tests/diag/expend.tmpl [new file with mode: 0644]

diff --git a/diag.c b/diag.c
index 83b8f993104f8922f25e1b31938d8f2826740ad5..81c831ed7011bcd174896671b4ff87d69ceb3548 100644 (file)
--- a/diag.c
+++ b/diag.c
@@ -151,6 +151,15 @@ static void diagnostic_feed(const char *file, size_t line, size_t column, size_t
     }
     
     switch (diagnostic) {
+        case DIAGNOSTIC_EXPECTED_END:
+            for (; len < vec_size(vec_last(read)->values); len++)
+                space += strlen(vec_last(read)->values[len]);
+            
+            /* +/- 1 because of the ^ */
+            len   = space  - column - 1;
+            space = column          + 1;
+            break;
+            
         case DIAGNOSTIC_EXPRESSION_CASE:
         case DIAGNOSTIC_SEMICOLON:
             for (; len < vec_size(vec_last(read)->values); len++)
@@ -243,20 +252,14 @@ void diagnostic_calculate(const char *file, size_t line, size_t column, size_t d
          * enable the marker (to show where it's missing).
          */
         case DIAGNOSTIC_SEMICOLON:
-            linebeg++;
-            marker = true;
-            break;
-            
         case DIAGNOSTIC_EXPRESSION_CASE:
+        case DIAGNOSTIC_EXPECTED_END:
             linebeg++;
             marker = true;
             break;
-
-        case DIAGNOSTIC_EXPECTED:
-            marker = true;
-            break;
-            
+        
         case DIAGNOSTIC_UNEXPECTED_IDENT:
+        case DIAGNOSTIC_EXPECTED:
             marker = true;
             break;
 
diff --git a/gmqcc.h b/gmqcc.h
index 1882a30043c38b5137cb2897caf92ad47dbd5069..622f3033553e4b1875dab65c1ccf164af661e32d 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -1035,7 +1035,8 @@ enum {
     DIAGNOSTIC_SEMICOLON,
     DIAGNOSTIC_EXPRESSION_CASE,
     DIAGNOSTIC_UNEXPECTED_IDENT,
-    DIAGNOSTIC_EXPECTED
+    DIAGNOSTIC_EXPECTED,
+    DIAGNOSTIC_EXPECTED_END
 };
 
 void diagnostic_destroy();
index 5deef696157bf851c8f3f59049a06f5ffa5f28dc..a4abb0eddaef290862d57abb2651cf10c794bb99 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -2220,6 +2220,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
                 }
             }
             if (!concatenated) {
+                parser->diagnostic = DIAGNOSTIC_EXPECTED_END;
                 parseerror(parser, "expected operator or end of statement");
                 goto onerr;
             }
diff --git a/test.c b/test.c
index 1b0bcbb27f2171e73efd719629c75e19588efa49..6899ff7da84866be2b1eeb562ce58e9f7932e6d4 100644 (file)
--- a/test.c
+++ b/test.c
@@ -1245,7 +1245,7 @@ static void task_schedualize(size_t *pad) {
              */
             if (vec_size(match) > vec_size(task_tasks[i].tmpl->comparematch)) {
                 for (d = 0; d < vec_size(match) - vec_size(task_tasks[i].tmpl->comparematch); d++) {
-                    con_out("        Expected: Nothing                                   | Got: \"%s\"\n",
+                    con_out("        Expected: Nothing                                                       | Got: \"%s\"\n",
                         match[d + vec_size(task_tasks[i].tmpl->comparematch)]
                     );
                 }
diff --git a/tests/diag/expend.qc b/tests/diag/expend.qc
new file mode 100644 (file)
index 0000000..dc96421
--- /dev/null
@@ -0,0 +1 @@
+const vector foo = '1 2 3'
diff --git a/tests/diag/expend.tmpl b/tests/diag/expend.tmpl
new file mode 100644 (file)
index 0000000..af926b6
--- /dev/null
@@ -0,0 +1,9 @@
+I: expend.qc
+D: expected end of statement
+T: -diagnostic
+C: -std=gmqcc
+M: expected operator or end of statement
+M:     2: const vector foo = '1 2 3'
+M:                           ~~~~~~~^
+M: unexpected eof
+