Fossil SCM

Update to the latest pikchr with improved syntax error context display.

drh 2021-01-31 17:57 trunk
Commit f36613647226986be79a3eeb32ef01bd895aa00b79c0803374448952566822c5
1 file changed +14 -3
+14 -3
--- src/pikchr.c
+++ src/pikchr.c
@@ -5028,13 +5028,23 @@
50285028
int iStart; /* Start position of the error context */
50295029
int iEnd; /* End position of the error context */
50305030
int iLineno; /* Line number of the error */
50315031
int iFirstLineno; /* Line number of start of error context */
50325032
int i; /* Loop counter */
5033
+ int iBump = 0; /* Bump the location of the error cursor */
50335034
char zLineno[20]; /* Buffer in which to generate line numbers */
50345035
50355036
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
+ }
50365046
iLineno = 1;
50375047
for(i=0; i<iErrPt; i++){
50385048
if( p->sIn.z[i]=='\n' ){
50395049
iLineno++;
50405050
}
@@ -5056,11 +5066,11 @@
50565066
pik_append_errtxt(p, p->sIn.z+iStart, i-iStart);
50575067
iStart = i+1;
50585068
pik_append(p, "\n", 1);
50595069
}
50605070
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); }
50625072
for(i=0; i<(int)pErr->n; i++) pik_append(p, "^", 1);
50635073
pik_append(p, "\n", 1);
50645074
}
50655075
50665076
@@ -7646,11 +7656,12 @@
76467656
#endif
76477657
pik_tokenize(&s, &s.sIn, &sParse, 0);
76487658
if( s.nErr==0 ){
76497659
PToken token;
76507660
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;
76527663
pik_parser(&sParse, 0, token);
76537664
}
76547665
pik_parserFinalize(&sParse);
76557666
if( s.zOut==0 && s.nErr==0 ){
76567667
pik_append(&s, "<!-- empty pikchr diagram -->\n", -1);
@@ -7929,6 +7940,6 @@
79297940
79307941
79317942
#endif /* PIKCHR_TCL */
79327943
79337944
7934
-#line 7959 "pikchr.c"
7945
+#line 7970 "pikchr.c"
79357946
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button