Changeset 10
- Timestamp:
- 10/23/05 19:48:10 (3 years ago)
- Files:
-
- jsolait/trunk/jsolait/jsolait.js (modified) (6 diffs)
- jsolait/trunk/jsolait/lib/lang.js (modified) (11 diffs)
- jsolait/trunk/tools/build.js (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
jsolait/trunk/jsolait/jsolait.js
r9 r10 103 103 NewClass.toString = function(){ 104 104 return "[class %s]".format(NewClass.__name__); 105 };106 107 NewClass.isSubclassOf=function(cls){108 return this.prototype instanceof cls;109 105 }; 110 106 … … 396 392 return s; 397 393 }else{ 398 throw new mod.Load FileFailed(uri, e);394 throw new mod.LoadURIFailed(uri,new mod.Exception("Server did not respond with 200")); 399 395 } 400 396 }; … … 405 401 mod.LoadURIFailed=Class(mod.Exception, function(publ, supr){ 406 402 /** 407 Initializes a new ImportFailed Exception.403 Initializes a new LoadURIFailed Exception. 408 404 @param name The name of the module. 409 405 @param sourceURI The uri jsolait tried to load the file from … … 435 431 var src,modPath; 436 432 //check if jsolait already knows the path of the module 437 if(mod.knownModuleURIs[name] ){433 if(mod.knownModuleURIs[name] != undefined){ 438 434 modPath = mod.knownModuleURIs[name].format(mod); 439 435 try{//to load the source of the module 440 436 src = mod.loadURI(modPath); 441 437 }catch(e){ 442 throw new mod.ImportFailed(name, modPath, e);438 throw new mod.ImportFailed(name, [modPath], e); 443 439 } 444 440 } … … 452 448 break; 453 449 }catch(e){ 454 if(e instanceof mod.LoadURIFailed){ 455 failedURIs.push(e.sourceURI); 456 }else{ 457 throw e; 458 } 450 failedURIs.push(e.sourceURI); 459 451 } 460 452 } 461 453 if(src == null){ 462 throw new mod.ImportFailed(name, failedURIs, e); 463 } 464 } 465 466 454 throw new mod.ImportFailed(name, failedURIs); 455 } 456 } 457 467 458 try{//interpret the script 468 459 src = 'Module.currentURI="%s";\n%s\nModule.currentURI=null;\n'.format(src.__sourceURI__.replace(/\\/g, '\\\\'), src); … … 470 461 f(); 471 462 }catch(e){ 472 throw new mod.ImportFailed(name, src.__sourceURI__, e);463 throw new mod.ImportFailed(name, [src.__sourceURI__], e); 473 464 } 474 465 jsolait/trunk/jsolait/lib/lang.js
r9 r10 411 411 }; 412 412 413 414 publ.parseSource=function(){ 415 var tkn = this.parseStatements(this.next()); 416 if(tkn !== undefined){ 417 throw mod.Expected("Expected end of source but found % .".format(tkn)); 418 } 419 }; 420 413 421 publ.parseStatements=function(tkn){ 414 422 while(tkn!==undefined){ … … 438 446 439 447 publ.parseStatement=function(tkn){ 448 440 449 if(this['parseStatement_' + tkn.constructor.__name__]){ 441 450 tkn = this['parseStatement_' + tkn.constructor.__name__].call(this,tkn); … … 443 452 tkn = this['parseStatement_' + tkn.value].call(this,tkn); 444 453 }else if(tkn instanceof mod.TokenIdentifier){//function call or assignment statement 445 446 454 tkn = this.parseExpression(tkn); 447 455 tkn = this.parseEndOfStatement(tkn); … … 1002 1010 this.wsNeeded=false; 1003 1011 }; 1012 var leftAndRightSpace=new sets.Set(['instanceof' , 'in']); 1013 var rightSpace = new sets.Set(['var', 'delete', 'throw', 'new', 'return', 'else', 'instanceof','in', 'case', 'typeof']); 1004 1014 1005 1015 publ.next=function(){ … … 1008 1018 this.bufferedTkn=null; 1009 1019 }else{ 1010 var tkn = this.nextNonWhiteSpace(); 1011 while((tkn instanceof mod.TokenComment)|| ((tkn instanceof mod.TokenNewLine ) && (this.lastTkn instanceof mod.TokenNewLine))){ 1012 tkn = this.nextNonWhiteSpace(); 1013 } 1014 if(tkn.value == 'instanceof'){ 1015 this.wsNeeded=false; 1016 this.bufferedTkn=tkn; 1017 return new mod.TokenWhiteSpace(' '); 1020 var tkn = supr.next.call(this); 1021 while((tkn instanceof mod.TokenWhiteSpace) || (tkn instanceof mod.TokenComment)|| ((tkn instanceof mod.TokenNewLine ) && (this.lastTkn instanceof mod.TokenNewLine))){ 1022 tkn = supr.next.call(this); 1023 } 1024 if(tkn === undefined){ 1025 return tkn; 1026 }else{ 1027 if(leftAndRightSpace.contains(tkn.value)){ 1028 this.wsNeeded=false; 1029 this.bufferedTkn=tkn; 1030 return new mod.TokenWhiteSpace(' '); 1031 } 1018 1032 } 1019 1033 } … … 1030 1044 this.wsNeeded=false; 1031 1045 }else{ 1032 switch(tkn.value){ 1033 case 'var': case 'delete': case 'throw': case 'new': case 'return': case 'else': case 'instanceof': 1034 this.wsNeeded=true; 1046 if(rightSpace.contains(tkn.value)){ 1047 this.wsNeeded=true; 1035 1048 } 1036 1049 } … … 1043 1056 1044 1057 mod.DocParser=Class(function(publ,supr){ 1058 publ.__init__=function(file){ 1059 this.file=file; 1060 }; 1061 1062 publ.pprint=function(m, indent){ 1063 var m = m.split("\n"); 1064 1065 indent =(indent === undefined) ? 0 : indent; 1066 1067 if(indent<0){ 1068 this.pprintIndent+=indent; 1069 } 1070 1071 var s=[]; 1072 for(var i=0;i<this.pprintIndent;i++){ 1073 s.push(' '); 1074 } 1075 s=s.join(''); 1076 for(var i=0;i<m.length;i++){ 1077 this.file.write(s + m[i] + '\n'); 1078 //print(s + m[i] ); 1079 } 1080 1081 if(indent>0){ 1082 this.pprintIndent += indent; 1083 } 1084 }; 1085 publ.pprintIndent=0; 1086 1045 1087 publ.printGlobalNode=function(n){ 1046 pprint('<global>', 4);1047 pprint('<modules>', 4);1088 this.pprint('<global>', 4); 1089 this.pprint('<modules>', 4); 1048 1090 1049 1091 for(var i=0;i<n.publics.length;i++){ … … 1054 1096 } 1055 1097 1056 pprint('</modules>', -4);1057 1058 1059 pprint('</global>', -4);1098 this.pprint('</modules>', -4); 1099 1100 1101 this.pprint('</global>', -4); 1060 1102 }; 1061 1103 1062 1104 publ.printModuleNode=function(n){ 1063 pprint('<module>',4);1064 pprint('<name>'+n.name+'</name>');1065 pprint('<description>', 4);1066 pprint(n.description);1067 pprint('</description>', -4);1068 pprint('<dependencies>'+n.dependencies+'</dependencies>');1105 this.pprint('<module>',4); 1106 this.pprint('<name>'+n.name+'</name>'); 1107 this.pprint('<description>', 4); 1108 this.pprint(n.description); 1109 this.pprint('</description>', -4); 1110 this.pprint('<dependencies>'+n.dependencies+'</dependencies>'); 1069 1111 1070 1112 this.printPublics(n); 1071 1113 1072 pprint('</module>',-4);1114 this.pprint('</module>',-4); 1073 1115 }; 1074 1116 1075 1117 publ.printClassNode=function(n){ 1076 pprint('<class>',4);1077 pprint('<name>'+n.name+'</name>');1078 1079 pprint('<description>', 4);1080 pprint(n.description);1081 pprint('</description>', -4);1118 this.pprint('<class>',4); 1119 this.pprint('<name>'+n.name+'</name>'); 1120 1121 this.pprint('<description>', 4); 1122 this.pprint(n.description); 1123 this.pprint('</description>', -4); 1082 1124 1083 1125 this.printPublics(n); 1084 1126 1085 pprint('</class>',-4);1127 this.pprint('</class>',-4); 1086 1128 }; 1087 1129 … … 1103 1145 1104 1146 if(n.publics.length>0){ 1105 pprint('<publics>',4);1147 this.pprint('<publics>',4); 1106 1148 if(classes.length > 0){ 1107 pprint('<classes>', 4);1149 this.pprint('<classes>', 4); 1108 1150 for(var i=0;i<classes.length;i++){ 1109 1151 this.printClassNode(classes[i]); 1110 1152 } 1111 pprint('<classes>', -4);1153 this.pprint('</classes>', -4); 1112 1154 } 1113 1155 1114 1156 if(methods.length > 0){ 1115 pprint('<methods>', 4);1157 this.pprint('<methods>', 4); 1116 1158 for(var i=0;i<methods.length;i++){ 1117 1159 this.printMethodNode(methods[i]); 1118 1160 } 1119 pprint('<methods>', -4);1161 this.pprint('</methods>', -4); 1120 1162 } 1121 1163 1122 1164 if(props.length > 0){ 1123 pprint('<properties>', 4);1165 this.pprint('<properties>', 4); 1124 1166 for(var i=0;i<props.length;i++){ 1125 1167 this.printPropertyNode(props[i]); 1126 1168 } 1127 pprint('<properties>', -4);1128 } 1129 pprint('</publics>',-4);1169 this.pprint('</properties>', -4); 1170 } 1171 this.pprint('</publics>',-4); 1130 1172 } 1131 1173 }; 1132 1174 1133 1175 publ.printPropertyNode=function(n){ 1134 pprint('<property>',4);1135 pprint('<name>' + n.name + '</name>');1136 pprint('<description>', 4);1137 pprint(n.description);1138 pprint('</description>', -4);1139 pprint('</property>',-4);1176 this.pprint('<property>',4); 1177 this.pprint('<name>' + n.name + '</name>'); 1178 this.pprint('<description>', 4); 1179 this.pprint(n.description); 1180 this.pprint('</description>', -4); 1181 this.pprint('</property>',-4); 1140 1182 1141 1183 }; 1142 1184 1143 1185 publ.printMethodNode=function(n){ 1144 pprint('<method>',4);1145 pprint('<name>' + n.name + '(' + n.parameters.join(', ') + ')</name>');1146 pprint('<description>', 4);1147 pprint(n.description);1148 pprint('</description>', -4);1149 pprint('</method>',-4);1186 this.pprint('<method>',4); 1187 this.pprint('<name>' + n.name + '(' + n.parameters.join(', ') + ')</name>'); 1188 this.pprint('<description>', 4); 1189 this.pprint(n.description); 1190 this.pprint('</description>', -4); 1191 this.pprint('</method>',-4); 1150 1192 }; 1151 1193 }); … … 1176 1218 fname=jsolait.baseURI + '/' + fname; 1177 1219 var s = jsolait.loadURI(fname); 1178 print(s.encode('uri')); 1179 1220 1180 1221 var p = new mod.Parser(s, gn); 1181 1182 1222 try{ 1183 1223 p.parseStatements(p.next()); … … 1188 1228 }); 1189 1229 1190 var dp = new mod.DocParser(); 1191 dp.printGlobalNode(gn); 1230 1192 1231 }; 1193 1232 });
