comparison src/luan/impl/LuanParser.java @ 1131:46732cc0ab87

add continue statement
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 14 Dec 2017 01:38:47 -0700
parents 5dc601c4ed6d
children ba4daf107e07
comparison
equal deleted inserted replaced
1130:bfbd5401353a 1131:46732cc0ab87
337 if( (stmt=ReturnStmt()) != null 337 if( (stmt=ReturnStmt()) != null
338 || (stmt=FunctionStmt()) != null 338 || (stmt=FunctionStmt()) != null
339 || (stmt=LocalStmt()) != null 339 || (stmt=LocalStmt()) != null
340 || (stmt=LocalFunctionStmt()) != null 340 || (stmt=LocalFunctionStmt()) != null
341 || (stmt=BreakStmt()) != null 341 || (stmt=BreakStmt()) != null
342 || (stmt=ContinueStmt()) != null
342 || (stmt=ForStmt()) != null 343 || (stmt=ForStmt()) != null
343 || (stmt=DoStmt()) != null 344 || (stmt=DoStmt()) != null
344 || (stmt=WhileStmt()) != null 345 || (stmt=WhileStmt()) != null
345 || (stmt=RepeatStmt()) != null 346 || (stmt=RepeatStmt()) != null
346 || (stmt=IfStmt()) != null 347 || (stmt=IfStmt()) != null
477 return parser.failure(null); 478 return parser.failure(null);
478 if( frame.loops <= 0 ) 479 if( frame.loops <= 0 )
479 throw parser.exception("'break' outside of loop"); 480 throw parser.exception("'break' outside of loop");
480 Stmts stmt = new Stmts(); 481 Stmts stmt = new Stmts();
481 stmt.add( "break; " ); 482 stmt.add( "break; " );
483 return parser.success( stmt );
484 }
485
486 private Stmts ContinueStmt() throws ParseException {
487 parser.begin();
488 if( !Keyword("continue") )
489 return parser.failure(null);
490 if( frame.loops <= 0 )
491 throw parser.exception("'continue' outside of loop");
492 Stmts stmt = new Stmts();
493 stmt.add( "continue; " );
482 return parser.success( stmt ); 494 return parser.success( stmt );
483 } 495 }
484 496
485 int forCounter = 0; 497 int forCounter = 0;
486 498
1492 } 1504 }
1493 1505
1494 private static final Set<String> keywords = new HashSet<String>(Arrays.asList( 1506 private static final Set<String> keywords = new HashSet<String>(Arrays.asList(
1495 "and", 1507 "and",
1496 "break", 1508 "break",
1509 "continue",
1497 "do", 1510 "do",
1498 "else", 1511 "else",
1499 "elseif", 1512 "elseif",
1500 "end", 1513 "end",
1501 "end_do", 1514 "end_do",