コード例 #1
0
ファイル: xsJSON.c プロジェクト: dadongdong/kinomajs
void fxParseJSONArray(txScriptParser* theParser)
{
	txMachine* the = theParser->the;
	txSlot* anArray;
	txIndex aLength;
	txSlot* anItem;

	fxGetNextJSONToken(theParser);
	*(--the->stack) = mxArrayPrototype;
	anArray = fxNewArrayInstance(the);
	aLength = 0;
	anItem = anArray->next;
	for (;;) {
		if (theParser->token == XS_TOKEN_RIGHT_BRACKET)
			break;
		fxParseJSONValue(theParser);
		aLength++;
		anItem->next = fxNewSlot(the);
		anItem = anItem->next;
		anItem->kind = the->stack->kind;
		anItem->value = the->stack->value;
		the->stack++;
		if (theParser->token != XS_TOKEN_COMMA)
			break;
		fxGetNextJSONToken(theParser);
	}
	anArray->next->value.array.length = aLength;
	fxCacheArray(the, anArray);
	if (theParser->token != XS_TOKEN_RIGHT_BRACKET)
		fxReportParserError(theParser, "missing ]");
	fxGetNextJSONToken(theParser);
}
コード例 #2
0
ファイル: xs6JSON.c プロジェクト: basuke/kinomajs
void fxParseJSONArray(txMachine* the, txJSONParser* theParser)
{
	txSlot* anArray;
	txIndex aLength;
	txSlot* anItem;

	fxGetNextJSONToken(the, theParser);
	mxPush(mxArrayPrototype);
	anArray = fxNewArrayInstance(the);
	aLength = 0;
	anItem = fxLastProperty(the, anArray);
	for (;;) {
		if (theParser->token == XS_JSON_TOKEN_RIGHT_BRACKET)
			break;
		fxParseJSONValue(the, theParser);
		aLength++;
		anItem->next = fxNewSlot(the);
		anItem = anItem->next;
		anItem->kind = the->stack->kind;
		anItem->value = the->stack->value;
		the->stack++;
		if (theParser->token != XS_JSON_TOKEN_COMMA)
			break;
		fxGetNextJSONToken(the, theParser);
	}
	anArray->next->value.array.length = aLength;
	fxCacheArray(the, anArray);
	if (theParser->token != XS_JSON_TOKEN_RIGHT_BRACKET)
		mxSyntaxError("missing ]");
	fxGetNextJSONToken(the, theParser);
}
コード例 #3
0
ファイル: xsJSON.c プロジェクト: dadongdong/kinomajs
void fxParseJSON(txMachine* the, void* theStream, txGetter theGetter)
{
	txSlot* aStack = the->stack;
	txScriptParser *aParser;

	aParser = the->parser;
	if (NULL == aParser) {
		aParser = c_malloc(sizeof(txScriptParser));
		if (NULL == aParser) {
			const char *msg = "Out of memory!";
#ifdef mxDebug
			fxDebugLoop(the, (char *)msg);
#endif
			fxThrowMessage(the, XS_UNKNOWN_ERROR, (char *)msg);
		}
		the->parser = aParser;
	}
	c_memset(aParser, 0, sizeof(txScriptParser) - sizeof(aParser->buffer));
	aParser->the = the;
	aParser->stream = theStream;
	aParser->getter = theGetter;
	aParser->path = C_NULL;
	aParser->line2 = 0;
	
	mxZeroSlot(--the->stack);
	aParser->flags = the->stack;
	aParser->flags->value.string = mxEmptyString.value.string;
	aParser->flags->kind = mxEmptyString.kind;
	mxZeroSlot(--the->stack);
	aParser->string = the->stack;
	aParser->string->value.string = mxEmptyString.value.string;
	aParser->string->kind = mxEmptyString.kind;
	mxZeroSlot(--the->stack);
	aParser->flags2 = the->stack;
	aParser->flags2->value.string = mxEmptyString.value.string;
	aParser->flags2->kind = mxEmptyString.kind;
	mxZeroSlot(--the->stack);
	aParser->string2 = the->stack;
	aParser->string2->value.string = mxEmptyString.value.string;
	aParser->string2->kind = mxEmptyString.kind;

	fxGetNextCharacter(aParser);
	fxGetNextJSONToken(aParser);
	fxGetNextJSONToken(aParser);

	fxParseJSONValue(aParser);
	fxMatchToken(aParser, XS_TOKEN_EOF);
	
	if (aParser->errorCount > 0) {
		the->stack = aStack;
		c_strcpy(aParser->buffer, "JSON error(s)!");
#ifdef mxDebug
		fxDebugLoop(the, aParser->buffer);
#endif
		fxThrowMessage(the, XS_SYNTAX_ERROR, aParser->buffer);
	}
}
コード例 #4
0
ファイル: xs6JSON.c プロジェクト: basuke/kinomajs
void fxParseJSON(txMachine* the, txJSONParser* theParser)
{
	mxPush(mxEmptyString);
	theParser->string = the->stack;
	fxGetNextJSONToken(the, theParser);
	fxParseJSONValue(the, theParser);
	if (theParser->token != XS_JSON_TOKEN_EOF)
		mxSyntaxError("missing EOF");
}
コード例 #5
0
ファイル: xs6JSON.c プロジェクト: basuke/kinomajs
void fxParseJSONObject(txMachine* the, txJSONParser* theParser)
{
	txSlot* anObject;
	txSlot* at;
	txSlot* aProperty;

	fxGetNextJSONToken(the, theParser);
	mxPush(mxObjectPrototype);
	anObject = fxNewObjectInstance(the);
	for (;;) {
		if (theParser->token == XS_JSON_TOKEN_RIGHT_BRACE)
			break;
		if (theParser->token != XS_JSON_TOKEN_STRING) {
			mxSyntaxError("missing name");
			break;
		}
		mxPushString(theParser->string->value.string);
		at = fxAt(the, the->stack);
		if (theParser->reviver)
			mxPushString(theParser->string->value.string);
		fxGetNextJSONToken(the, theParser);
		if (theParser->token != XS_JSON_TOKEN_COLON) {
			mxSyntaxError("missing :");
			break;
		}
		fxGetNextJSONToken(the, theParser);
		fxParseJSONValue(the, theParser);
		if (theParser->reviver) {
			mxPushInteger(2);
			mxPushReference(anObject);
			mxPushReference(theParser->reviver);
			fxCall(the);
		}
		if (the->stack->kind != XS_UNDEFINED_KIND) {
			aProperty = fxSetProperty(the, anObject, at->value.at.id, at->value.at.index, XS_OWN);
			aProperty->kind = the->stack->kind;
			aProperty->value = the->stack->value;
		}
		the->stack++;
		the->stack++;
		if (theParser->token != XS_JSON_TOKEN_COMMA)
			break;
		fxGetNextJSONToken(the, theParser);
	}
	if (theParser->token != XS_JSON_TOKEN_RIGHT_BRACE)
		mxSyntaxError("missing }");
	fxGetNextJSONToken(the, theParser);
}
コード例 #6
0
ファイル: xsJSON.c プロジェクト: dadongdong/kinomajs
void fxParseJSONObject(txScriptParser* theParser)
{
	txMachine* the = theParser->the;
	txSlot* anObject;
	txSlot* aProperty;
	txID anID;

	fxGetNextJSONToken(theParser);
	*(--the->stack) = mxObjectPrototype;
	anObject = fxNewObjectInstance(the);
	for (;;) {
		if (theParser->token == XS_TOKEN_RIGHT_BRACE)
			break;
		if (theParser->token != XS_TOKEN_STRING) {
			fxReportParserError(theParser, "missing name");
			break;
		}
		mxInitSlot(--the->stack, XS_STRING_KIND);
		the->stack->value.string = theParser->string->value.string;
		fxGetNextJSONToken(theParser);
		if (theParser->token != XS_TOKEN_COLON) {
			fxReportParserError(theParser, "missing :");
			break;
		}
		fxGetNextJSONToken(theParser);
		fxParseJSONValue(theParser);
		aProperty = fxSetPropertyAt(the, anObject, the->stack + 1, &anID, C_NULL);
		aProperty->kind = the->stack->kind;
		aProperty->value = the->stack->value;
		the->stack += 2;
		if (theParser->token != XS_TOKEN_COMMA)
			break;
		fxGetNextJSONToken(theParser);
	}
	if (theParser->token != XS_TOKEN_RIGHT_BRACE)
		fxReportParserError(theParser, "missing }");
	fxGetNextJSONToken(theParser);
}