lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] [4/4] git commit: Add line number to CFC parser error message
Date Sat, 22 Mar 2014 14:46:21 GMT
Add line number to CFC parser error message

This sometimes reports the line following the actual syntax error but
it's a lot better than no line numbers at all.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/76f9b9a9
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/76f9b9a9
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/76f9b9a9

Branch: refs/heads/master
Commit: 76f9b9a95c6dbe7817512b0f3862ca71b08a9aaf
Parents: 6a7b05b
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Sat Mar 22 15:11:19 2014 +0100
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Sat Mar 22 15:45:22 2014 +0100

----------------------------------------------------------------------
 compiler/src/CFCHierarchy.c   |  3 ++-
 compiler/src/CFCParseHeader.y |  2 ++
 compiler/src/CFCParser.c      | 13 +++++++++++++
 compiler/src/CFCParser.h      |  5 +++++
 4 files changed, 22 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/76f9b9a9/compiler/src/CFCHierarchy.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCHierarchy.c b/compiler/src/CFCHierarchy.c
index c5fcac5..ca7dba5 100644
--- a/compiler/src/CFCHierarchy.c
+++ b/compiler/src/CFCHierarchy.c
@@ -350,7 +350,8 @@ S_parse_cf_files(CFCHierarchy *self, const char *source_dir, int is_included)
{
         CFCFile *file = CFCParser_parse_file(self->parser, content, file_spec);
         FREEMEM(content);
         if (!file) {
-            CFCUtil_die("parser error for %s", source_path);
+            int lineno = CFCParser_get_lineno(self->parser);
+            CFCUtil_die("%s:%d: parser error", source_path, lineno);
         }
 
         // Add parsed file to pool if it's from a required parcel.

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/76f9b9a9/compiler/src/CFCParseHeader.y
----------------------------------------------------------------------
diff --git a/compiler/src/CFCParseHeader.y b/compiler/src/CFCParseHeader.y
index 1cc84c2..5528998 100644
--- a/compiler/src/CFCParseHeader.y
+++ b/compiler/src/CFCParseHeader.y
@@ -27,6 +27,7 @@
 #include <assert.h>
 #include <stdlib.h>
 #include "CFC.h"
+#include "CFCLexHeader.h"
 #ifndef true
   #define true 1
   #define false 0
@@ -221,6 +222,7 @@ S_new_type(CFCParser *state, int flags, char *type_name,
     (void)yymajor;
     (void)yyminor;
     CFCParser_set_errors(state, true);
+    CFCParser_set_lineno(state, yyget_lineno());
 }
 
 %type result                            {CFCBase*}

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/76f9b9a9/compiler/src/CFCParser.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCParser.c b/compiler/src/CFCParser.c
index 6e93ad7..9cb9d6a 100644
--- a/compiler/src/CFCParser.c
+++ b/compiler/src/CFCParser.c
@@ -38,6 +38,7 @@ struct CFCParser {
     void *header_parser;
     struct CFCBase *result;
     int errors;
+    int lineno;
     char *class_name;
     char *class_cnick;
     CFCFileSpec *file_spec;
@@ -65,6 +66,7 @@ CFCParser_init(CFCParser *self) {
     }
     self->result       = NULL;
     self->errors       = false;
+    self->lineno       = 0;
     self->class_name   = NULL;
     self->class_cnick  = NULL;
     self->file_spec    = NULL;
@@ -98,6 +100,7 @@ CFCParser_parse(CFCParser *self, const char *string) {
 
     // Zero out, then parse.
     self->errors = false;
+    self->lineno = 0;
     YY_BUFFER_STATE buffer = yy_scan_bytes(string, (int)strlen(string));
     yylex();
     yy_delete_buffer(buffer);
@@ -153,6 +156,16 @@ CFCParser_set_errors(CFCParser *self, int errors) {
 }
 
 void
+CFCParser_set_lineno(CFCParser *self, int lineno) {
+    self->lineno = lineno;
+}
+
+int
+CFCParser_get_lineno(CFCParser *self) {
+    return self->lineno;
+}
+
+void
 CFCParser_set_parcel(CFCParser *self, CFCParcel *parcel) {
     CFCBase_incref((CFCBase*)parcel);
     CFCBase_decref((CFCBase*)self->parcel);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/76f9b9a9/compiler/src/CFCParser.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCParser.h b/compiler/src/CFCParser.h
index 19300cf..8b250a3 100644
--- a/compiler/src/CFCParser.h
+++ b/compiler/src/CFCParser.h
@@ -66,6 +66,11 @@ void
 CFCParser_set_errors(CFCParser *self, int errors);
 
 void
+CFCParser_set_lineno(CFCParser *self, int lineno);
+
+int
+CFCParser_get_lineno(CFCParser *self);
+void
 CFCParser_set_text(CFCParser *self, const char *text, size_t len);
 
 const char*


Mime
View raw message