Diff
Not logged in

Differences From Artifact [9751c1054b6569e6]:

To Artifact [f6a85fc83dd90cb0]:


297 } 297 } 298 scope(exit) lex.popFront; 298 scope(exit) lex.popFront; 299 return new Var(pos, lex.front.str); 299 return new Var(pos, lex.front.str); 300 } 300 } 301 301 302 AST parseIfAfterIf(LexPosition pos) 302 AST parseIfAfterIf(LexPosition pos) 303 { 303 { 304 eat("(", "after if"); < 305 auto cond = E(0); 304 auto cond = E(0); > 305 auto thenPos = currentPosition(); > 306 if(!tryEat(":")) { 306 eat(")", "after if condition"); | 307 eat("then", "after if condition"); 307 auto thenPos = lex.front.pos; < 308 AST th; < 309 if( tryEat("{") ) { | 308 tryEat(":"); 310 th = Body(); < 311 eat("}", "after if-then body"); < 312 } else { < 313 th = E(0); < 314 } 309 } > 310 AST th = E(0); 315 auto el = doNothingExpression(); 311 auto el = doNothingExpression(); 316 auto elsePos = (lex.empty ? LexPosition.dummy : lex.front.pos); | 312 auto elsePos = currentPosition(); 317 if( tryEat("else") ) | 313 if( tryEat("else") ) { 318 if( tryEat("{") ) { | 314 tryEat(":"); 319 el = Body(); < 320 eat("}", "after else body"); < 321 } else { < 322 el = E(0); | 315 el = E(0); 323 } | 316 } 324 return new App(pos, new Var(pos,"if"), cond, new Fun(thenPos,[], 317 return new App(pos, new Var(pos,"if"), cond, new Fun(thenPos,[], 325 } 318 } 326 319 327 AST parsePatternMatch(LexPosition pos) 320 AST parsePatternMatch(LexPosition pos) 328 { 321 { 329 // case pmExpr CASES 322 // case pmExpr CASES 330 //==> 323 //==> ................................................................................................................................................................................ 584 assert_eq(parseString(`1;2;`), let("_","",intl(1),intl(2))); 577 assert_eq(parseString(`1;2;`), let("_","",intl(1),intl(2))); 585 assert_eq(parseString(`let x=1 in 2`), let("x","",intl(1),intl(2))); 578 assert_eq(parseString(`let x=1 in 2`), let("x","",intl(1),intl(2))); 586 assert_eq(parseString(`var x=1;2;`), let("x","",intl(1),intl(2))); 579 assert_eq(parseString(`var x=1;2;`), let("x","",intl(1),intl(2))); 587 assert_eq(parseString(`def x=1`), let("x","",intl(1),var("x"))); 580 assert_eq(parseString(`def x=1`), let("x","",intl(1),var("x"))); 588 assert_eq(parseString(`@val x=1;`), let("x","@val",intl(1),var("x"))); 581 assert_eq(parseString(`@val x=1;`), let("x","@val",intl(1),var("x"))); 589 assert_eq(parseString(`@typ x="#int";`), let("x","@typ",strl("#int"),var 582 assert_eq(parseString(`@typ x="#int";`), let("x","@typ",strl("#int"),var 590 assert_eq(parseString(`f(1,2)`), call(var("f"),intl(1),intl(2))); 583 assert_eq(parseString(`f(1,2)`), call(var("f"),intl(1),intl(2))); 591 assert_eq(parseString(`if(1){2}`), call(var("if"),intl(1),fun([],intl(2) | 584 assert_eq(parseString(`if 1 then 2`), call(var("if"),intl(1),fun([],intl 592 assert_eq(parseString(`if(1){2}else{3}`), call(var("if"),intl(1),fun([], | 585 assert_eq(parseString(`if 1 then: 2 else(3)`), call(var("if"),intl(1),fu 593 assert_eq(parseString(`if(1){}else{3}()()`), | 586 assert_eq(parseString(`(if 1 then () else 3)()()`), 594 call(call(call(var("if"),intl(1),fun([],strl("(empty function bo 587 call(call(call(var("if"),intl(1),fun([],strl("(empty function bo 595 assert_eq(parseString(`1+2*3`), call(var("+"),intl(1),call(var("*"),intl 588 assert_eq(parseString(`1+2*3`), call(var("+"),intl(1),call(var("*"),intl 596 assert_eq(parseString(`(1+2)*3`), call(var("*"),call(var("+"),intl(1),in 589 assert_eq(parseString(`(1+2)*3`), call(var("*"),call(var("+"),intl(1),in 597 assert_eq(parseString(`1*(2+3)`), call(var("*"),intl(1),call(var("+"),in 590 assert_eq(parseString(`1*(2+3)`), call(var("*"),intl(1),call(var("+"),in 598 assert_eq(parseString(`1*2+3`), call(var("+"),call(var("*"),intl(1),intl 591 assert_eq(parseString(`1*2+3`), call(var("+"),call(var("*"),intl(1),intl 599 assert_eq(parseString(`@x(1)`), lay("@x", intl(1))); 592 assert_eq(parseString(`@x(1)`), lay("@x", intl(1))); 600 assert_eq(parseString(`fun(x @v @t, y, z @t){}`), 593 assert_eq(parseString(`fun(x @v @t, y, z @t){}`), ................................................................................................................................................................................ 605 let y = 200; #comment!!!!! 598 let y = 200; #comment!!!!! 606 x+y 599 x+y 607 `), 600 `), 608 let("x", "", intl(100), let("y", "", intl(200), call(var("+"), v 601 let("x", "", intl(100), let("y", "", intl(200), call(var("+"), v 609 ); 602 ); 610 603 611 assert_eq(parseString(` 604 assert_eq(parseString(` 612 var fac = fun(x){ if(x <= 1) {1} else {x*fac(x-1)} }; | 605 var fac = fun(x){ if(x <= 1) then 1 else x*fac(x-1) }; 613 fac(10) 606 fac(10) 614 `), 607 `), 615 let("fac", "", fun(["x"], 608 let("fac", "", fun(["x"], 616 call(var("if"), 609 call(var("if"), 617 call(var("<="), var("x"), intl(1)), 610 call(var("<="), var("x"), intl(1)), 618 fun([], intl(1)), 611 fun([], intl(1)), 619 fun([], call(var("*"), var("x"), call(var("fac") 612 fun([], call(var("*"), var("x"), call(var("fac") ................................................................................................................................................................................ 666 `)); 659 `)); 667 assert_nothrow(parseString(` 660 assert_nothrow(parseString(` 668 case 1 661 case 1 669 when {aaaa:@value(x)}: 1 662 when {aaaa:@value(x)}: 1 670 when {aaaa:{bbb:_}, ccc:123}: 1 663 when {aaaa:{bbb:_}, ccc:123}: 1 671 `)); 664 `)); 672 } 665 } 673 < 674 unittest < 675 { < 676 // test for omitting { .. } < 677 assert_nothrow(parseString(` < 678 if(1) 2 else 3 < 679 `)); < 680 assert_nothrow(parseString(` < 681 if(1) x{y:z} else 3 < 682 `)); < 683 } <