Fossil SCM

More fixes to TH1 integer and expression processing.

mistachkin 2015-04-02 20:15 trunk
Commit fc248d66aad2c2336e4fddc8a4cca7e9c26c422d
2 files changed +17 -6 +40
+17 -6
--- src/th.c
+++ src/th.c
@@ -2227,18 +2227,29 @@
22272227
default: {
22282228
int j;
22292229
const char *zOp;
22302230
for(j=0; (zOp=aOperator[j].zOp); j++){
22312231
int nOp = aOperator[j].nOp;
2232
+ int nRemain = nExpr - i;
22322233
int isMatch = 0;
2233
- if( (nExpr-i)>=nOp && 0==memcmp(zOp, &zExpr[i], nOp) ){
2234
+ if( nRemain>=nOp && 0==memcmp(zOp, &zExpr[i], nOp) ){
22342235
isMatch = 1;
22352236
}
2236
- if( isMatch && aOperator[j].eOp==OP_OPEN_BRACKET ){
2237
- nNest++;
2238
- }else if( isMatch && aOperator[j].eOp==OP_CLOSE_BRACKET ){
2239
- nNest--;
2237
+ if( isMatch ){
2238
+ if( aOperator[j].eOp==OP_CLOSE_BRACKET ){
2239
+ nNest--;
2240
+ }else if( nRemain>nOp ){
2241
+ if( aOperator[j].eOp==OP_OPEN_BRACKET ){
2242
+ nNest++;
2243
+ }
2244
+ }else{
2245
+ /*
2246
+ ** This is not really a match because this operator cannot
2247
+ ** legally appear at the end of the string.
2248
+ */
2249
+ isMatch = 0;
2250
+ }
22402251
}
22412252
if( nToken>0 && aOperator[j].iPrecedence==1 ){
22422253
Expr *pPrev = apToken[nToken-1];
22432254
if( !pPrev->pOp || pPrev->pOp->eOp==OP_CLOSE_BRACKET ){
22442255
continue;
@@ -2649,11 +2660,11 @@
26492660
}
26502661
26512662
if( n>1 && (z[0]=='-' || z[0]=='+') ){
26522663
i = 1;
26532664
}
2654
- if( n>2 && z[i]=='0'){
2665
+ if( (n-i)>2 && z[i]=='0' ){
26552666
if( z[i+1]=='x' || z[i+1]=='X' ){
26562667
i += 2;
26572668
base = 16;
26582669
isdigit = th_ishexdig;
26592670
}else if( z[i+1]=='o' || z[i+1]=='O' ){
26602671
--- src/th.c
+++ src/th.c
@@ -2227,18 +2227,29 @@
2227 default: {
2228 int j;
2229 const char *zOp;
2230 for(j=0; (zOp=aOperator[j].zOp); j++){
2231 int nOp = aOperator[j].nOp;
 
2232 int isMatch = 0;
2233 if( (nExpr-i)>=nOp && 0==memcmp(zOp, &zExpr[i], nOp) ){
2234 isMatch = 1;
2235 }
2236 if( isMatch && aOperator[j].eOp==OP_OPEN_BRACKET ){
2237 nNest++;
2238 }else if( isMatch && aOperator[j].eOp==OP_CLOSE_BRACKET ){
2239 nNest--;
 
 
 
 
 
 
 
 
 
 
2240 }
2241 if( nToken>0 && aOperator[j].iPrecedence==1 ){
2242 Expr *pPrev = apToken[nToken-1];
2243 if( !pPrev->pOp || pPrev->pOp->eOp==OP_CLOSE_BRACKET ){
2244 continue;
@@ -2649,11 +2660,11 @@
2649 }
2650
2651 if( n>1 && (z[0]=='-' || z[0]=='+') ){
2652 i = 1;
2653 }
2654 if( n>2 && z[i]=='0'){
2655 if( z[i+1]=='x' || z[i+1]=='X' ){
2656 i += 2;
2657 base = 16;
2658 isdigit = th_ishexdig;
2659 }else if( z[i+1]=='o' || z[i+1]=='O' ){
2660
--- src/th.c
+++ src/th.c
@@ -2227,18 +2227,29 @@
2227 default: {
2228 int j;
2229 const char *zOp;
2230 for(j=0; (zOp=aOperator[j].zOp); j++){
2231 int nOp = aOperator[j].nOp;
2232 int nRemain = nExpr - i;
2233 int isMatch = 0;
2234 if( nRemain>=nOp && 0==memcmp(zOp, &zExpr[i], nOp) ){
2235 isMatch = 1;
2236 }
2237 if( isMatch ){
2238 if( aOperator[j].eOp==OP_CLOSE_BRACKET ){
2239 nNest--;
2240 }else if( nRemain>nOp ){
2241 if( aOperator[j].eOp==OP_OPEN_BRACKET ){
2242 nNest++;
2243 }
2244 }else{
2245 /*
2246 ** This is not really a match because this operator cannot
2247 ** legally appear at the end of the string.
2248 */
2249 isMatch = 0;
2250 }
2251 }
2252 if( nToken>0 && aOperator[j].iPrecedence==1 ){
2253 Expr *pPrev = apToken[nToken-1];
2254 if( !pPrev->pOp || pPrev->pOp->eOp==OP_CLOSE_BRACKET ){
2255 continue;
@@ -2649,11 +2660,11 @@
2660 }
2661
2662 if( n>1 && (z[0]=='-' || z[0]=='+') ){
2663 i = 1;
2664 }
2665 if( (n-i)>2 && z[i]=='0' ){
2666 if( z[i+1]=='x' || z[i+1]=='X' ){
2667 i += 2;
2668 base = 16;
2669 isdigit = th_ishexdig;
2670 }else if( z[i+1]=='o' || z[i+1]=='O' ){
2671
--- test/th1.test
+++ test/th1.test
@@ -507,10 +507,50 @@
507507
508508
###############################################################################
509509
510510
fossil test-th-eval "expr (((1)*2)*2)"
511511
test th1-expr-41 {$RESULT eq {4}}
512
+
513
+###############################################################################
514
+
515
+fossil test-th-eval "expr +"
516
+test th1-expr-42 {$RESULT eq {TH_ERROR: syntax error in expression: "+"}}
517
+
518
+###############################################################################
519
+
520
+fossil test-th-eval "expr -"
521
+test th1-expr-43 {$RESULT eq {TH_ERROR: syntax error in expression: "-"}}
522
+
523
+###############################################################################
524
+
525
+fossil test-th-eval "expr ++"
526
+test th1-expr-44 {$RESULT eq {TH_ERROR: syntax error in expression: "++"}}
527
+
528
+###############################################################################
529
+
530
+fossil test-th-eval "expr --"
531
+test th1-expr-45 {$RESULT eq {TH_ERROR: syntax error in expression: "--"}}
532
+
533
+###############################################################################
534
+
535
+fossil test-th-eval "lindex list +"
536
+test th1-expr-46 {$RESULT eq {TH_ERROR: expected integer, got: "+"}}
537
+
538
+###############################################################################
539
+
540
+fossil test-th-eval "lindex list -"
541
+test th1-expr-47 {$RESULT eq {TH_ERROR: expected integer, got: "-"}}
542
+
543
+###############################################################################
544
+
545
+fossil test-th-eval "lindex list +0x"
546
+test th1-expr-48 {$RESULT eq {TH_ERROR: expected integer, got: "+0x"}}
547
+
548
+###############################################################################
549
+
550
+fossil test-th-eval "lindex list -0x"
551
+test th1-expr-49 {$RESULT eq {TH_ERROR: expected integer, got: "-0x"}}
512552
513553
###############################################################################
514554
515555
fossil test-th-eval "checkout 1"; # NOTE: Assumes running "in tree".
516556
test th1-checkout-1 {[string length $RESULT] > 0}
517557
--- test/th1.test
+++ test/th1.test
@@ -507,10 +507,50 @@
507
508 ###############################################################################
509
510 fossil test-th-eval "expr (((1)*2)*2)"
511 test th1-expr-41 {$RESULT eq {4}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
512
513 ###############################################################################
514
515 fossil test-th-eval "checkout 1"; # NOTE: Assumes running "in tree".
516 test th1-checkout-1 {[string length $RESULT] > 0}
517
--- test/th1.test
+++ test/th1.test
@@ -507,10 +507,50 @@
507
508 ###############################################################################
509
510 fossil test-th-eval "expr (((1)*2)*2)"
511 test th1-expr-41 {$RESULT eq {4}}
512
513 ###############################################################################
514
515 fossil test-th-eval "expr +"
516 test th1-expr-42 {$RESULT eq {TH_ERROR: syntax error in expression: "+"}}
517
518 ###############################################################################
519
520 fossil test-th-eval "expr -"
521 test th1-expr-43 {$RESULT eq {TH_ERROR: syntax error in expression: "-"}}
522
523 ###############################################################################
524
525 fossil test-th-eval "expr ++"
526 test th1-expr-44 {$RESULT eq {TH_ERROR: syntax error in expression: "++"}}
527
528 ###############################################################################
529
530 fossil test-th-eval "expr --"
531 test th1-expr-45 {$RESULT eq {TH_ERROR: syntax error in expression: "--"}}
532
533 ###############################################################################
534
535 fossil test-th-eval "lindex list +"
536 test th1-expr-46 {$RESULT eq {TH_ERROR: expected integer, got: "+"}}
537
538 ###############################################################################
539
540 fossil test-th-eval "lindex list -"
541 test th1-expr-47 {$RESULT eq {TH_ERROR: expected integer, got: "-"}}
542
543 ###############################################################################
544
545 fossil test-th-eval "lindex list +0x"
546 test th1-expr-48 {$RESULT eq {TH_ERROR: expected integer, got: "+0x"}}
547
548 ###############################################################################
549
550 fossil test-th-eval "lindex list -0x"
551 test th1-expr-49 {$RESULT eq {TH_ERROR: expected integer, got: "-0x"}}
552
553 ###############################################################################
554
555 fossil test-th-eval "checkout 1"; # NOTE: Assumes running "in tree".
556 test th1-checkout-1 {[string length $RESULT] > 0}
557

Keyboard Shortcuts

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