Changeset 10

Show
Ignore:
Timestamp:
10/23/05 19:48:10 (3 years ago)
Author:
Jan-Klaas Kollhof
Message:

bug fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • jsolait/trunk/jsolait/jsolait.js

    r9 r10  
    103103    NewClass.toString = function(){ 
    104104        return "[class %s]".format(NewClass.__name__); 
    105     }; 
    106      
    107     NewClass.isSubclassOf=function(cls){ 
    108         return this.prototype instanceof cls; 
    109105    }; 
    110106     
     
    396392            return s; 
    397393        }else{ 
    398              throw new mod.LoadFileFailed(uri, e); 
     394             throw new mod.LoadURIFailed(uri,new mod.Exception("Server did not respond with 200")); 
    399395        } 
    400396    }; 
     
    405401    mod.LoadURIFailed=Class(mod.Exception, function(publ, supr){ 
    406402        /** 
    407             Initializes a new ImportFailed Exception. 
     403            Initializes a new LoadURIFailed Exception. 
    408404            @param name      The name of the module. 
    409405            @param sourceURI  The uri jsolait tried to load the file from 
     
    435431            var src,modPath; 
    436432            //check if jsolait already knows the path of the module 
    437             if(mod.knownModuleURIs[name]){ 
     433            if(mod.knownModuleURIs[name] != undefined){ 
    438434                modPath = mod.knownModuleURIs[name].format(mod); 
    439435                try{//to load the source of the module 
    440436                    src = mod.loadURI(modPath); 
    441437                }catch(e){ 
    442                     throw new mod.ImportFailed(name, modPath, e); 
     438                    throw new mod.ImportFailed(name, [modPath], e); 
    443439                } 
    444440            } 
     
    452448                        break; 
    453449                    }catch(e){ 
    454                         if(e instanceof mod.LoadURIFailed){ 
    455                             failedURIs.push(e.sourceURI); 
    456                         }else{ 
    457                             throw e; 
    458                         } 
     450                        failedURIs.push(e.sourceURI); 
    459451                    } 
    460452                } 
    461453                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                         
    467458            try{//interpret the script 
    468459                src = 'Module.currentURI="%s";\n%s\nModule.currentURI=null;\n'.format(src.__sourceURI__.replace(/\\/g, '\\\\'), src); 
     
    470461                f(); 
    471462            }catch(e){ 
    472                 throw new mod.ImportFailed(name, src.__sourceURI__, e); 
     463                throw new mod.ImportFailed(name, [src.__sourceURI__], e); 
    473464            } 
    474465             
  • jsolait/trunk/jsolait/lib/lang.js

    r9 r10  
    411411        }; 
    412412         
     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         
    413421        publ.parseStatements=function(tkn){ 
    414422            while(tkn!==undefined){ 
     
    438446                 
    439447        publ.parseStatement=function(tkn){ 
     448         
    440449            if(this['parseStatement_' + tkn.constructor.__name__]){ 
    441450                tkn = this['parseStatement_' + tkn.constructor.__name__].call(this,tkn); 
     
    443452                tkn = this['parseStatement_' + tkn.value].call(this,tkn); 
    444453            }else if(tkn instanceof mod.TokenIdentifier){//function call or assignment statement 
    445                 
    446454                tkn = this.parseExpression(tkn); 
    447455                tkn = this.parseEndOfStatement(tkn); 
     
    10021010            this.wsNeeded=false; 
    10031011        }; 
     1012        var leftAndRightSpace=new sets.Set(['instanceof' , 'in']); 
     1013        var rightSpace = new sets.Set(['var', 'delete', 'throw', 'new', 'return', 'else', 'instanceof','in', 'case', 'typeof']); 
    10041014         
    10051015        publ.next=function(){ 
     
    10081018                this.bufferedTkn=null; 
    10091019            }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                    } 
    10181032                } 
    10191033            } 
     
    10301044                this.wsNeeded=false; 
    10311045            }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; 
    10351048                } 
    10361049            } 
     
    10431056    
    10441057    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         
    10451087        publ.printGlobalNode=function(n){ 
    1046             pprint('<global>', 4); 
    1047             pprint('<modules>', 4); 
     1088           this.pprint('<global>', 4); 
     1089           this.pprint('<modules>', 4); 
    10481090                       
    10491091            for(var i=0;i<n.publics.length;i++){ 
     
    10541096            } 
    10551097             
    1056             pprint('</modules>', -4); 
    1057              
    1058              
    1059             pprint('</global>', -4); 
     1098           this.pprint('</modules>', -4); 
     1099             
     1100             
     1101           this.pprint('</global>', -4); 
    10601102        };  
    10611103         
    10621104        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>'); 
    10691111             
    10701112            this.printPublics(n); 
    10711113             
    1072             pprint('</module>',-4); 
     1114           this.pprint('</module>',-4); 
    10731115        }; 
    10741116         
    10751117        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); 
    10821124             
    10831125            this.printPublics(n); 
    10841126 
    1085             pprint('</class>',-4); 
     1127           this.pprint('</class>',-4); 
    10861128        }; 
    10871129         
     
    11031145             
    11041146            if(n.publics.length>0){ 
    1105                 pprint('<publics>',4); 
     1147               this.pprint('<publics>',4); 
    11061148                if(classes.length > 0){ 
    1107                     pprint('<classes>', 4); 
     1149                   this.pprint('<classes>', 4); 
    11081150                    for(var i=0;i<classes.length;i++){ 
    11091151                        this.printClassNode(classes[i]); 
    11101152                    } 
    1111                     pprint('<classes>', -4); 
     1153                   this.pprint('</classes>', -4); 
    11121154                } 
    11131155                 
    11141156                if(methods.length > 0){ 
    1115                     pprint('<methods>', 4); 
     1157                   this.pprint('<methods>', 4); 
    11161158                    for(var i=0;i<methods.length;i++){ 
    11171159                        this.printMethodNode(methods[i]); 
    11181160                    } 
    1119                     pprint('<methods>', -4); 
     1161                   this.pprint('</methods>', -4); 
    11201162                } 
    11211163                 
    11221164                if(props.length > 0){ 
    1123                     pprint('<properties>', 4); 
     1165                   this.pprint('<properties>', 4); 
    11241166                    for(var i=0;i<props.length;i++){ 
    11251167                        this.printPropertyNode(props[i]); 
    11261168                    } 
    1127                     pprint('<properties>', -4); 
    1128                 } 
    1129                 pprint('</publics>',-4); 
     1169                   this.pprint('</properties>', -4); 
     1170                } 
     1171               this.pprint('</publics>',-4); 
    11301172            } 
    11311173        }; 
    11321174         
    11331175        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); 
    11401182             
    11411183        }; 
    11421184         
    11431185        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); 
    11501192        }; 
    11511193    }); 
     
    11761218            fname=jsolait.baseURI + '/' + fname; 
    11771219            var s = jsolait.loadURI(fname); 
    1178            print(s.encode('uri')); 
    1179          
     1220             
    11801221            var p = new mod.Parser(s, gn); 
    1181                  
    11821222            try{ 
    11831223                p.parseStatements(p.next()); 
     
    11881228        }); 
    11891229         
    1190         var dp = new mod.DocParser(); 
    1191         dp.printGlobalNode(gn); 
     1230         
    11921231    }; 
    11931232});