Mercurial Hosting > luan
comparison src/luan/interp/LuanParser.java @ 151:c9100f29fae0
conditions must be type boolean
git-svn-id: https://luan-java.googlecode.com/svn/trunk@152 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Mon, 16 Jun 2014 10:37:06 +0000 |
parents | f99fd64291b3 |
children | fa03671f59a0 |
comparison
equal
deleted
inserted
replaced
150:f35c50027985 | 151:c9100f29fae0 |
---|---|
449 return parser.failure(null); | 449 return parser.failure(null); |
450 return parser.success(name); | 450 return parser.success(name); |
451 } | 451 } |
452 | 452 |
453 private Stmt WhileStmt() throws ParseException { | 453 private Stmt WhileStmt() throws ParseException { |
454 parser.begin(); | 454 int start = parser.begin(); |
455 if( !Keyword("while",In.NOTHING) ) | 455 if( !Keyword("while",In.NOTHING) ) |
456 return parser.failure(null); | 456 return parser.failure(null); |
457 Expr cnd = expr(RequiredExpr(In.NOTHING)); | 457 Expr cnd = expr(RequiredExpr(In.NOTHING)); |
458 RequiredKeyword("do",In.NOTHING); | 458 RequiredKeyword("do",In.NOTHING); |
459 Stmt loop = RequiredLoopBlock(); | 459 Stmt loop = RequiredLoopBlock(); |
460 RequiredKeyword("end",In.NOTHING); | 460 RequiredKeyword("end",In.NOTHING); |
461 return parser.success( new WhileStmt(cnd,loop) ); | 461 return parser.success( new WhileStmt(se(start),cnd,loop) ); |
462 } | 462 } |
463 | 463 |
464 private Stmt RepeatStmt() throws ParseException { | 464 private Stmt RepeatStmt() throws ParseException { |
465 parser.begin(); | 465 int start = parser.begin(); |
466 if( !Keyword("repeat",In.NOTHING) ) | 466 if( !Keyword("repeat",In.NOTHING) ) |
467 return parser.failure(null); | 467 return parser.failure(null); |
468 Stmt loop = RequiredLoopBlock(); | 468 Stmt loop = RequiredLoopBlock(); |
469 RequiredKeyword("until",In.NOTHING); | 469 RequiredKeyword("until",In.NOTHING); |
470 Expr cnd = expr(RequiredExpr(In.NOTHING)); | 470 Expr cnd = expr(RequiredExpr(In.NOTHING)); |
471 return parser.success( new RepeatStmt(loop,cnd) ); | 471 return parser.success( new RepeatStmt(se(start),loop,cnd) ); |
472 } | 472 } |
473 | 473 |
474 private Stmt RequiredLoopBlock() throws ParseException { | 474 private Stmt RequiredLoopBlock() throws ParseException { |
475 incLoops(); | 475 incLoops(); |
476 Stmt stmt = RequiredBlock(); | 476 Stmt stmt = RequiredBlock(); |
484 return parser.failure(null); | 484 return parser.failure(null); |
485 return parser.success( IfStmt2() ); | 485 return parser.success( IfStmt2() ); |
486 } | 486 } |
487 | 487 |
488 private Stmt IfStmt2() throws ParseException { | 488 private Stmt IfStmt2() throws ParseException { |
489 int start = parser.currentIndex(); | |
489 Expr cnd = expr(RequiredExpr(In.NOTHING)); | 490 Expr cnd = expr(RequiredExpr(In.NOTHING)); |
490 RequiredKeyword("then",In.NOTHING); | 491 RequiredKeyword("then",In.NOTHING); |
491 Stmt thenBlock = RequiredBlock(); | 492 Stmt thenBlock = RequiredBlock(); |
492 Stmt elseBlock; | 493 Stmt elseBlock; |
493 if( Keyword("elseif",In.NOTHING) ) { | 494 if( Keyword("elseif",In.NOTHING) ) { |
494 elseBlock = IfStmt2(); | 495 elseBlock = IfStmt2(); |
495 } else { | 496 } else { |
496 elseBlock = Keyword("else",In.NOTHING) ? RequiredBlock() : Stmt.EMPTY; | 497 elseBlock = Keyword("else",In.NOTHING) ? RequiredBlock() : Stmt.EMPTY; |
497 RequiredKeyword("end",In.NOTHING); | 498 RequiredKeyword("end",In.NOTHING); |
498 } | 499 } |
499 return new IfStmt(cnd,thenBlock,elseBlock); | 500 return new IfStmt(se(start),cnd,thenBlock,elseBlock); |
500 } | 501 } |
501 | 502 |
502 private Stmt SetStmt() throws ParseException { | 503 private Stmt SetStmt() throws ParseException { |
503 parser.begin(); | 504 parser.begin(); |
504 List<Settable> vars = new ArrayList<Settable>(); | 505 List<Settable> vars = new ArrayList<Settable>(); |