Skip to content

Commit

Permalink
no expect returns
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Oct 17, 2011
1 parent 0cdce28 commit 9f7816f
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions lib/json.js
Expand Up @@ -75,9 +75,11 @@ Parser.prototype.end = function(data) {
};

Parser.prototype._expect = function(ch, ex) {
if (ch !== ex) throw new
Error('Unexpected `' + ch + '`.'
+ (ex ? ' Expected: `' + ex + '`.' : ''));
if (ch !== ex) {
throw new
Error('Unexpected `' + ch + '`.'
+ (ex ? ' Expected: `' + ex + '`.' : ''));
}
};

Parser.prototype._parse = function(data) {
Expand All @@ -95,7 +97,7 @@ Parser.prototype._parse = function(data) {
this.emit('object start');
break;
default:
return this._expect(ch);
this._expect(ch);
}
break;
case '}':
Expand All @@ -114,7 +116,7 @@ Parser.prototype._parse = function(data) {
this.emit('object end');
break;
default:
return this._expect(ch);
this._expect(ch);
}
break;
case '[':
Expand All @@ -123,7 +125,7 @@ Parser.prototype._parse = function(data) {
this.emit('array start');
break;
default:
return this._expect(ch);
this._expect(ch);
}
break;
case ']':
Expand All @@ -142,7 +144,7 @@ Parser.prototype._parse = function(data) {
this.emit('array end');
break;
default:
return this._expect(ch);
this._expect(ch);
}
break;
case '"':
Expand All @@ -156,13 +158,12 @@ Parser.prototype._parse = function(data) {
this._escapeNext = 0;
} else {
this.state = 'value';
// hack for now, or else empty strings wont work
// empty strings need to be truthy
// hack for empty strings
if (!this.value) this.value = ' ';
}
break;
default:
return this._expect(ch);
this._expect(ch);
}
break;
case ',':
Expand All @@ -179,7 +180,7 @@ Parser.prototype._parse = function(data) {
}
break;
default:
return this._expect(ch);
this._expect(ch);
}
break;
case ':':
Expand All @@ -189,7 +190,7 @@ Parser.prototype._parse = function(data) {
this.value = '';
break;
default:
return this._expect(ch);
this._expect(ch);
}
break;
case '\\':
Expand All @@ -202,7 +203,7 @@ Parser.prototype._parse = function(data) {
}
break;
default:
return this._expect(ch);
this._expect(ch);
}
break;
case '-':
Expand All @@ -220,7 +221,7 @@ Parser.prototype._parse = function(data) {
switch (this.state) {
case 'unicode':
if (ch === '.' || ch === '-') {
return this._expect(ch);
this._expect(ch);
}
this.unicode += ch;
if (this.unicode.length === 4) {
Expand All @@ -232,23 +233,23 @@ Parser.prototype._parse = function(data) {
case 'value':
if (ch === '.') {
// json doesnt have .x numbers
return this._expect(ch);
this._expect(ch);
}
this.state = 'number';
this.value += ch;
break;
case 'number':
if (ch === '-') {
// json doesnt have expressions
return this._expect(ch);
this._expect(ch);
}
this.value += ch;
break;
case 'string':
this.value += ch;
break;
default:
return this._expect(ch);
this._expect(ch);
}
break;
case 'u':
Expand Down Expand Up @@ -276,7 +277,7 @@ Parser.prototype._parse = function(data) {
this.state = ch;
break;
default:
return this._expect(ch);
this._expect(ch);
}
break;
case 'n':
Expand Down Expand Up @@ -326,14 +327,14 @@ Parser.prototype._parse = function(data) {
this.value += ch;
break;
default:
return this._expect(ch);
this._expect(ch);
}
break;
default:
switch (this.state) {
case 'number':
if (ch > ' ') {
return this._expect(ch);
this._expect(ch);
}
this.state = 'value';
this.emit('number', +this.value);
Expand All @@ -342,11 +343,13 @@ Parser.prototype._parse = function(data) {
case 'string':
this.value += ch;
break;
default:
case 'value':
if (ch > ' ') {
return this._expect(ch);
this._expect(ch);
}
break;
default:
this._expect(ch);
}
break;
}
Expand Down

0 comments on commit 9f7816f

Please sign in to comment.