JSDOC/TokenReader.js
[gnome.introspection-doc-generator] / JSDOC / PrettyPrint.js
index f872e38..3101f30 100644 (file)
@@ -1,17 +1,34 @@
 
 // <script type="text/javascript">
 
+TokenReader = imports.TokenReader.TokenReader;
+ScopeParser= imports.ScopeParser.ScopeParser;
+Collapse = imports.Collapse.Collapse;
+TextStream = imports.TextStream.TextStream;
 
-toPretty = function toPretty(str)
+function  escapeHTML(str) { 
+    return str.replace(/&/g,'&amp;').
+            replace(/>/g,'&gt;'). 
+            replace(/</g,'&lt;'). 
+            replace(/"/g,'&quot;');
+};
+
+function toPretty(str)
 {
-    var tr = new JSDOC.TokenReader();
-    var toks = tr.tokenize(str,false); // dont merge xxx + . + yyyy etc.
-    var sp = new JSDOC.ScopeParser(new JSDOC.TokenStream(toks));
-    sp.buildSymbolTree();
+    
+    var txs = new TextStream(str);
+    var tr = new TokenReader({ keepComments : true, keepWhite : true });
+    var toks = tr.tokenize(txs)
+    
+    //var sp = new ScopeParser(new Collapse(toks));
+    //sp.buildSymbolTree();
+    
+    
    // sp.mungeSymboltree();
     var r = '';
-    r += sp.warnings.join("<BR>");
-    r == "<BR>";
+    //r += sp.warnings.join("<BR>");
+    //r == "<BR>";
     
     
     
@@ -20,24 +37,23 @@ toPretty = function toPretty(str)
     
     function toStyle(tok)
     {
-        if (tok.isType("whitespace")) {
+        if (tok.is("WHIT") || tok.is("COMM") ) {
             if (tok.data.indexOf("/") > -1) {
                 return 'comment';
             }
             return cs; // keep the same..
         }
-        if (tok.isType('string')) {
+        if (tok.is('STRN')) {
             return 'string';
         }
         // other 'vary things??
-        if (tok.isType('identifier') || tok.isType('dot') || tok.isType('this')) {
+        if (tok.is('NAME') || tok.data == '.' || tok.name == 'THIS') {
             return 'var';
         }
         if (/^[a-z]+/i.test(tok.data)) {
             return 'keyword';
         }
         return 'syntax'
-        
     }
     // loop through and print it...?
     
@@ -53,13 +69,14 @@ toPretty = function toPretty(str)
         if (toks[i].identifier) {
             
             r += '<span class="with-ident2">' +
-                htmlescape(toks[i].data) + '</span>';
+                escapeHTML(toks[i].data) + '</span>';
                 continue;
                 
         }
-        r += htmlescape(toks[i].data).replace(/\n/g, '<BR>');
+        r += escapeHTML(toks[i].data); //.replace(/\n/g, "<BR/>\n");
     }
     if (cs.length) r +='</span>';
+    
     return '<code class="jsdoc-pretty">'+r+'</code>';