Permalink
Browse files

works with hxcpp

  • Loading branch information...
1 parent 70e02a6 commit 33ab1d84cdfa0406b73a59b56a9b27062d9ccacf @TheHippo committed Dec 9, 2010
Showing with 48 additions and 48 deletions.
  1. +35 −35 hxjson2/JSONDecoder.hx
  2. +1 −1 hxjson2/JSONToken.hx
  3. +12 −12 hxjson2/JSONTokenizer.hx
View
@@ -41,19 +41,19 @@
package hxjson2 ;
enum JSONTokenType {
- UNKNOWN;
- COMMA;
- LEFT_BRACE;
- RIGHT_BRACE;
- LEFT_BRACKET;
- RIGHT_BRACKET;
- COLON;
- TRUE;
- FALSE;
- NULL;
- STRING;
- NUMBER;
- NAN;
+ tUNKNOWN;
+ tCOMMA;
+ tLEFT_BRACE;
+ tRIGHT_BRACE;
+ tLEFT_BRACKET;
+ tRIGHT_BRACKET;
+ tCOLON;
+ tTRUE;
+ tFALSE;
+ tNULL;
+ tSTRING;
+ tNUMBER;
+ tNAN;
}
class JSONDecoder {
@@ -114,15 +114,15 @@ class JSONDecoder {
// past the opening [
nextToken();
// check to see if we have an empty array
- if ( token.type == RIGHT_BRACKET ) {
+ if ( token.type == tRIGHT_BRACKET ) {
// we're done reading the array, so return it
return a;
}
else {
- if (!strict && token.type == JSONTokenType.COMMA) {
+ if (!strict && token.type == JSONTokenType.tCOMMA) {
nextToken();
// check to see if we're reached the end of the array
- if ( token.type == JSONTokenType.RIGHT_BRACKET ){
+ if ( token.type == JSONTokenType.tRIGHT_BRACKET ){
return a;
}
else {
@@ -137,17 +137,17 @@ class JSONDecoder {
a.push ( parseValue() );
// after the value there should be a ] or a ,
nextToken();
- if ( token.type == RIGHT_BRACKET ) {
+ if ( token.type == tRIGHT_BRACKET ) {
// we're done reading the array, so return it
return a;
- } else if ( token.type == COMMA ) {
+ } else if ( token.type == tCOMMA ) {
// move past the comma and read another value
nextToken();
// Allow arrays to have a comma after the last element
// if the decoder is not in strict mode
if ( !strict ){
// Reached ",]" as the end of the array, so return it
- if ( token.type == JSONTokenType.RIGHT_BRACKET ){
+ if ( token.type == JSONTokenType.tRIGHT_BRACKET ){
return a;
}
}
@@ -171,17 +171,17 @@ class JSONDecoder {
// grab the next token from the tokenizer
nextToken();
// check to see if we have an empty object
- if ( token.type == RIGHT_BRACE ) {
+ if ( token.type == tRIGHT_BRACE ) {
// we're done reading the object, so return it
return o;
} // in non-strict mode an empty object is also a comma
// followed by a right bracket
else {
- if ( !strict && token.type == JSONTokenType.COMMA ) {
+ if ( !strict && token.type == JSONTokenType.tCOMMA ) {
// move past the comma
nextToken();
// check to see if we're reached the end of the object
- if ( token.type == JSONTokenType.RIGHT_BRACE ) {
+ if ( token.type == JSONTokenType.tRIGHT_BRACE ) {
return o;
}
else {
@@ -192,31 +192,31 @@ class JSONDecoder {
// deal with members of the object, and use an "infinite"
// loop because we could have any amount of members
while ( true ) {
- if ( token.type == STRING ) {
+ if ( token.type == tSTRING ) {
// the string value we read is the key for the object
key = Std.string(token.value);
// move past the string to see what's next
nextToken();
// after the string there should be a :
- if ( token.type == COLON ) {
+ if ( token.type == tCOLON ) {
// move past the : and read/assign a value for the key
nextToken();
Reflect.setField(o,key,parseValue());
// move past the value to see what's next
nextToken();
// after the value there's either a } or a ,
- if ( token.type == RIGHT_BRACE ) {
+ if ( token.type == tRIGHT_BRACE ) {
// // we're done reading the object, so return it
return o;
- } else if ( token.type == COMMA ) {
+ } else if ( token.type == tCOMMA ) {
// skip past the comma and read another member
nextToken();
// Allow objects to have a comma after the last member
// if the decoder is not in strict mode
if ( !strict ){
// Reached ",}" as the end of the object, so return it
- if ( token.type == JSONTokenType.RIGHT_BRACE ) {
+ if ( token.type == JSONTokenType.tRIGHT_BRACE ) {
return o;
}
}
@@ -241,21 +241,21 @@ class JSONDecoder {
if ( token == null )
tokenizer.parseError( "Unexpected end of input" );
switch ( token.type ) {
- case LEFT_BRACE:
+ case tLEFT_BRACE:
return parseObject();
- case LEFT_BRACKET:
+ case tLEFT_BRACKET:
return parseArray();
- case STRING:
+ case tSTRING:
return token.value;
- case NUMBER:
+ case tNUMBER:
return token.value;
- case TRUE:
+ case tTRUE:
return true;
- case FALSE:
+ case tFALSE:
return false;
- case NULL:
+ case tNULL:
return null;
- case NAN:
+ case tNAN:
if (!strict)
return token.value;
else
View
@@ -56,7 +56,7 @@ class JSONToken {
* @param value The value of the token
*/
public function new(?type:JSONTokenType,?value:Dynamic = null) {
- this.type = type==null?UNKNOWN:type;
+ this.type = type==null?tUNKNOWN:type;
this.value = value;
}
}
View
@@ -87,33 +87,33 @@ class JSONTokenizer {
// examine the new character and see what we have...
switch ( ch ) {
case '{':
- token.type = LEFT_BRACE;
+ token.type = tLEFT_BRACE;
token.value = '{';
nextChar();
case '}':
- token.type = RIGHT_BRACE;
+ token.type = tRIGHT_BRACE;
token.value = '}';
nextChar();
case '[':
- token.type = LEFT_BRACKET;
+ token.type = tLEFT_BRACKET;
token.value = '[';
nextChar();
case ']':
- token.type = RIGHT_BRACKET;
+ token.type = tRIGHT_BRACKET;
token.value = ']';
nextChar();
case ',':
- token.type = COMMA;
+ token.type = tCOMMA;
token.value = ',';
nextChar();
case ':':
- token.type = COLON;
+ token.type = tCOLON;
token.value = ':';
nextChar();
case 't': // attempt to read true
var possibleTrue:String = "t" + nextChar() + nextChar() + nextChar();
if ( possibleTrue == "true" ) {
- token.type = TRUE;
+ token.type = tTRUE;
token.value = true;
nextChar();
} else {
@@ -122,7 +122,7 @@ class JSONTokenizer {
case 'f': // attempt to read false
var possibleFalse:String = "f" + nextChar() + nextChar() + nextChar() + nextChar();
if ( possibleFalse == "false" ) {
- token.type = FALSE;
+ token.type = tFALSE;
token.value = false;
nextChar();
} else {
@@ -131,7 +131,7 @@ class JSONTokenizer {
case 'n': // attempt to read null
var possibleNull:String = "n" + nextChar() + nextChar() + nextChar();
if ( possibleNull == "null" ) {
- token.type = NULL;
+ token.type = tNULL;
token.value = null;
nextChar();
} else {
@@ -140,7 +140,7 @@ class JSONTokenizer {
case 'N': //attempt to read NAN
var possibleNAN:String = 'N' + nextChar() + nextChar();
if (possibleNAN == "NAN" || possibleNAN == "NaN") {
- token.type = NAN;
+ token.type = tNAN;
token.value = Math.NaN;
nextChar();
}
@@ -252,7 +252,7 @@ class JSONTokenizer {
nextChar();
// the token for the string we'll try to read
var token:JSONToken = new JSONToken();
- token.type = STRING;
+ token.type = tSTRING;
// attach to the string to the token so we can return it
token.value = string;
return token;
@@ -384,7 +384,7 @@ class JSONTokenizer {
if ( Math.isFinite( num ) && !Math.isNaN( num ) ) {
// the token for the number we'll try to read
var token:JSONToken = new JSONToken();
- token.type = NUMBER;
+ token.type = tNUMBER;
token.value = num;
return token;
} else {

0 comments on commit 33ab1d8

Please sign in to comment.