Nikhil Marathe avatar Nikhil Marathe committed c035a88

made test.js more javascripty by adding events, removed error checking

Comments (0)

Files changed (1)

-// The complete reformatter in javascript
+// Will be a complete reformatter in javascript similar to the Yajl reformatter
 var sys = require('sys');
 var posix = require('posix');
 var yajl = require('./src/yajl');
 
-var callbacks = {
-    onNull : function(gen) {
-        gen.addNull();
-    },
-    onBoolean : function(gen, bool) {
-        gen.boolean( bool );
-    },
-    onNumber : function(gen, str) {
-        gen.number( str );
-    },
-    onString : function(gen, str) {
-        gen.string( str );
-    },
-    onMapKey : function(gen, key) {
-        gen.string( key );
-    },
-    onStartMap : function(gen) {
-        g.openMap();
-    },
-    onEndMap : function(gen) {
-        g.closeMap();
-    },
-    onStartArray : function(gen) {
-        g.openArray();
-    },
-    onEndArray : function(gen) {
-        g.closeArray();
-    }
-};
-
 function usage() {
     sys.error( "Usage: %s <filename>\n"
                +"    -m Minimize json rather than beautify (default)\n"
     usage();
 }
 
-var g = new yajl.Generator( conf, null );
-
 var handle = yajl.createHandle();
 handle.addListener( "null", function() {
     sys.debug("Nullify");
 });
 
+handle.addListener( "boolean", function(b) {
+    sys.debug(b);
+});
+
+handle.addListener( "number", function(n) {
+    sys.debug("Num: " + n);
+});
+
+handle.addListener( "string", function(s) {
+    sys.debug("String: " + s);
+});
+
+handle.addListener( "mapKey", function(k) {
+    sys.debug("Key: " + k );
+});
+
+handle.addListener( "startMap", function() {
+    sys.debug("{");
+});
+
+handle.addListener( "endMap", function() {
+    sys.debug("}");
+});
+
+handle.addListener( "startArray", function() {
+    sys.debug("[");
+});
+
+handle.addListener( "endArray", function() {
+    sys.debug("]");
+});
+
+handle.addListener( "error", function( errorString ) {
+    sys.error("Error parsing json: " + errorString );
+});
+
 var done = false;
 
 process.stdio.open();
 process.stdio.addListener( "data", function( data ) {
-    var stat = handle.parse(data);
-//    if( stat != yajl.STATUS_OK &&
-//        stat != yajl.STATUS_INSUFFICIENT_DATA ) {
-//        sys.error( handle.error( yajl.ERROR_VERBOSE, data ) );
-//    }
+    handle.parse(data);
 });
-//
-//process.stdio.addListener( "close", function() {
-//    var stat = handle.parseComplete();
-//    if( stat != yajl.STATUS_OK )
-//        sys.error( handle.error( yajl.ERROR_VERBOSE, data ) );
-//    else
-//        process.stdio.write( g.buffer() );
-//});
+process.stdio.addListener( "close", function() {
+    handle.parseComplete();
+});
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.