Permalink
Browse files

Replaced JSONTokenType class and constants with compile-time defines.

1 parent d96c733 commit caef3ee03ad9bd1beb43b46d7e585496c1e22422 @darronschall darronschall committed Nov 7, 2010
View
@@ -64,6 +64,23 @@
<source-path path-element="${src.dir}" />
<source-path path-element="${test.src.dir}" />
+ <!--
+ Define JSON Constants
+ -->
+ <define name="JSON_TOKEN::UNKNOWN" value="-1" />
+ <define name="JSON_TOKEN::COMMA" value="0" />
+ <define name="JSON_TOKEN::LEFT_BRACE" value="1" />
+ <define name="JSON_TOKEN::RIGHT_BRACE" value="2" />
+ <define name="JSON_TOKEN::LEFT_BRACKET" value="3" />
+ <define name="JSON_TOKEN::RIGHT_BRACKET" value="4" />
+ <define name="JSON_TOKEN::COLON" value="6" />
+ <define name="JSON_TOKEN::TRUE" value="7" />
+ <define name="JSON_TOKEN::FALSE" value="8" />
+ <define name="JSON_TOKEN::NULL" value="9" />
+ <define name="JSON_TOKEN::STRING" value="10" />
+ <define name="JSON_TOKEN::NUMBER" value="11" />
+ <define name="JSON_TOKEN::NAN" value="12" />
+
<!-- The TestRunner needs the flexunit libraries in the build/libs folder -->
<library-path dir="${build.libs.dir}" append="true">
<include name="*.swc" />
@@ -105,13 +122,34 @@
<load-config filename="${FLEX_HOME}/frameworks/air-config.xml" />
+ <!--
+ Define JSON Constants
+ -->
+ <define name="JSON_TOKEN::UNKNOWN" value="-1" />
+ <define name="JSON_TOKEN::COMMA" value="0" />
+ <define name="JSON_TOKEN::LEFT_BRACE" value="1" />
+ <define name="JSON_TOKEN::RIGHT_BRACE" value="2" />
+ <define name="JSON_TOKEN::LEFT_BRACKET" value="3" />
+ <define name="JSON_TOKEN::RIGHT_BRACKET" value="4" />
+ <define name="JSON_TOKEN::COLON" value="6" />
+ <define name="JSON_TOKEN::TRUE" value="7" />
+ <define name="JSON_TOKEN::FALSE" value="8" />
+ <define name="JSON_TOKEN::NULL" value="9" />
+ <define name="JSON_TOKEN::STRING" value="10" />
+ <define name="JSON_TOKEN::NUMBER" value="11" />
+ <define name="JSON_TOKEN::NAN" value="12" />
+
<source-path path-element="${src.dir}" />
<include-sources dir="${src.dir}" includes="*" />
</compc>
</target>
<target name="docs" depends="init" description="Generate ASDoc documentation">
- <java jar="${FLEX_HOME}/lib/asdoc.jar" dir="${FLEX_HOME}/frameworks" fork="true" failonerror="true">
+ <java jar="${FLEX_HOME}/lib/asdoc.jar"
+ dir="${FLEX_HOME}/frameworks" fork="true" failonerror="true">
+
+ <arg line="-load-config '${FLEX_HOME}/frameworks/air-config.xml'" />
+
<!-- Place the documentation in the "docs" directory -->
<arg line="-output ${docs.dir}" />
@@ -123,6 +161,9 @@
<!-- Include the library name in the window title -->
<arg line="-window-title 'Adobe ActionScript 3.0 Core Library - ${library.name}' "/>
+
+ <!-- Define JSON Constants -->
+ <arg line="-define+=JSON_TOKEN::UNKNOWN,-1 -define+=JSON_TOKEN::COMMA,0 -define+=JSON_TOKEN::LEFT_BRACE,1 -define+=JSON_TOKEN::RIGHT_BRACE,2 -define+=JSON_TOKEN::LEFT_BRACKET,3 -define+=JSON_TOKEN::RIGHT_BRACKET,4 -define+=JSON_TOKEN::COLON,6 -define+=JSON_TOKEN::TRUE,7 -define+=JSON_TOKEN::FALSE,8 -define+=JSON_TOKEN::NULL,9 -define+=JSON_TOKEN::STRING,10 -define+=JSON_TOKEN::NUMBER,11 -define+=JSON_TOKEN::NAN,12" />
</java>
<echo message="Documentation has been created in ${docs.dir}" />
@@ -116,20 +116,20 @@ package com.adobe.serialization.json
nextToken();
// check to see if we have an empty array
- if ( token.type == JSONTokenType.RIGHT_BRACKET )
+ if ( token.type == JSON_TOKEN::RIGHT_BRACKET )
{
// we're done reading the array, so return it
return a;
}
// in non-strict mode an empty array is also a comma
// followed by a right bracket
- else if ( !strict && token.type == JSONTokenType.COMMA )
+ else if ( !strict && token.type == JSON_TOKEN::COMMA )
{
// move past the comma
nextToken();
// check to see if we're reached the end of the array
- if ( token.type == JSONTokenType.RIGHT_BRACKET )
+ if ( token.type == JSON_TOKEN::RIGHT_BRACKET )
{
return a;
}
@@ -149,12 +149,12 @@ package com.adobe.serialization.json
// after the value there should be a ] or a ,
nextToken();
- if ( token.type == JSONTokenType.RIGHT_BRACKET )
+ if ( token.type == JSON_TOKEN::RIGHT_BRACKET )
{
// we're done reading the array, so return it
return a;
}
- else if ( token.type == JSONTokenType.COMMA )
+ else if ( token.type == JSON_TOKEN::COMMA )
{
// move past the comma and read another value
nextToken();
@@ -164,7 +164,7 @@ package com.adobe.serialization.json
if ( !strict )
{
// Reached ",]" as the end of the array, so return it
- if ( token.type == JSONTokenType.RIGHT_BRACKET )
+ if ( token.type == JSON_TOKEN::RIGHT_BRACKET )
{
return a;
}
@@ -195,20 +195,20 @@ package com.adobe.serialization.json
nextToken();
// check to see if we have an empty object
- if ( token.type == JSONTokenType.RIGHT_BRACE )
+ if ( token.type == JSON_TOKEN::RIGHT_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 )
+ else if ( !strict && token.type == JSON_TOKEN::COMMA )
{
// 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 == JSON_TOKEN::RIGHT_BRACE )
{
return o;
}
@@ -222,7 +222,7 @@ package com.adobe.serialization.json
// loop because we could have any amount of members
while ( true )
{
- if ( token.type == JSONTokenType.STRING )
+ if ( token.type == JSON_TOKEN::STRING )
{
// the string value we read is the key for the object
key = String( token.value );
@@ -231,7 +231,7 @@ package com.adobe.serialization.json
nextToken();
// after the string there should be a :
- if ( token.type == JSONTokenType.COLON )
+ if ( token.type == JSON_TOKEN::COLON )
{
// move past the : and read/assign a value for the key
nextToken();
@@ -241,12 +241,12 @@ package com.adobe.serialization.json
nextToken();
// after the value there's either a } or a ,
- if ( token.type == JSONTokenType.RIGHT_BRACE )
+ if ( token.type == JSON_TOKEN::RIGHT_BRACE )
{
// we're done reading the object, so return it
return o;
}
- else if ( token.type == JSONTokenType.COMMA )
+ else if ( token.type == JSON_TOKEN::COMMA )
{
// skip past the comma and read another member
nextToken();
@@ -256,7 +256,7 @@ package com.adobe.serialization.json
if ( !strict )
{
// Reached ",}" as the end of the object, so return it
- if ( token.type == JSONTokenType.RIGHT_BRACE )
+ if ( token.type == JSON_TOKEN::RIGHT_BRACE )
{
return o;
}
@@ -293,20 +293,20 @@ package com.adobe.serialization.json
switch ( token.type )
{
- case JSONTokenType.LEFT_BRACE:
+ case JSON_TOKEN::LEFT_BRACE:
return parseObject();
- case JSONTokenType.LEFT_BRACKET:
+ case JSON_TOKEN::LEFT_BRACKET:
return parseArray();
- case JSONTokenType.STRING:
- case JSONTokenType.NUMBER:
- case JSONTokenType.TRUE:
- case JSONTokenType.FALSE:
- case JSONTokenType.NULL:
+ case JSON_TOKEN::STRING:
+ case JSON_TOKEN::NUMBER:
+ case JSON_TOKEN::TRUE:
+ case JSON_TOKEN::FALSE:
+ case JSON_TOKEN::NULL:
return token.value;
- case JSONTokenType.NAN:
+ case JSON_TOKEN::NAN:
if ( !strict )
{
return token.value;
@@ -46,7 +46,7 @@ package com.adobe.serialization.json {
* @playerversion Flash 9.0
* @tiptext
*/
- public function JSONToken( type:int = -1 /* JSONTokenType.UNKNOWN */, value:Object = null ) {
+ public function JSONToken( type:int = JSON_TOKEN::UNKNOWN, value:Object = null ) {
_type = type;
_value = value;
}
@@ -1,69 +0,0 @@
-/*
- Copyright (c) 2008, Adobe Systems Incorporated
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- * Neither the name of Adobe Systems Incorporated nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-package com.adobe.serialization.json {
-
- /**
- * Class containing constant values for the different types
- * of tokens in a JSON encoded string.
- */
- public class JSONTokenType {
-
- public static const UNKNOWN:int = -1;
-
- public static const COMMA:int = 0;
-
- public static const LEFT_BRACE:int = 1;
-
- public static const RIGHT_BRACE:int = 2;
-
- public static const LEFT_BRACKET:int = 3;
-
- public static const RIGHT_BRACKET:int = 4;
-
- public static const COLON:int = 6;
-
- public static const TRUE:int = 7;
-
- public static const FALSE:int = 8;
-
- public static const NULL:int = 9;
-
- public static const STRING:int = 10;
-
- public static const NUMBER:int = 11;
-
- public static const NAN:int = 12;
-
- }
-
-}
@@ -93,37 +93,37 @@ package com.adobe.serialization.json {
switch ( ch )
{
case '{':
- token.type = JSONTokenType.LEFT_BRACE;
+ token.type = JSON_TOKEN::LEFT_BRACE;
token.value = '{';
nextChar();
break
case '}':
- token.type = JSONTokenType.RIGHT_BRACE;
+ token.type = JSON_TOKEN::RIGHT_BRACE;
token.value = '}';
nextChar();
break
case '[':
- token.type = JSONTokenType.LEFT_BRACKET;
+ token.type = JSON_TOKEN::LEFT_BRACKET;
token.value = '[';
nextChar();
break
case ']':
- token.type = JSONTokenType.RIGHT_BRACKET;
+ token.type = JSON_TOKEN::RIGHT_BRACKET;
token.value = ']';
nextChar();
break
case ',':
- token.type = JSONTokenType.COMMA;
+ token.type = JSON_TOKEN::COMMA;
token.value = ',';
nextChar();
break
case ':':
- token.type = JSONTokenType.COLON;
+ token.type = JSON_TOKEN::COLON;
token.value = ':';
nextChar();
break;
@@ -133,7 +133,7 @@ package com.adobe.serialization.json {
if ( possibleTrue == "true" )
{
- token.type = JSONTokenType.TRUE;
+ token.type = JSON_TOKEN::TRUE;
token.value = true;
nextChar();
}
@@ -149,7 +149,7 @@ package com.adobe.serialization.json {
if ( possibleFalse == "false" )
{
- token.type = JSONTokenType.FALSE;
+ token.type = JSON_TOKEN::FALSE;
token.value = false;
nextChar();
}
@@ -165,7 +165,7 @@ package com.adobe.serialization.json {
if ( possibleNull == "null" )
{
- token.type = JSONTokenType.NULL;
+ token.type = JSON_TOKEN::NULL;
token.value = null;
nextChar();
}
@@ -181,7 +181,7 @@ package com.adobe.serialization.json {
if ( possibleNaN == "NaN" )
{
- token.type = JSONTokenType.NAN;
+ token.type = JSON_TOKEN::NAN;
token.value = NaN;
nextChar();
}
@@ -272,7 +272,7 @@ package com.adobe.serialization.json {
// Unescape the string
// the token for the string we'll try to read
var token:JSONToken = new JSONToken();
- token.type = JSONTokenType.STRING;
+ token.type = JSON_TOKEN::STRING;
// Attach resulting string to the token to return it
token.value = unescapeString( jsonString.substr( loc, quoteIndex - loc ) );
@@ -513,7 +513,7 @@ package com.adobe.serialization.json {
{
// the token for the number that we've read
var token:JSONToken = new JSONToken();
- token.type = JSONTokenType.NUMBER;
+ token.type = JSON_TOKEN::NUMBER;
token.value = num;
return token;
}

3 comments on commit caef3ee

Hello. it seems cool that you use compile-time defines. however, what should I do to make it happen on Flash Builder 4? it keeps error'ing. I guess not so many guys grasp this advanced skills of using compile-time defines.

Thanks.

Contributor

darronschall replied Nov 8, 2010

You asked the question before I had a chance to blog about it. :)

Add the following to the command line arguments in the Library Project build propeties inside FlashBuilder (all one line):

-define+=JSON_TOKEN::UNKNOWN,-1 -define+=JSON_TOKEN::COMMA,0 -define+=JSON_TOKEN::LEFT_BRACE,1 -define+=JSON_TOKEN::RIGHT_BRACE,2 -define+=JSON_TOKEN::LEFT_BRACKET,3 -define+=JSON_TOKEN::RIGHT_BRACKET,4 -define+=JSON_TOKEN::COLON,6 -define+=JSON_TOKEN::TRUE,7 -define+=JSON_TOKEN::FALSE,8 -define+=JSON_TOKEN::NULL,9 -define+=JSON_TOKEN::STRING,10 -define+=JSON_TOKEN::NUMBER,11 -define+=JSON_TOKEN::NAN,12

Contributor

darronschall replied Nov 9, 2010

This change ended up being too obscure for users to easily build from source (requiring additional setup steps), so I backed it out in change 24c6c16.

Please sign in to comment.