Mercurial Hosting > luan
comparison core/src/luan/impl/LuanParser.java @ 321:7f7708e8fdd4
remove import statement
git-svn-id: https://luan-java.googlecode.com/svn/trunk@322 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Sun, 08 Feb 2015 07:26:20 +0000 |
parents | fed1893821bf |
children | b24a35612947 |
comparison
equal
deleted
inserted
replaced
320:fed1893821bf | 321:7f7708e8fdd4 |
---|---|
247 return; | 247 return; |
248 Stmt stmt; | 248 Stmt stmt; |
249 if( (stmt=ReturnStmt()) != null | 249 if( (stmt=ReturnStmt()) != null |
250 || (stmt=FunctionStmt()) != null | 250 || (stmt=FunctionStmt()) != null |
251 || (stmt=LocalFunctionStmt()) != null | 251 || (stmt=LocalFunctionStmt()) != null |
252 || (stmt=ImportStmt()) != null | |
253 || (stmt=JavaStmt()) != null | |
254 || (stmt=BreakStmt()) != null | 252 || (stmt=BreakStmt()) != null |
255 || (stmt=ForStmt()) != null | 253 || (stmt=ForStmt()) != null |
256 || (stmt=TryStmt()) != null | 254 || (stmt=TryStmt()) != null |
257 || (stmt=DoStmt()) != null | 255 || (stmt=DoStmt()) != null |
258 || (stmt=WhileStmt()) != null | 256 || (stmt=WhileStmt()) != null |
344 return parser.failure(null); | 342 return parser.failure(null); |
345 String name = RequiredName(In.NOTHING); | 343 String name = RequiredName(In.NOTHING); |
346 addSymbol( name ); | 344 addSymbol( name ); |
347 FnDef fnDef = RequiredFunction(In.NOTHING); | 345 FnDef fnDef = RequiredFunction(In.NOTHING); |
348 return parser.success( new SetStmt( new SetLocalVar(symbolsSize()-1), fnDef ) ); | 346 return parser.success( new SetStmt( new SetLocalVar(symbolsSize()-1), fnDef ) ); |
349 } | |
350 | |
351 private Stmt ImportStmt() throws ParseException { | |
352 int start = parser.begin(); | |
353 if( !Keyword("import",In.NOTHING) ) | |
354 return parser.failure(null); | |
355 String modName = StringLiteral(In.NOTHING); | |
356 if( modName==null ) | |
357 return parser.failure(null); | |
358 int i = modName.lastIndexOf('/'); | |
359 if( i == -1 ) | |
360 i = modName.lastIndexOf('.'); | |
361 if( i == -1 ) | |
362 i = modName.lastIndexOf(':'); | |
363 String varName = modName.substring(i+1); | |
364 if( !isValidName(varName) ) | |
365 throw parser.exception("invalid variable name '"+varName+"' in import"); | |
366 LuanSource.Element se = se(start); | |
367 FnCall require = new FnCall( se, new ConstExpr(se,PackageLuan.requireFn), new ConstExpr(se(start,modName),modName) ); | |
368 Settable settable; | |
369 if( interactive ) { | |
370 settable = nameVar(se,varName).settable(); | |
371 } else { | |
372 addSymbol( varName ); | |
373 settable = new SetLocalVar(symbolsSize()-1); | |
374 } | |
375 return parser.success( new SetStmt( settable, expr(require) ) ); | |
376 } | |
377 | |
378 private boolean isValidName(String s) { | |
379 if( s.length() == 0 ) | |
380 return false; | |
381 char c = s.charAt(0); | |
382 if( !('a'<=c && c<='z' || 'A'<=c && c<='Z' || c=='_') ) | |
383 return false; | |
384 for( int i=1; i<s.length() ; i++ ) { | |
385 if( !('a'<=c && c<='z' || 'A'<=c && c<='Z' || c=='_' || '0'<=c && c<='9') ) | |
386 return false; | |
387 } | |
388 return true; | |
389 } | |
390 | |
391 private Stmt JavaStmt() throws ParseException { | |
392 parser.begin(); | |
393 if( !Keyword("java",In.NOTHING) ) | |
394 return parser.failure(null); | |
395 return parser.success( new JavaStmt() ); | |
396 } | 347 } |
397 | 348 |
398 private Stmt BreakStmt() throws ParseException { | 349 private Stmt BreakStmt() throws ParseException { |
399 parser.begin(); | 350 parser.begin(); |
400 if( !Keyword("break",In.NOTHING) ) | 351 if( !Keyword("break",In.NOTHING) ) |
1152 "false", | 1103 "false", |
1153 "for", | 1104 "for", |
1154 "function", | 1105 "function", |
1155 "goto", | 1106 "goto", |
1156 "if", | 1107 "if", |
1157 "import", | |
1158 "in", | 1108 "in", |
1159 "java", | |
1160 "local", | 1109 "local", |
1161 "nil", | 1110 "nil", |
1162 "not", | 1111 "not", |
1163 "or", | 1112 "or", |
1164 "repeat", | 1113 "repeat", |