/*
 * Parsec
 * https://github.com/d-plaindoux/parsec
 *
 * Copyright (c) 2016 Didier Plaindoux
 * Licensed under the LGPL2 license.
 */
 
 module.exports = (function() {
     
     'use strict';
     
     var parser = require('../parsec/parser.js'),
         genlex = require('../genlex/genlex.js'), 
         token = require('../genlex/token.js');
     
     //
     // Facilities
     // 
     
     var tkNumber = token.parser.number,
         tkString = token.parser.string,
         tkKeyword = token.parser.keyword;
               
     function tkKey(s) {
         return tkKeyword.match(s);
     }

     /**
      * Json parser class
      */     
     function JsonParser() {
         var keywords = [ "null", "false", "true", "{", "}", "[", "]", ":", "," ];
         this.tokenizer = genlex.generator(keywords).tokenBetweenSpaces(token.builder);
     }
     
     // unit -> Parser ? Token
     function array() {
         return parser.lazy(expr).
                thenLeft(tkKey(',').then(parser.lazy(array)).opt());
     }

     // unit -> Parser ? Token
     function object() {
         return tkString.thenLeft(tkKey(':')).then(parser.lazy(expr)).
                thenLeft(tkKey(',').then(parser.lazy(object)).opt());
     }

     // unit -> Parser ? Token
     function expr() { 
         return tkNumber.
                or(tkString).
                or(tkKey("null")).
                or(tkKey("true")).
                or(tkKey("false")).
                or(tkKey('[').thenRight(parser.lazy(array).opt()).thenLeft(tkKey(']'))).
                or(tkKey('{').thenRight(parser.lazy(object).opt()).thenLeft(tkKey('}')));
     }

     // unit -> Parser ? char
     JsonParser.prototype.parser = function() {
        return this.tokenizer.chain(expr().thenLeft(parser.eos));         
     };
     
     return {
         parse : function (source, index) {
             return new JsonParser().parser().parse(source, index);             
         }
     };

}());
@@ -606,270 +606,8 @@
  %7D%0A%0A
-     /**%0A      * Json parser class%0A      */     %0A     function JsonParser() %7B%0A         var keywords = %5B %22null%22, %22false%22, %22true%22, %22%7B%22, %22%7D%22, %22%5B%22, %22%5D%22, %22:%22, %22,%22 %5D;%0A         this.tokenizer = genlex.generator(keywords).tokenBetweenSpaces(token.builder);%0A     %7D%0A     %0A
     
@@ -1387,67 +1387,33 @@
     
-// unit -%3E Parser ? char%0A     JsonParser.prototype.
+return %7B%0A         
 parse
-r =
+ :
  fun
@@ -1409,33 +1409,47 @@
 parse : function
-(
+ (source, index
 ) %7B%0A        retu
@@ -1448,191 +1448,242 @@
     
+   
-return this.tokenizer.chain(expr().thenLeft(parser.eos));         
+  var keywords = %5B %22null%22, %22false%22, %22true%22, %22%7B%22, %22%7D%22, %22%5B%22, %22%5D%22, %22:%22, %22,%22 %5D,
 %0A     
-%7D;%0A
+  
      
-%0A
      
-return %7B%0A         parse : function (source, index) %7B%0A             return new JsonParser().
+tokenizer = genlex.generator(keywords).tokenBetweenSpaces(token.builder);%0A%0A             return tokenizer.chain(expr().thenLeft(
 parser
-(
+.eos)
 ).pa

Simplify json parser code