Mercurial Hosting > luan
comparison core/src/luan/impl/LuanParser.java @ 661:1bbb08c0d8f1
compile LocalFunctionStmt
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 06 Apr 2016 21:19:30 -0600 |
parents | e064377994b2 |
children | ee00a619eec1 |
comparison
equal
deleted
inserted
replaced
660:e064377994b2 | 661:1bbb08c0d8f1 |
---|---|
247 if( LocalStmt(stmts) ) | 247 if( LocalStmt(stmts) ) |
248 return; | 248 return; |
249 StmtString stmt; | 249 StmtString stmt; |
250 if( (stmt=ReturnStmt()) != null | 250 if( (stmt=ReturnStmt()) != null |
251 || (stmt=FunctionStmt()) != null | 251 || (stmt=FunctionStmt()) != null |
252 || (stmt=stmtStr(LocalFunctionStmt())) != null | 252 || (stmt=LocalFunctionStmt()) != null |
253 || (stmt=BreakStmt()) != null | 253 || (stmt=BreakStmt()) != null |
254 || (stmt=ForStmt()) != null | 254 || (stmt=ForStmt()) != null |
255 || (stmt=DoStmt()) != null | 255 || (stmt=DoStmt()) != null |
256 || (stmt=WhileStmt()) != null | 256 || (stmt=WhileStmt()) != null |
257 || (stmt=RepeatStmt()) != null | 257 || (stmt=RepeatStmt()) != null |
355 | 355 |
356 FnDef fnDef = RequiredFunction(In.NOTHING); | 356 FnDef fnDef = RequiredFunction(In.NOTHING); |
357 return parser.success( var.set(new ExpString(fnDef)) ); | 357 return parser.success( var.set(new ExpString(fnDef)) ); |
358 } | 358 } |
359 | 359 |
360 private Stmt LocalFunctionStmt() throws ParseException { | 360 private StmtString LocalFunctionStmt() throws ParseException { |
361 parser.begin(); | 361 parser.begin(); |
362 if( !(Keyword("local",In.NOTHING) && Keyword("function",In.NOTHING)) ) | 362 if( !(Keyword("local",In.NOTHING) && Keyword("function",In.NOTHING)) ) |
363 return parser.failure(null); | 363 return parser.failure(null); |
364 String name = RequiredName(In.NOTHING); | 364 String name = RequiredName(In.NOTHING); |
365 addSymbol( name ); | 365 addSymbol( name ); |
366 FnDef fnDef = RequiredFunction(In.NOTHING); | 366 FnDef fnDef = RequiredFunction(In.NOTHING); |
367 return parser.success( new SetStmt( new SetLocalVar(symbolsSize()-1), fnDef ) ); | 367 Settable s = new SetLocalVar(symbolsSize()-1); |
368 String code = new SettableString(s).code + ".set(luan," + new ExpString(fnDef).code + ");\n"; | |
369 return parser.success( new StmtString(code) ); | |
368 } | 370 } |
369 | 371 |
370 private StmtString BreakStmt() throws ParseException { | 372 private StmtString BreakStmt() throws ParseException { |
371 parser.begin(); | 373 parser.begin(); |
372 if( !Keyword("break",In.NOTHING) ) | 374 if( !Keyword("break",In.NOTHING) ) |
1561 } | 1563 } |
1562 } | 1564 } |
1563 | 1565 |
1564 private static class StmtString { | 1566 private static class StmtString { |
1565 final String code; | 1567 final String code; |
1566 | 1568 /* |
1567 StmtString(Stmt stmt) { | 1569 StmtString(Stmt stmt) { |
1568 if( stmt==null ) throw new NullPointerException(); | 1570 if( stmt==null ) throw new NullPointerException(); |
1569 int i = LuanImpl.addStmt(stmt); | 1571 int i = LuanImpl.addStmt(stmt); |
1570 code = "LuanImpl.getStmt(" + i + ").eval(luan);\n"; | 1572 code = "LuanImpl.getStmt(" + i + ").eval(luan);\n"; |
1571 } | 1573 } |
1572 | 1574 */ |
1573 StmtString(String code) { | 1575 StmtString(String code) { |
1574 this.code = code; | 1576 this.code = code; |
1575 if( code.contains("LuanParser") ) throw new RuntimeException("\n"+code); | 1577 if( code.contains("LuanParser") ) throw new RuntimeException("\n"+code); |
1576 } | 1578 } |
1577 | 1579 |
1609 | 1611 |
1610 private static Stmt stmt(StmtString stmtStr) { | 1612 private static Stmt stmt(StmtString stmtStr) { |
1611 return stmtStr==null ? null : stmtStr.toStmt(); | 1613 return stmtStr==null ? null : stmtStr.toStmt(); |
1612 } | 1614 } |
1613 | 1615 |
1614 private static StmtString stmtStr(Stmt stmt) { | |
1615 return stmt==null ? null : new StmtString(stmt); | |
1616 } | |
1617 | |
1618 | 1616 |
1619 private static class SettableString { | 1617 private static class SettableString { |
1620 final String code; | 1618 final String code; |
1621 | 1619 |
1622 SettableString(Settable settable) { | 1620 SettableString(Settable settable) { |