예제 #1
0
errorCode recursiveTextGrammarOutput(QNameID qnameid, Index grIndex, EXIGrammar* gr, EXIPSchema* schema, FILE* out)
{
	errorCode tmp_err_code = UNEXPECTED_ERROR;
	Index r, p;

	tmp_err_code = textGrammarOutput(qnameid, grIndex, gr, schema, out);
	if(tmp_err_code != ERR_OK)
		return tmp_err_code;

	for(r = 0; r < gr->count; r++)
	{
		for(p = 0; p < gr->rule[r].pCount; p++)
		{
			if(GET_PROD_EXI_EVENT(gr->rule[r].production[p].content) == EVENT_SE_QNAME &&
					gr->rule[r].production[p].typeId != INDEX_MAX)
			{
				tmp_err_code = recursiveTextGrammarOutput(gr->rule[r].production[p].qnameId, gr->rule[r].production[p].typeId, &schema->grammarTable.grammar[gr->rule[r].production[p].typeId], schema, out);
				if(tmp_err_code != ERR_OK)
					return tmp_err_code;
			}
		}
	}

	return ERR_OK;
}
예제 #2
0
errorCode convertProtoGrammar(AllocList* memlist, ProtoGrammar* pg, EXIGrammar* exiGrammar)
{
	Index ruleIter;
	Index prodIter;
	uint16_t attrCount;
	boolean hasEE;

	exiGrammar->props = 0;
	SET_SCHEMA_GR(exiGrammar->props);
	SET_CONTENT_INDEX(exiGrammar->props, pg->contentIndex);
	exiGrammar->count = pg->count;

	exiGrammar->rule = (GrammarRule*) memManagedAllocate(memlist, sizeof(GrammarRule)*(pg->count));
	if(exiGrammar->rule == NULL)
		return EXIP_MEMORY_ALLOCATION_ERROR;

	for(ruleIter = 0; ruleIter < pg->count; ruleIter++)
	{
		attrCount = 0;
		hasEE = FALSE;

		exiGrammar->rule[ruleIter].production = (Production*) memManagedAllocate(memlist, sizeof(Production)*pg->rule[ruleIter].count);
		if(exiGrammar->rule[ruleIter].production == NULL)
			return EXIP_MEMORY_ALLOCATION_ERROR;

		exiGrammar->rule[ruleIter].pCount = pg->rule[ruleIter].count;
		exiGrammar->rule[ruleIter].meta = 0;

		for(prodIter = 0; prodIter < pg->rule[ruleIter].count; prodIter++)
		{
			if(GET_PROD_EXI_EVENT_CLASS(pg->rule[ruleIter].prod[prodIter].content) == EVENT_AT_CLASS)
				attrCount++;
			else if(GET_PROD_EXI_EVENT(pg->rule[ruleIter].prod[prodIter].content) == EVENT_EE)
				hasEE = TRUE;
			exiGrammar->rule[ruleIter].production[prodIter] = pg->rule[ruleIter].prod[prodIter];
		}

		RULE_SET_AT_COUNT(exiGrammar->rule[ruleIter].meta, attrCount);
		if(hasEE)
			RULE_SET_CONTAIN_EE(exiGrammar->rule[ruleIter].meta);
	}

	return EXIP_OK;
}
예제 #3
0
errorCode cloneProtoGrammar(ProtoGrammar* src, ProtoGrammar* dest)
{
	errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR;
	ProtoRuleEntry* pRuleEntry;
	Index i;
	Index j;

	TRY(createProtoGrammar(src->count, dest));

	dest->contentIndex = src->contentIndex;
	for (i = 0; i < src->count; i++)
	{
		TRY(addProtoRule(dest, src->rule[i].count, &pRuleEntry));

		for (j = 0; j < src->rule[i].count; j++)
		{
			TRY(addProduction(pRuleEntry, GET_PROD_EXI_EVENT(src->rule[i].prod[j].content), src->rule[i].prod[j].typeId, src->rule[i].prod[j].qnameId, GET_PROD_NON_TERM(src->rule[i].prod[j].content)));
		}
	}

	return EXIP_OK;
}
예제 #4
0
errorCode textGrammarOutput(QNameID qnameid, Index grIndex, EXIGrammar* gr, EXIPSchema* schema, FILE* out)
{
	Index ruleIter, prodIter;
	Production* tmpProd;
	EXIType exiType = VALUE_TYPE_NONE;

	fprintf(out, "Grammar %d [%d:%d] ", (int) grIndex, (int) qnameid.uriId, (int) qnameid.lnId);
	fwrite(schema->uriTable.uri[qnameid.uriId].uriStr.str, sizeof(CharType), schema->uriTable.uri[qnameid.uriId].uriStr.length, out);
	fprintf(out, ":");
	fwrite(GET_LN_URI_QNAME(schema->uriTable, qnameid).lnStr.str, sizeof(CharType), GET_LN_URI_QNAME(schema->uriTable, qnameid).lnStr.length, out);
	fprintf(out, "\n");

	for(ruleIter = 0; ruleIter < gr->count; ruleIter++)
	{
		fprintf(out, "NT-%d: \n", (int) ruleIter);

		for(prodIter = 0; prodIter < gr->rule[ruleIter].pCount; prodIter++)
		{
			tmpProd = &gr->rule[ruleIter].production[gr->rule[ruleIter].pCount - 1 - prodIter];
			if(GET_PROD_EXI_EVENT(tmpProd->content) != EVENT_SE_QNAME && tmpProd->typeId != INDEX_MAX)
				exiType = GET_EXI_TYPE(schema->simpleTypeTable.sType[tmpProd->typeId].content);
			else
				exiType = VALUE_TYPE_NONE;
			switch(GET_PROD_EXI_EVENT(tmpProd->content))
			{
				case EVENT_SD:
					fprintf(out, "\tSD ");
					break;
				case EVENT_ED:
					fprintf(out, "\tED ");
					break;
				case EVENT_SE_QNAME:
					fprintf(out, "\tSE ([%d:%d]", (int) tmpProd->qnameId.uriId, (int) tmpProd->qnameId.lnId);
					fwrite(schema->uriTable.uri[tmpProd->qnameId.uriId].uriStr.str, sizeof(CharType), schema->uriTable.uri[tmpProd->qnameId.uriId].uriStr.length, out);
					fprintf(out, ":");
					fwrite(GET_LN_URI_QNAME(schema->uriTable, tmpProd->qnameId).lnStr.str, sizeof(CharType), GET_LN_URI_QNAME(schema->uriTable, tmpProd->qnameId).lnStr.length, out);
					fprintf(out, ") ");
					break;
				case EVENT_SE_URI:
					fprintf(out, "\tSE (uri) ");
					break;
				case EVENT_SE_ALL:
					fprintf(out, "\tSE (*) ");
					break;
				case EVENT_EE:
					fprintf(out, "\tEE ");
					break;
				case EVENT_AT_QNAME:
					fprintf(out, "\tAT ([%d:%d]", (int) tmpProd->qnameId.uriId, (int) tmpProd->qnameId.lnId);
					fwrite(schema->uriTable.uri[tmpProd->qnameId.uriId].uriStr.str, sizeof(CharType), schema->uriTable.uri[tmpProd->qnameId.uriId].uriStr.length, out);
					fprintf(out, ":");
					fwrite(GET_LN_URI_QNAME(schema->uriTable, tmpProd->qnameId).lnStr.str, sizeof(CharType), GET_LN_URI_QNAME(schema->uriTable, tmpProd->qnameId).lnStr.length, out);
					fprintf(out, ") ");
					writeValueTypeString(out, exiType);
					break;
				case EVENT_AT_URI:
					fprintf(out, "\tAT (uri) ");
					break;
				case EVENT_AT_ALL:
					fprintf(out, "\tAT (*) ");
					writeValueTypeString(out, exiType);
					break;
				case EVENT_CH:
					fprintf(out, "\tCH ");
					writeValueTypeString(out, exiType);
					break;
				case EVENT_NS:
					fprintf(out, "\tNS ");
					break;
				case EVENT_CM:
					fprintf(out, "\tCM ");
					break;
				case EVENT_PI:
					fprintf(out, "\tPI ");
					break;
				case EVENT_DT:
					fprintf(out, "\tDT ");
					break;
				case EVENT_ER:
					fprintf(out, "\tER ");
					break;
				case EVENT_SC:
					fprintf(out, "\tSC ");
					break;
				case EVENT_VOID:
					fprintf(out, " ");
					break;
				default:
					return UNEXPECTED_ERROR;
			}
			if(GET_PROD_NON_TERM(tmpProd->content) != GR_VOID_NON_TERMINAL)
			{
				fprintf(out, "\tNT-%u\t", (unsigned int) GET_PROD_NON_TERM(tmpProd->content));
			}
			fprintf(out, "%d\n", (int) prodIter);
		}
		fprintf(out, "\n");
	}

	return ERR_OK;
}
예제 #5
0
errorCode printProtoGrammarRule(SmallIndex nonTermID, ProtoRuleEntry* rule)
{
	Index j = 0;
	Production* tmpProd;

	DEBUG_MSG(INFO, EXIP_DEBUG, ("\n>RULE\n"));
	DEBUG_MSG(INFO, EXIP_DEBUG, ("NT-%u:", (unsigned int) nonTermID));

	DEBUG_MSG(INFO, EXIP_DEBUG, ("\n"));

	for(j = 0; j < rule->count; j++)
	{
		tmpProd = &rule->prod[j];
		DEBUG_MSG(INFO, EXIP_DEBUG, ("\t"));

		switch(GET_PROD_EXI_EVENT(tmpProd->content))
		{
			case EVENT_SD:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("SD                    "));
				break;
			case EVENT_ED:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("ED                    "));
				break;
			case EVENT_SE_QNAME:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("SE (qname: %u:%u)     ", (unsigned int) tmpProd->qnameId.uriId, (unsigned int) tmpProd->qnameId.lnId));
				break;
			case EVENT_SE_URI:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("SE (uri)              "));
				break;
			case EVENT_SE_ALL:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("SE (*)                "));
				break;
			case EVENT_EE:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("EE                    "));
				break;
			case EVENT_AT_QNAME:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("AT (qname %u:%u) [%d] ", (unsigned int) tmpProd->qnameId.uriId, (unsigned int) tmpProd->qnameId.lnId, (unsigned int) tmpProd->typeId));
				break;
			case EVENT_AT_URI:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("AT (uri)              "));
				break;
			case EVENT_AT_ALL:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("AT (*)                "));
				break;
			case EVENT_CH:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("CH [%d]               ", (unsigned int) tmpProd->typeId));
				break;
			case EVENT_NS:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("NS                    "));
				break;
			case EVENT_CM:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("CM                    "));
				break;
			case EVENT_PI:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("PI                    "));
				break;
			case EVENT_DT:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("DT                    "));
				break;
			case EVENT_ER:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("ER                    "));
				break;
			case EVENT_SC:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("SC                    "));
				break;
			case EVENT_VOID:
				DEBUG_MSG(INFO, EXIP_DEBUG, (" "));
				break;
			default:
				return EXIP_UNEXPECTED_ERROR;
		}
		if(GET_PROD_NON_TERM(tmpProd->content) != GR_VOID_NON_TERMINAL)
		{
			DEBUG_MSG(INFO, EXIP_DEBUG, ("NT-%u", (unsigned int) GET_PROD_NON_TERM(tmpProd->content)));
		}

		DEBUG_MSG(INFO, EXIP_DEBUG, ("\n"));
	}
	return EXIP_OK;
}
예제 #6
0
파일: grammars.c 프로젝트: actility/ong
errorCode printGrammarRule(SmallIndex nonTermID, GrammarRule* rule, EXIPSchema *schema)
{
	Index j = 0;
	Production* tmpProd;
	EXIType exiType = VALUE_TYPE_NONE;

	DEBUG_MSG(INFO, EXIP_DEBUG, ("\n>RULE\n"));
	DEBUG_MSG(INFO, EXIP_DEBUG, ("NT-%u:", (unsigned int) nonTermID));

	DEBUG_MSG(INFO, EXIP_DEBUG, ("\n"));

	for(j = 0; j < rule->pCount; j++)
	{
		String *localName = NULL;
		tmpProd = &rule->production[rule->pCount - 1 - j];
		DEBUG_MSG(INFO, EXIP_DEBUG, ("\t"));

		if(GET_PROD_EXI_EVENT(tmpProd->content) != EVENT_SE_QNAME && tmpProd->typeId != INDEX_MAX)
			exiType = GET_EXI_TYPE(schema->simpleTypeTable.sType[tmpProd->typeId].content);
		else
			exiType = VALUE_TYPE_NONE;

		switch(GET_PROD_EXI_EVENT(tmpProd->content))
		{
			case EVENT_SD:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("SD "));
				break;
			case EVENT_ED:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("ED "));
				break;
			case EVENT_SE_QNAME:
			{
				QNameID *qname = &tmpProd->qnameId;
				localName = &(GET_LN_URI_P_QNAME(schema->uriTable, qname).lnStr);
				DEBUG_MSG(INFO, EXIP_DEBUG, ("SE (qname: %u:%u) ", (unsigned int) qname->uriId, (unsigned int) qname->lnId));
				break;
			}
			case EVENT_SE_URI:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("SE (uri) "));
				break;
			case EVENT_SE_ALL:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("SE (*) "));
				break;
			case EVENT_EE:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("EE "));
				break;
			case EVENT_AT_QNAME:
			{
				QNameID *qname = &tmpProd->qnameId;
				localName = &(GET_LN_URI_P_QNAME(schema->uriTable, qname).lnStr);
				DEBUG_MSG(INFO, EXIP_DEBUG, ("AT (qname %u:%u) ", (unsigned int) tmpProd->qnameId.uriId, (unsigned int) tmpProd->qnameId.lnId));
				writeValueTypeString(exiType);
				break;
			}
			case EVENT_AT_URI:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("AT (uri) "));
				break;
			case EVENT_AT_ALL:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("AT (*) "));
				writeValueTypeString(exiType);
				break;
			case EVENT_CH:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("CH "));
				writeValueTypeString(exiType);
				break;
			case EVENT_NS:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("NS "));
				break;
			case EVENT_CM:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("CM "));
				break;
			case EVENT_PI:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("PI "));
				break;
			case EVENT_DT:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("DT "));
				break;
			case EVENT_ER:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("ER "));
				break;
			case EVENT_SC:
				DEBUG_MSG(INFO, EXIP_DEBUG, ("SC "));
				break;
			case EVENT_VOID:
				DEBUG_MSG(INFO, EXIP_DEBUG, (" "));
				break;
			default:
				return UNEXPECTED_ERROR;
		}
		DEBUG_MSG(INFO, EXIP_DEBUG, ("\t"));
		if(GET_PROD_NON_TERM(tmpProd->content) != GR_VOID_NON_TERMINAL)
		{
			DEBUG_MSG(INFO, EXIP_DEBUG, ("NT-%u", (unsigned int) GET_PROD_NON_TERM(tmpProd->content)));
		}
		DEBUG_MSG(INFO, EXIP_DEBUG, ("\t"));

		DEBUG_MSG(INFO, EXIP_DEBUG, ("%u", (unsigned int) j));

		if (localName != NULL)
		{
			DEBUG_MSG(INFO, EXIP_DEBUG, ("\t"));
			printString(localName);
		}
		DEBUG_MSG(INFO, EXIP_DEBUG, ("\n"));
	}
	return ERR_OK;
}