Mercurial Hosting > luan
comparison core/src/luan/impl/LuanParser.java @ 186:cf939124461a
don't import modules by default
git-svn-id: https://luan-java.googlecode.com/svn/trunk@187 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Thu, 26 Jun 2014 00:36:50 +0000 |
parents | 5d2cb8c1f844 |
children | 04b86428dc50 |
comparison
equal
deleted
inserted
replaced
185:5f50dba8ac7d | 186:cf939124461a |
---|---|
7 import java.util.ArrayList; | 7 import java.util.ArrayList; |
8 import java.util.Scanner; | 8 import java.util.Scanner; |
9 import luan.Luan; | 9 import luan.Luan; |
10 import luan.LuanState; | 10 import luan.LuanState; |
11 import luan.LuanSource; | 11 import luan.LuanSource; |
12 import luan.modules.PackageLuan; | |
12 | 13 |
13 | 14 |
14 final class LuanParser { | 15 final class LuanParser { |
15 | 16 |
16 private static final class Frame { | 17 private static final class Frame { |
343 | 344 |
344 private Stmt ImportStmt() throws ParseException { | 345 private Stmt ImportStmt() throws ParseException { |
345 int start = parser.begin(); | 346 int start = parser.begin(); |
346 if( !Keyword("import",In.NOTHING) ) | 347 if( !Keyword("import",In.NOTHING) ) |
347 return parser.failure(null); | 348 return parser.failure(null); |
348 Expr importExpr; | |
349 { | |
350 LuanSource.Element se = se(start); | |
351 int index = stackIndex("require"); | |
352 if( index != -1 ) { | |
353 importExpr = new GetLocalVar(se,index); | |
354 } else { | |
355 index = upValueIndex("require"); | |
356 if( index != -1 ) { | |
357 importExpr = new GetUpVar(se,index); | |
358 } else { | |
359 throw parser.exception("no local 'require' function, needed for import"); | |
360 } | |
361 } | |
362 } | |
363 String modName = StringLiteral(In.NOTHING); | 349 String modName = StringLiteral(In.NOTHING); |
364 if( modName==null ) | 350 if( modName==null ) |
365 return parser.failure(null); | 351 return parser.failure(null); |
366 int i = modName.lastIndexOf('/'); | 352 int i = modName.lastIndexOf('/'); |
367 if( i == -1 ) | 353 if( i == -1 ) |
368 i = modName.lastIndexOf('.'); | 354 i = modName.lastIndexOf('.'); |
369 String varName = modName.substring(i+1); | 355 String varName = modName.substring(i+1); |
370 if( !isValidName(varName) ) | 356 if( !isValidName(varName) ) |
371 throw parser.exception("invalid variable name '"+varName+"' in import"); | 357 throw parser.exception("invalid variable name '"+varName+"' in import"); |
372 LuanSource.Element se = se(start); | 358 LuanSource.Element se = se(start); |
373 FnCall require = new FnCall( se, importExpr, new ConstExpr(modName) ); | 359 FnCall require = new FnCall( se, new ConstExpr(se,PackageLuan.requireFn), new ConstExpr(modName) ); |
374 Settable settable; | 360 Settable settable; |
375 if( interactive ) { | 361 if( interactive ) { |
376 settable = nameVar(se,varName).settable(); | 362 settable = nameVar(se,varName).settable(); |
377 } else { | 363 } else { |
378 addSymbol( varName ); | 364 addSymbol( varName ); |