Пример #1
0
Файл: rex.c Проект: DeadZen/qse
/* compile a list of atoms at the outermost level and/or
 * within a subgroup */
static qse_rex_node_t* comp_branch (comp_t* c, pair_t* pair)
{
#define REACHED_END(c) \
	(IS_EOF(c) || IS_SPE(c,QSE_T('|')) || \
	 (c->gdepth > 0 && IS_SPE(c,QSE_T(')'))))

	if (REACHED_END(c))
	{
		qse_rex_node_t* nop = newnopnode (c);	
		if (nop == QSE_NULL) return QSE_NULL;
		nop->occ.min = 1; nop->occ.max = 1;
		pair->head = nop; pair->tail = nop;
	}
	else
	{
		pair->head = QSE_NULL; pair->tail = QSE_NULL;

		do
		{
			qse_rex_node_t* atom = comp_atom (c);
			if (atom == QSE_NULL) return QSE_NULL;

			if (atom->occ.min <= 0)
			{
			#if 0
				if (atom->occ.max >= OCC_MAX)
				{
					/*    
					 * +-----------next--+
					 * v                 | 
					 * BR --alter----> ORG(atom)
					 * | 
					 * +----next------------------->
					 *    
					 */
					atom = zero_or_more (c, atom);
				}
				else
				{
			#endif
					/*
					 * Given an atom, enclose it with a
					 * pseudogroup head and a psuedogroup 
					 * tail. the head is followed by a 
					 * branch that conntects to the tail 
					 * and the atom given. The atom given
					 * gets connected to the tail.
					 *   Head -> BR        -> Tail
					 *        -> ORG(atom) -> Tail
					 */
					atom = pseudo_group (c, atom);
			#if 0
				}
			#endif
				if (atom == QSE_NULL) return QSE_NULL;
			}
	
			if (pair->tail == QSE_NULL) 
			{
				QSE_ASSERT (pair->head == QSE_NULL);
				pair->head = atom;
			}
			else pair->tail->next = atom;
			pair->tail = atom;
		}
		while (!REACHED_END(c));
	}

	return pair->head;
#undef REACHED_END
}
Пример #2
0
str_iter zero_or_more(str_iter iter, str_ptr str)
{
	return zero_or_more(iter, match, str);
}