]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
reworked error location translator function to find the file by path in list of open...
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 26 Mar 2019 15:32:07 +0000 (11:32 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 26 Mar 2019 15:32:07 +0000 (11:32 -0400)
example.src
source/lex.c

index 12c6dfbda9b5116683f731dbbde6f3407ae56e10..6200d0d6369c418a697e7dd19087118b326530e7 100644 (file)
@@ -2,9 +2,9 @@ require ("fmt")
 provide (main)
 
 let const_true bool = true
-#let const_false bool = false
-#let const_uint int = 123
-#let const_string string = "
+let const_false bool = false
+let const_uint int = 123
+let const_string string = ""
 
 var var_true bool = true
 var var_false bool = false
index c150f9408e13ed1051ce77e2d8289ef1edeccdbf..de5bba9eaf9e3720c13d5b6a36f25a0f2df288a6 100644 (file)
@@ -195,6 +195,7 @@ void lexfile(Parser* ctx, char* path) {
 }
 
 void lex(Parser* ctx) {
+    ctx->tok.file = ctx->file->path;
     ctx->tok.type = T_NONE;
     while (ctx->tok.type == T_NONE) {
         if (!ctx->file) {
@@ -214,9 +215,21 @@ void lex(Parser* ctx) {
     }
 }
 
+static LexFile* get_file(Parser* p, char* path) {
+    LexFile* lf = p->file;
+    while (lf && strcmp(lf->path, path))
+        lf = lf->next;
+    if (!lf) {
+        lf = p->done;
+        while (lf && strcmp(lf->path, path))
+            lf = lf->next;
+    }
+    return lf;
+}
+
 void lexprintpos(Parser* p, FILE* file, Tok* tok) {
     size_t line = 1, col = 1;
-    char* data = p->file->fbeg;
+    char* data = get_file(p, tok->file)->fbeg;
     char* end = data + tok->offset;
     for (; *data && data < end; data++) {
         if (*data == '\n') {
@@ -226,5 +239,5 @@ void lexprintpos(Parser* p, FILE* file, Tok* tok) {
             col++;
         }
     }
-    fprintf(file, "%s:%zu:%zu:", p->file->path, line, col);
+    fprintf(file, "%s:%zu:%zu:", tok->file, line, col);
 }