comparison core/src/luan/impl/LuanParser.java @ 658:e038905512d3

compile ReturnStmt
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 05 Apr 2016 18:38:29 -0600
parents 8081713bf7d9
children e064377994b2
comparison
equal deleted inserted replaced
657:8081713bf7d9 658:e038905512d3
179 } 179 }
180 180
181 FnDef Expression() throws ParseException { 181 FnDef Expression() throws ParseException {
182 Spaces(In.NOTHING); 182 Spaces(In.NOTHING);
183 int start = parser.begin(); 183 int start = parser.begin();
184 Expressions expr = exp(ExprZ(In.NOTHING)); 184 ExpString expr = ExprZ(In.NOTHING);
185 if( expr != null && parser.endOfInput() ) { 185 if( expr != null && parser.endOfInput() ) {
186 Stmt stmt = new ReturnStmt( expr ); 186 String code = "luan.returnValues = " + expr.code + ";\n";
187 Stmt stmt = stmt( new StmtString(code) );
187 return parser.success(newFnDef(start,stmt)); 188 return parser.success(newFnDef(start,stmt));
188 } 189 }
189 return parser.failure(null); 190 return parser.failure(null);
190 } 191 }
191 192
244 245
245 private void Stmt(StringBuilder stmts) throws ParseException { 246 private void Stmt(StringBuilder stmts) throws ParseException {
246 if( LocalStmt(stmts) ) 247 if( LocalStmt(stmts) )
247 return; 248 return;
248 StmtString stmt; 249 StmtString stmt;
249 if( (stmt=stmtStr(ReturnStmt())) != null 250 if( (stmt=ReturnStmt()) != null
250 || (stmt=stmtStr(FunctionStmt())) != null 251 || (stmt=stmtStr(FunctionStmt())) != null
251 || (stmt=stmtStr(LocalFunctionStmt())) != null 252 || (stmt=stmtStr(LocalFunctionStmt())) != null
252 || (stmt=BreakStmt()) != null 253 || (stmt=BreakStmt()) != null
253 || (stmt=ForStmt()) != null 254 || (stmt=ForStmt()) != null
254 || (stmt=DoStmt()) != null 255 || (stmt=DoStmt()) != null
325 builder.add( constExpStr(match) ); 326 builder.add( constExpStr(match) );
326 } 327 }
327 } 328 }
328 } 329 }
329 330
330 private Stmt ReturnStmt() throws ParseException { 331 private StmtString ReturnStmt() throws ParseException {
331 parser.begin(); 332 parser.begin();
332 if( !Keyword("return",In.NOTHING) ) 333 if( !Keyword("return",In.NOTHING) )
333 return parser.failure(null); 334 return parser.failure(null);
334 Expressions exprs = exp(ExpStringList(In.NOTHING)); 335 ExpString exprs = ExpStringList(In.NOTHING);
335 if( exprs==null ) 336 String code = "luan.returnValues = " + (exprs!=null ? exprs.code : "LuanFunction.NOTHING") + ";\n"
336 exprs = ExpList.emptyExpList; 337 +"return;\n";
337 return parser.success( new ReturnStmt(exprs) ); 338 return parser.success( new StmtString(code) );
338 } 339 }
339 340
340 private Stmt FunctionStmt() throws ParseException { 341 private Stmt FunctionStmt() throws ParseException {
341 parser.begin(); 342 parser.begin();
342 if( !Keyword("function",In.NOTHING) ) 343 if( !Keyword("function",In.NOTHING) )