Exemplo n.º 1
0
errorCode addProduction(ProtoRuleEntry* ruleEntry, EventType eventType, Index typeId, QNameID qnameID, SmallIndex nonTermID)
{
	errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR;
	Production *newProd;
	Index newProdId;

	TRY(addEmptyDynEntry(&ruleEntry->dynArray, (void**)&newProd, &newProdId));

	SET_PROD_EXI_EVENT(newProd->content, eventType);
	newProd->typeId = typeId;
	newProd->qnameId = qnameID;
	SET_PROD_NON_TERM(newProd->content, nonTermID);

	return EXIP_OK;
}
Exemplo n.º 2
0
errorCode insertZeroProduction(DynGrammarRule* rule, EventType eventType, SmallIndex nonTermID, QNameID* qnameId, boolean hasSecondLevelProd)
{
	if(rule->pCount == rule->prodDim) // The dynamic array rule->production needs to be resized
	{
		void* ptr = EXIP_REALLOC(rule->production, sizeof(Production)*(rule->prodDim + DEFAULT_PROD_ARRAY_DIM));
		if(ptr == NULL)
			return MEMORY_ALLOCATION_ERROR;

		rule->production = ptr;
		rule->prodDim += DEFAULT_PROD_ARRAY_DIM;
	}

	SET_PROD_EXI_EVENT(rule->production[rule->pCount].content, eventType);
	SET_PROD_NON_TERM(rule->production[rule->pCount].content, nonTermID);
	rule->production[rule->pCount].typeId = INDEX_MAX;
	rule->production[rule->pCount].qnameId = *qnameId;

	rule->pCount += 1;
	return ERR_OK;
}
Exemplo n.º 3
0
errorCode generateBuiltInTypesGrammars(EXIPSchema* schema)
{
	unsigned int i;
	QNameID typeQnameID;
	Index typeId;
	EXIGrammar grammar;
	Index dynArrId;

	// URI id 3 -> http://www.w3.org/2001/XMLSchema
	typeQnameID.uriId = XML_SCHEMA_NAMESPACE_ID;

	grammar.count = 2;

	for(i = 0; i < schema->uriTable.uri[XML_SCHEMA_NAMESPACE_ID].lnTable.count; i++)
	{
		typeQnameID.lnId = i;
		typeId = typeQnameID.lnId;

		grammar.props = 0;
		SET_SCHEMA_GR(grammar.props);
		if(HAS_TYPE_FACET(schema->simpleTypeTable.sType[typeId].content, TYPE_FACET_NAMED_SUBTYPE_UNION))
			SET_NAMED_SUB_TYPE_OR_UNION(grammar.props);

		// One more rule slot for grammar augmentation when strict == FASLE
		grammar.rule = (GrammarRule*)memManagedAllocate(&schema->memList, sizeof(GrammarRule)*(grammar.count + 1));
		if(grammar.rule == NULL)
			return MEMORY_ALLOCATION_ERROR;

		if(typeId == SIMPLE_TYPE_ANY_TYPE)
		{
			// <xs:anyType> - The base complex type; complex ur-type
			SET_CONTENT_INDEX(grammar.props, 1);

			grammar.rule[0].production = memManagedAllocate(&schema->memList, sizeof(Production)*4);
			if(grammar.rule[0].production == NULL)
				return MEMORY_ALLOCATION_ERROR;

			SET_PROD_EXI_EVENT(grammar.rule[0].production[3].content, EVENT_AT_ALL);
			SET_PROD_NON_TERM(grammar.rule[0].production[3].content, 0);
			grammar.rule[0].production[3].typeId = INDEX_MAX;
			grammar.rule[0].production[3].qnameId.uriId = URI_MAX;
			grammar.rule[0].production[3].qnameId.lnId = LN_MAX;

			SET_PROD_EXI_EVENT(grammar.rule[0].production[2].content, EVENT_SE_ALL);
			SET_PROD_NON_TERM(grammar.rule[0].production[2].content, 1);
			grammar.rule[0].production[2].typeId = INDEX_MAX;
			grammar.rule[0].production[2].qnameId.uriId = URI_MAX;
			grammar.rule[0].production[2].qnameId.lnId = LN_MAX;

			SET_PROD_EXI_EVENT(grammar.rule[0].production[1].content, EVENT_EE);
			SET_PROD_NON_TERM(grammar.rule[0].production[1].content, GR_VOID_NON_TERMINAL);
			grammar.rule[0].production[1].typeId = INDEX_MAX;
			grammar.rule[0].production[1].qnameId.uriId = URI_MAX;
			grammar.rule[0].production[1].qnameId.lnId = LN_MAX;

			SET_PROD_EXI_EVENT(grammar.rule[0].production[0].content, EVENT_CH);
			SET_PROD_NON_TERM(grammar.rule[0].production[0].content, 1);
			grammar.rule[0].production[0].typeId = INDEX_MAX;
			grammar.rule[0].production[0].qnameId.uriId = URI_MAX;
			grammar.rule[0].production[0].qnameId.lnId = LN_MAX;

			grammar.rule[0].pCount = 4;

			grammar.rule[1].production = memManagedAllocate(&schema->memList, sizeof(Production)*3);
			if(grammar.rule[1].production == NULL)
				return MEMORY_ALLOCATION_ERROR;

			SET_PROD_EXI_EVENT(grammar.rule[1].production[2].content, EVENT_SE_ALL);
			SET_PROD_NON_TERM(grammar.rule[1].production[2].content, 1);
			grammar.rule[1].production[2].typeId = INDEX_MAX;
			grammar.rule[1].production[2].qnameId.uriId = URI_MAX;
			grammar.rule[1].production[2].qnameId.lnId = LN_MAX;

			SET_PROD_EXI_EVENT(grammar.rule[1].production[1].content, EVENT_EE);
			SET_PROD_NON_TERM(grammar.rule[1].production[1].content, GR_VOID_NON_TERMINAL);
			grammar.rule[1].production[1].typeId = INDEX_MAX;
			grammar.rule[1].production[1].qnameId.uriId = URI_MAX;
			grammar.rule[1].production[1].qnameId.lnId = LN_MAX;

			SET_PROD_EXI_EVENT(grammar.rule[1].production[0].content, EVENT_CH);
			SET_PROD_NON_TERM(grammar.rule[1].production[0].content, 1);
			grammar.rule[1].production[0].typeId = INDEX_MAX;
			grammar.rule[1].production[0].qnameId.uriId = URI_MAX;
			grammar.rule[1].production[0].qnameId.lnId = LN_MAX;

			grammar.rule[1].pCount = 3;
		}
		else // a regular simple type
		{
			grammar.rule[0].production = memManagedAllocate(&schema->memList, sizeof(Production));
			if(grammar.rule[0].production == NULL)
				return MEMORY_ALLOCATION_ERROR;

			SET_PROD_EXI_EVENT(grammar.rule[0].production[0].content, EVENT_CH);
			SET_PROD_NON_TERM(grammar.rule[0].production[0].content, 1);
			grammar.rule[0].production[0].typeId = typeId;
			grammar.rule[0].production[0].qnameId.uriId = URI_MAX;
			grammar.rule[0].production[0].qnameId.lnId = LN_MAX;
			grammar.rule[0].pCount = 1;

			grammar.rule[1].production = memManagedAllocate(&schema->memList, sizeof(Production));
			if(grammar.rule[1].production == NULL)
				return MEMORY_ALLOCATION_ERROR;

			SET_PROD_EXI_EVENT(grammar.rule[1].production[0].content, EVENT_EE);
			SET_PROD_NON_TERM(grammar.rule[1].production[0].content, GR_VOID_NON_TERMINAL);
			grammar.rule[1].production[0].typeId = INDEX_MAX;
			grammar.rule[1].production[0].qnameId.uriId = URI_MAX;
			grammar.rule[1].production[0].qnameId.lnId = LN_MAX;
			grammar.rule[1].pCount = 1;
		}

		/** Add the grammar to the schema grammar table */
		addDynEntry(&schema->grammarTable.dynArray, &grammar, &dynArrId);
		schema->uriTable.uri[3].lnTable.ln[i].typeGrammar = dynArrId;
	}

	return ERR_OK;
}
Exemplo n.º 4
0
errorCode createDocGrammar(EXIPSchema* schema, QNameID* elQnameArr, Index qnameCount)
{
	GrammarRule* tmp_rule;

	schema->docGrammar.count = DEF_DOC_GRAMMAR_RULE_NUMBER;
	schema->docGrammar.props = 0;
	SET_DOCUMENT_GR(schema->docGrammar.props);
	schema->docGrammar.rule = (GrammarRule*) memManagedAllocate(&schema->memList, sizeof(GrammarRule)*DEF_DOC_GRAMMAR_RULE_NUMBER);
	if(schema->docGrammar.rule == NULL)
		return MEMORY_ALLOCATION_ERROR;

	/* Rule for Document */
	/*
	 * Document :
	 *			  SD DocContent	0
	 */

	// IGNORED!

	/* Rule for document content */
	tmp_rule = &schema->docGrammar.rule[GR_DOC_CONTENT];

	if(elQnameArr != NULL)   // Creates Schema Informed Grammar
	{
		unsigned int e = 0;
		Index tmp_code1;

		SET_SCHEMA_GR(schema->docGrammar.props);
		tmp_code1 = qnameCount + 1;

		tmp_rule->production = (Production*) memManagedAllocate(&schema->memList, sizeof(Production)*tmp_code1);
		if(tmp_rule->production == NULL)
			return MEMORY_ALLOCATION_ERROR;

		/*
		 * DocContent :
		 *			   	SE (G-0)   DocEnd	0
		 *				SE (G-1)   DocEnd	1
		 *				⋮	⋮      ⋮
		 *				SE (G-n−1) DocEnd n-1
		 *			//	SE (*)     DocEnd	n		//  This is created as part of the Built-In grammar further on
		 */

		for(e = 0; e < qnameCount; e++)
		{
			SET_PROD_EXI_EVENT(tmp_rule->production[qnameCount - e].content, EVENT_SE_QNAME);
			SET_PROD_NON_TERM(tmp_rule->production[qnameCount - e].content, GR_DOC_END);
			tmp_rule->production[qnameCount - e].typeId = GET_LN_URI_QNAME(schema->uriTable, elQnameArr[e]).elemGrammar;
			tmp_rule->production[qnameCount - e].qnameId = elQnameArr[e];
		}
		tmp_rule->pCount = tmp_code1;
	}
	else
	{
		tmp_rule->production = (Production*) memManagedAllocate(&schema->memList, sizeof(Production));
		if(tmp_rule->production == NULL)
			return MEMORY_ALLOCATION_ERROR;

		tmp_rule->pCount = 1;
		tmp_rule->meta = 0;
	}

	/*
	 * DocContent :
	 *				SE (*) DocEnd	0
	 */
	SET_PROD_EXI_EVENT(tmp_rule->production[0].content, EVENT_SE_ALL);
	SET_PROD_NON_TERM(tmp_rule->production[0].content, GR_DOC_END);
	tmp_rule->production[0].typeId = INDEX_MAX;
	tmp_rule->production[0].qnameId.uriId = URI_MAX;
	tmp_rule->production[0].qnameId.lnId = LN_MAX;

	/* Rule for Document end */
	/* 
	 * DocEnd :
	 *			ED	        0
	 */
	tmp_rule = &schema->docGrammar.rule[GR_DOC_END];

	// TODO: consider ignoring this rule as well. In exipg generation as well ...

	/* Part 1 */
	tmp_rule->production = (Production*) memManagedAllocate(&schema->memList, sizeof(Production));
	if(tmp_rule->production == NULL)
		return MEMORY_ALLOCATION_ERROR;

	SET_PROD_EXI_EVENT(tmp_rule->production[0].content, EVENT_ED);
	SET_PROD_NON_TERM(tmp_rule->production[0].content, GR_VOID_NON_TERMINAL);
	tmp_rule->production[0].typeId = INDEX_MAX;
	tmp_rule->production[0].qnameId.uriId = URI_MAX;
	tmp_rule->production[0].qnameId.lnId = LN_MAX;

	tmp_rule->pCount = 1;
	tmp_rule->meta = 0;

	return ERR_OK;
}
Exemplo n.º 5
0
errorCode createFragmentGrammar(EXIPSchema* schema, QNameID* elQnameArr, Index qnameCount)
{
	GrammarRule* tmp_rule;

	schema->docGrammar.count = DEF_FRAG_GRAMMAR_RULE_NUMBER;
	schema->docGrammar.props = 0;
	schema->docGrammar.rule = (GrammarRule*) memManagedAllocate(&schema->memList, sizeof(GrammarRule)*DEF_FRAG_GRAMMAR_RULE_NUMBER);
	if(schema->docGrammar.rule == NULL)
		return MEMORY_ALLOCATION_ERROR;

	/* Rule for Fragment */
	/* Fragment : SD FragmentContent	0 */
	// IGNORED!

	/* Rule for Fragment content */
	tmp_rule = &schema->docGrammar.rule[GR_FRAGMENT_CONTENT];

	/* Part 1 */
	if(elQnameArr != NULL)   // Creates Schema Informed Grammar
	{
		unsigned int e = 0;
		Index tmp_code1;

		SET_SCHEMA_GR(schema->docGrammar.props);
		tmp_code1 = qnameCount + 2;

		tmp_rule->production = (Production*) memManagedAllocate(&schema->memList, sizeof(Production)*tmp_code1);
		if(tmp_rule->production == NULL)
			return MEMORY_ALLOCATION_ERROR;

		/*
		 * FragmentContent :
		 *			   	SE (F-0)   FragmentContent	0
		 *				SE (F-1)   FragmentContent	1
		 *				⋮	⋮      ⋮
		 *				SE (F-n−1) FragmentContent  n-1
		 *			//	SE (*)     FragmentContent	n		//  This is created as part of the Build-In grammar further on
 		 *			//	ED		   					n+1		//  This is created as part of the Build-In grammar further on
		 */

		for(e = 0; e < qnameCount; e++)
		{
			SET_PROD_EXI_EVENT(tmp_rule->production[qnameCount - e].content, EVENT_SE_QNAME);
			SET_PROD_NON_TERM(tmp_rule->production[qnameCount - e].content, GR_FRAGMENT_CONTENT);
			tmp_rule->production[qnameCount - e].typeId = GET_LN_URI_QNAME(schema->uriTable, elQnameArr[e]).elemGrammar;
			tmp_rule->production[qnameCount - e].qnameId = elQnameArr[e];
		}
		tmp_rule->pCount = tmp_code1;
	}
	else
	{
		tmp_rule->production = (Production*) memManagedAllocate(&schema->memList, sizeof(Production)*2);
		if(tmp_rule->production == NULL)
			return MEMORY_ALLOCATION_ERROR;

		/* Productions further on... */
		tmp_rule->pCount = 2;
	}

	/*
	 * FragmentContent :
	 *				SE (*) FragmentContent	0
	 *				ED						1
	 */

	SET_PROD_EXI_EVENT(tmp_rule->production[0].content, EVENT_ED);
	SET_PROD_NON_TERM(tmp_rule->production[0].content, GR_VOID_NON_TERMINAL);
	tmp_rule->production[0].typeId = INDEX_MAX;
	tmp_rule->production[0].qnameId.uriId = URI_MAX;
	tmp_rule->production[0].qnameId.lnId = LN_MAX;

	SET_PROD_EXI_EVENT(tmp_rule->production[1].content, EVENT_SE_ALL);
	SET_PROD_NON_TERM(tmp_rule->production[1].content, GR_FRAGMENT_CONTENT);
	tmp_rule->production[1].typeId = INDEX_MAX;
	tmp_rule->production[1].qnameId.uriId = URI_MAX;
	tmp_rule->production[1].qnameId.lnId = LN_MAX;

	return ERR_OK;
}
Exemplo n.º 6
0
errorCode createBuiltInElementGrammar(EXIGrammar* elementGrammar, EXIStream* strm)
{
	DynGrammarRule* tmp_rule;

	elementGrammar->count = DEF_ELEMENT_GRAMMAR_RULE_NUMBER;
	elementGrammar->props = 0;
	SET_BUILT_IN_ELEM_GR(elementGrammar->props);
	elementGrammar->rule = (GrammarRule*) EXIP_MALLOC(sizeof(DynGrammarRule)*DEF_ELEMENT_GRAMMAR_RULE_NUMBER);
	if(elementGrammar->rule == NULL)
		return MEMORY_ALLOCATION_ERROR;

	/* Rule for StartTagContent */
	/* StartTagContent :
	 *						EE	                    0.0
	 *						AT (*) StartTagContent	0.1
	 *						NS StartTagContent	    0.2
	 *						SC Fragment	            0.3
	 *						SE (*) ElementContent	0.4
	 *						CH ElementContent	    0.5
	 *						ER ElementContent	    0.6
	 *						CM ElementContent	    0.7.0
	 *						PI ElementContent	    0.7.1
	 */

	tmp_rule = &((DynGrammarRule*) elementGrammar->rule)[GR_START_TAG_CONTENT];

	/* Part 1 */
	tmp_rule->production = (Production*) EXIP_MALLOC(sizeof(Production)*DEFAULT_PROD_ARRAY_DIM);
	if(tmp_rule->production == NULL)
		return MEMORY_ALLOCATION_ERROR;

	/* The part 1 productions get added later... */
	tmp_rule->pCount = 0;
	tmp_rule->meta = 0;
	tmp_rule->prodDim = DEFAULT_PROD_ARRAY_DIM;

	/* Rule for ElementContent */
	/* ElementContent :
	 *						EE	                    0
	 *						SE (*) ElementContent	1.0
	 *						CH ElementContent	    1.1
	 *						ER ElementContent	    1.2
	 *						CM ElementContent	    1.3.0
	 *						PI ElementContent	    1.3.1
	 */
	tmp_rule = &((DynGrammarRule*) elementGrammar->rule)[GR_ELEMENT_CONTENT];

	/* Part 1 */
	tmp_rule->production = (Production*) EXIP_MALLOC(sizeof(Production)*DEFAULT_PROD_ARRAY_DIM);
	if(tmp_rule->production == NULL)
		return MEMORY_ALLOCATION_ERROR;

	/* EE	                  0 */
	SET_PROD_EXI_EVENT(tmp_rule->production[0].content, EVENT_EE);
	SET_PROD_NON_TERM(tmp_rule->production[0].content, GR_VOID_NON_TERMINAL);
	tmp_rule->production[0].typeId = INDEX_MAX;
	tmp_rule->production[0].qnameId.uriId = URI_MAX;
	tmp_rule->production[0].qnameId.lnId = LN_MAX;
	tmp_rule->pCount = 1;
	tmp_rule->prodDim = DEFAULT_PROD_ARRAY_DIM;
	/* More part 1 productions get added later... */

	return ERR_OK;
}