コード例 #1
0
ファイル: xsJSON.c プロジェクト: dadongdong/kinomajs
void fxParseJSONValue(txScriptParser* theParser)
{
	txMachine* the = theParser->the;
	switch (theParser->token) {
	case XS_TOKEN_FALSE:
		mxInitSlot(--the->stack, XS_BOOLEAN_KIND);
		the->stack->value.boolean = 0;
		fxGetNextJSONToken(theParser);
		break;
	case XS_TOKEN_TRUE:
		mxInitSlot(--the->stack, XS_BOOLEAN_KIND);
		the->stack->value.boolean = 1;
		fxGetNextJSONToken(theParser);
		break;
	case XS_TOKEN_NULL:
		mxInitSlot(--the->stack, XS_NULL_KIND);
		fxGetNextJSONToken(theParser);
		break;
	case XS_TOKEN_INTEGER:
		mxInitSlot(--the->stack, XS_INTEGER_KIND);
		the->stack->value.integer = theParser->integer;
		fxGetNextJSONToken(theParser);
		break;
	case XS_TOKEN_NUMBER:
		mxInitSlot(--the->stack, XS_NUMBER_KIND);
		the->stack->value.number = theParser->number;
		fxGetNextJSONToken(theParser);
		break;
	case XS_TOKEN_STRING:
		mxInitSlot(--the->stack, XS_STRING_KIND);
		the->stack->value.string = theParser->string->value.string;
		fxGetNextJSONToken(theParser);
		break;
	case XS_TOKEN_LEFT_BRACE:
		fxParseJSONObject(theParser);
		break;
	case XS_TOKEN_LEFT_BRACKET:
		fxParseJSONArray(theParser);
		break;
	default:
		mxInitSlot(--the->stack, XS_UNDEFINED_KIND);
		fxReportParserError(theParser, "invalid value");
		break;
	}
}
コード例 #2
0
ファイル: xs6JSON.c プロジェクト: basuke/kinomajs
void fxParseJSONValue(txMachine* the, txJSONParser* theParser)
{
	switch (theParser->token) {
	case XS_JSON_TOKEN_FALSE:
		mxPushBoolean(0);
		fxGetNextJSONToken(the, theParser);
		break;
	case XS_JSON_TOKEN_TRUE:
		mxPushBoolean(1);
		fxGetNextJSONToken(the, theParser);
		break;
	case XS_JSON_TOKEN_NULL:
		mxPushNull();
		fxGetNextJSONToken(the, theParser);
		break;
	case XS_JSON_TOKEN_INTEGER:
		mxPushInteger(theParser->integer);
		fxGetNextJSONToken(the, theParser);
		break;
	case XS_JSON_TOKEN_NUMBER:
		mxPushNumber(theParser->number);
		fxGetNextJSONToken(the, theParser);
		break;
	case XS_JSON_TOKEN_STRING:
		mxPushString(theParser->string->value.string);
		fxGetNextJSONToken(the, theParser);
		break;
	case XS_JSON_TOKEN_LEFT_BRACE:
		fxParseJSONObject(the, theParser);
		break;
	case XS_JSON_TOKEN_LEFT_BRACKET:
		fxParseJSONArray(the, theParser);
		break;
	default:
		mxPushUndefined();
		mxSyntaxError("invalid value");
		break;
	}
}