-class JSONSpec
+EventEmitter = require('events').EventEmitter
+
+SINGLE_LINE_REGEXP = /\n/
+ISO_8601_REGEXP= /^(\d{4})-(\d{2})-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})(\.\d{3})?(([A-Z]+)|([+-]\d{2}\:\d{2}))$/
+URI_REGEXP = /^[a-z]+\:.+/
+
+class JSONSpec extends EventEmitter
+
   normalize:(src)=>
     dst = {}
     for k,v of src
-      console.log k
       dst[k] = @_normalize_attributes(v)
     return dst
 

                  if not @_validate_attribute(attr[k],v,p)
                    valid = false
          else
            console.error "datatype ",spec.datatype,"not handled"," at",path
            valid = false
        # ENUM
        if spec.enum?
          unless attr in spec.enum
            console.error "expected one of ",spec.enum,"found", attr," at",path
            valid = false
          else
            console.log "ok (enum) at",path
        # RANGE
        if spec.range?
          if spec.range.length is 2 or spec.range[2] is 'inclusive'
            unless spec.range[0] <= attr <= spec.range[1]
              console.error "expected a value between ",spec.range,"found", attr," at",path
              valid = false
            else
              console.log "ok (range) at",path
          else
            unless spec.range[0] < attr < spec.range[1]
              console.error "expected a value between ",spec.range,"found", attr," at",path
              valid = false
            else
              console.log "ok (range) at",path
        # FORMAT
        if spec.format?
          for f in spec.format
            switch f
              when 'singleline'
                if /\n/.test attr
                  console.error "expected a single-line string at ",path
                  valid = false
                else
                  console.log "ok (singleline) at",path
              when 'iso8601date'
                unless /^(\d{4})-(\d{2})-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})(\.\d{3})?(([A-Z]+)|([+-]\d{2}\:\d{2}))$/.test attr
                  console.error "expected an ISO 8601 formatted date at ",path,"found",attr
                  valid = false
                else
                  console.log "ok (iso8601date) at",path
              when 'uri'
                unless /^[a-z]+\:.+/.test attr
                  console.error "expected a URI at ",path,"found",attr
                  valid = false
                else
                  console.log "ok (uri) at",path
      console.log "RETURNING",valid
      return valid

################################################################################


                  valid = false
          when 'map'
            unless typeof attr is 'object'
              @_emit_validation_error(attr,spec,'datatype',path,attr,'object')
            else
              @_emit_message "ok","(map)",path
              if spec.attributes?
                for k,v of spec.attributes
                  p = [].concat(path)
