comparison core/src/luan/impl/LuanParser.java @ 680:ecd436959855

improve template statements
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 14 Apr 2016 16:38:30 -0600
parents 43522473599d
children f1c935be546d
comparison
equal deleted inserted replaced
679:43522473599d 680:ecd436959855
181 181
182 // final LuanSource source; 182 // final LuanSource source;
183 private Frame frame; 183 private Frame frame;
184 private final Parser parser; 184 private final Parser parser;
185 private final Stmts top; 185 private final Stmts top;
186 private boolean hasTemplateWrite = false;
186 187
187 LuanParser(String sourceName,String sourceText) { 188 LuanParser(String sourceName,String sourceText) {
188 // this.source = source; 189 // this.source = source;
189 this.frame = new Frame(); 190 this.frame = new Frame();
190 this.parser = new Parser(sourceName,sourceText); 191 this.parser = new Parser(sourceName,sourceText);
370 371
371 private Stmts TemplateStmt() throws ParseException { 372 private Stmts TemplateStmt() throws ParseException {
372 Expr exprs = TemplateExpressions(In.NOTHING); 373 Expr exprs = TemplateExpressions(In.NOTHING);
373 if( exprs == null ) 374 if( exprs == null )
374 return null; 375 return null;
375 Expr requireCall = new Expr(Val.SINGLE,false); 376 if( !hasTemplateWrite ) {
376 requireCall.add( "PackageLuan.require(luan,\"luan:Io\")" ); 377 top.add(0,"final LuanFunction template_write = Luan.checkFunction(luan.index(PackageLuan.require(luan,\"luan:Io\"),\"template_write\")); ");
377 Expr stdoutExp = indexExpStr( requireCall.single(), constExpStr("stdout") ); 378 hasTemplateWrite = true;
378 Expr writeExp = indexExpStr( stdoutExp, constExpStr("write") ); 379 }
379 Expr writeCall = callExpStr( writeExp, exprs );
380 Stmts stmt = new Stmts(); 380 Stmts stmt = new Stmts();
381 stmt.addAll( writeCall ); 381 stmt.add( "template_write.call(luan," );
382 stmt.add( "; " ); 382 stmt.addAll( exprs.array() );
383 stmt.add( "); " );
383 return stmt; 384 return stmt;
384 } 385 }
385 386
386 private Expr TemplateExpressions(In in) throws ParseException { 387 private Expr TemplateExpressions(In in) throws ParseException {
387 if( in.template ) 388 if( in.template )