Fossil SCM
Update to the latest pikchr with improved syntax error context display.
Commit
f36613647226986be79a3eeb32ef01bd895aa00b79c0803374448952566822c5
Parent
70964869af78b2a…
1 file changed
+14
-3
+14
-3
| --- src/pikchr.c | ||
| +++ src/pikchr.c | ||
| @@ -5028,13 +5028,23 @@ | ||
| 5028 | 5028 | int iStart; /* Start position of the error context */ |
| 5029 | 5029 | int iEnd; /* End position of the error context */ |
| 5030 | 5030 | int iLineno; /* Line number of the error */ |
| 5031 | 5031 | int iFirstLineno; /* Line number of start of error context */ |
| 5032 | 5032 | int i; /* Loop counter */ |
| 5033 | + int iBump = 0; /* Bump the location of the error cursor */ | |
| 5033 | 5034 | char zLineno[20]; /* Buffer in which to generate line numbers */ |
| 5034 | 5035 | |
| 5035 | 5036 | iErrPt = (int)(pErr->z - p->sIn.z); |
| 5037 | + if( iErrPt>=p->sIn.n ){ | |
| 5038 | + iErrPt = p->sIn.n-1; | |
| 5039 | + iBump = 1; | |
| 5040 | + }else{ | |
| 5041 | + while( iErrPt>0 && (p->sIn.z[iErrPt]=='\n' || p->sIn.z[iErrPt]=='\r') ){ | |
| 5042 | + iErrPt--; | |
| 5043 | + iBump = 1; | |
| 5044 | + } | |
| 5045 | + } | |
| 5036 | 5046 | iLineno = 1; |
| 5037 | 5047 | for(i=0; i<iErrPt; i++){ |
| 5038 | 5048 | if( p->sIn.z[i]=='\n' ){ |
| 5039 | 5049 | iLineno++; |
| 5040 | 5050 | } |
| @@ -5056,11 +5066,11 @@ | ||
| 5056 | 5066 | pik_append_errtxt(p, p->sIn.z+iStart, i-iStart); |
| 5057 | 5067 | iStart = i+1; |
| 5058 | 5068 | pik_append(p, "\n", 1); |
| 5059 | 5069 | } |
| 5060 | 5070 | for(iErrCol=0, i=iErrPt; i>0 && p->sIn.z[i]!='\n'; iErrCol++, i--){} |
| 5061 | - for(i=0; i<iErrCol+11; i++){ pik_append(p, " ", 1); } | |
| 5071 | + for(i=0; i<iErrCol+11+iBump; i++){ pik_append(p, " ", 1); } | |
| 5062 | 5072 | for(i=0; i<(int)pErr->n; i++) pik_append(p, "^", 1); |
| 5063 | 5073 | pik_append(p, "\n", 1); |
| 5064 | 5074 | } |
| 5065 | 5075 | |
| 5066 | 5076 | |
| @@ -7646,11 +7656,12 @@ | ||
| 7646 | 7656 | #endif |
| 7647 | 7657 | pik_tokenize(&s, &s.sIn, &sParse, 0); |
| 7648 | 7658 | if( s.nErr==0 ){ |
| 7649 | 7659 | PToken token; |
| 7650 | 7660 | memset(&token,0,sizeof(token)); |
| 7651 | - token.z = zText; | |
| 7661 | + token.z = zText + (s.sIn.n>0 ? s.sIn.n-1 : 0); | |
| 7662 | + token.n = 1; | |
| 7652 | 7663 | pik_parser(&sParse, 0, token); |
| 7653 | 7664 | } |
| 7654 | 7665 | pik_parserFinalize(&sParse); |
| 7655 | 7666 | if( s.zOut==0 && s.nErr==0 ){ |
| 7656 | 7667 | pik_append(&s, "<!-- empty pikchr diagram -->\n", -1); |
| @@ -7929,6 +7940,6 @@ | ||
| 7929 | 7940 | |
| 7930 | 7941 | |
| 7931 | 7942 | #endif /* PIKCHR_TCL */ |
| 7932 | 7943 | |
| 7933 | 7944 | |
| 7934 | -#line 7959 "pikchr.c" | |
| 7945 | +#line 7970 "pikchr.c" | |
| 7935 | 7946 |
| --- src/pikchr.c | |
| +++ src/pikchr.c | |
| @@ -5028,13 +5028,23 @@ | |
| 5028 | int iStart; /* Start position of the error context */ |
| 5029 | int iEnd; /* End position of the error context */ |
| 5030 | int iLineno; /* Line number of the error */ |
| 5031 | int iFirstLineno; /* Line number of start of error context */ |
| 5032 | int i; /* Loop counter */ |
| 5033 | char zLineno[20]; /* Buffer in which to generate line numbers */ |
| 5034 | |
| 5035 | iErrPt = (int)(pErr->z - p->sIn.z); |
| 5036 | iLineno = 1; |
| 5037 | for(i=0; i<iErrPt; i++){ |
| 5038 | if( p->sIn.z[i]=='\n' ){ |
| 5039 | iLineno++; |
| 5040 | } |
| @@ -5056,11 +5066,11 @@ | |
| 5056 | pik_append_errtxt(p, p->sIn.z+iStart, i-iStart); |
| 5057 | iStart = i+1; |
| 5058 | pik_append(p, "\n", 1); |
| 5059 | } |
| 5060 | for(iErrCol=0, i=iErrPt; i>0 && p->sIn.z[i]!='\n'; iErrCol++, i--){} |
| 5061 | for(i=0; i<iErrCol+11; i++){ pik_append(p, " ", 1); } |
| 5062 | for(i=0; i<(int)pErr->n; i++) pik_append(p, "^", 1); |
| 5063 | pik_append(p, "\n", 1); |
| 5064 | } |
| 5065 | |
| 5066 | |
| @@ -7646,11 +7656,12 @@ | |
| 7646 | #endif |
| 7647 | pik_tokenize(&s, &s.sIn, &sParse, 0); |
| 7648 | if( s.nErr==0 ){ |
| 7649 | PToken token; |
| 7650 | memset(&token,0,sizeof(token)); |
| 7651 | token.z = zText; |
| 7652 | pik_parser(&sParse, 0, token); |
| 7653 | } |
| 7654 | pik_parserFinalize(&sParse); |
| 7655 | if( s.zOut==0 && s.nErr==0 ){ |
| 7656 | pik_append(&s, "<!-- empty pikchr diagram -->\n", -1); |
| @@ -7929,6 +7940,6 @@ | |
| 7929 | |
| 7930 | |
| 7931 | #endif /* PIKCHR_TCL */ |
| 7932 | |
| 7933 | |
| 7934 | #line 7959 "pikchr.c" |
| 7935 |
| --- src/pikchr.c | |
| +++ src/pikchr.c | |
| @@ -5028,13 +5028,23 @@ | |
| 5028 | int iStart; /* Start position of the error context */ |
| 5029 | int iEnd; /* End position of the error context */ |
| 5030 | int iLineno; /* Line number of the error */ |
| 5031 | int iFirstLineno; /* Line number of start of error context */ |
| 5032 | int i; /* Loop counter */ |
| 5033 | int iBump = 0; /* Bump the location of the error cursor */ |
| 5034 | char zLineno[20]; /* Buffer in which to generate line numbers */ |
| 5035 | |
| 5036 | iErrPt = (int)(pErr->z - p->sIn.z); |
| 5037 | if( iErrPt>=p->sIn.n ){ |
| 5038 | iErrPt = p->sIn.n-1; |
| 5039 | iBump = 1; |
| 5040 | }else{ |
| 5041 | while( iErrPt>0 && (p->sIn.z[iErrPt]=='\n' || p->sIn.z[iErrPt]=='\r') ){ |
| 5042 | iErrPt--; |
| 5043 | iBump = 1; |
| 5044 | } |
| 5045 | } |
| 5046 | iLineno = 1; |
| 5047 | for(i=0; i<iErrPt; i++){ |
| 5048 | if( p->sIn.z[i]=='\n' ){ |
| 5049 | iLineno++; |
| 5050 | } |
| @@ -5056,11 +5066,11 @@ | |
| 5066 | pik_append_errtxt(p, p->sIn.z+iStart, i-iStart); |
| 5067 | iStart = i+1; |
| 5068 | pik_append(p, "\n", 1); |
| 5069 | } |
| 5070 | for(iErrCol=0, i=iErrPt; i>0 && p->sIn.z[i]!='\n'; iErrCol++, i--){} |
| 5071 | for(i=0; i<iErrCol+11+iBump; i++){ pik_append(p, " ", 1); } |
| 5072 | for(i=0; i<(int)pErr->n; i++) pik_append(p, "^", 1); |
| 5073 | pik_append(p, "\n", 1); |
| 5074 | } |
| 5075 | |
| 5076 | |
| @@ -7646,11 +7656,12 @@ | |
| 7656 | #endif |
| 7657 | pik_tokenize(&s, &s.sIn, &sParse, 0); |
| 7658 | if( s.nErr==0 ){ |
| 7659 | PToken token; |
| 7660 | memset(&token,0,sizeof(token)); |
| 7661 | token.z = zText + (s.sIn.n>0 ? s.sIn.n-1 : 0); |
| 7662 | token.n = 1; |
| 7663 | pik_parser(&sParse, 0, token); |
| 7664 | } |
| 7665 | pik_parserFinalize(&sParse); |
| 7666 | if( s.zOut==0 && s.nErr==0 ){ |
| 7667 | pik_append(&s, "<!-- empty pikchr diagram -->\n", -1); |
| @@ -7929,6 +7940,6 @@ | |
| 7940 | |
| 7941 | |
| 7942 | #endif /* PIKCHR_TCL */ |
| 7943 | |
| 7944 | |
| 7945 | #line 7970 "pikchr.c" |
| 7946 |