Exemplo n.º 1
0
void
anjuta_token_style_format (AnjutaTokenStyle *style, AnjutaToken *list)
{
	AnjutaToken *item;
	AnjutaToken *last;
	AnjutaToken *text;
	AnjutaToken *prev;

	/* Find following tokens */
	for (last = list; last != NULL; last = anjuta_token_next (last))
	{
		/* Get all tokens in group */
		last = anjuta_token_last (last);

		gint flags = anjuta_token_get_flags (last);
		if (!(flags & (ANJUTA_TOKEN_ADDED | ANJUTA_TOKEN_REMOVED))) break;
	}

	/* Find previous token */
	for (prev = list; prev != NULL; prev = anjuta_token_previous (prev))
	{
		gint flags = anjuta_token_get_flags (prev);
		if ((anjuta_token_get_length (prev) != 0) && !(flags & (ANJUTA_TOKEN_ADDED | ANJUTA_TOKEN_REMOVED))) break;
		list = prev;
	}

	for (item = list; (item != NULL) && (item != last); item = anjuta_token_next (item))
	{
		if ((anjuta_token_get_flags (item) & ANJUTA_TOKEN_ADDED) &&
			!(anjuta_token_get_flags (item) & ANJUTA_TOKEN_REMOVED))
		{
			switch (anjuta_token_get_type (item))
			{
			case ANJUTA_TOKEN_START:
				text = anjuta_token_style_lookup (style, ANJUTA_TOKEN_START, FALSE);
				anjuta_token_set_flags (text, ANJUTA_TOKEN_ADDED);
				anjuta_token_insert_after (item, text);
				anjuta_token_merge (item, text);
				item = text;
				break;
			case ANJUTA_TOKEN_NEXT:
				text = anjuta_token_style_lookup (style, ANJUTA_TOKEN_NEXT, FALSE);
				anjuta_token_set_flags (text, ANJUTA_TOKEN_ADDED);
				anjuta_token_insert_after (item, text);
				anjuta_token_merge (item, text);
				item = text;
				break;
			case ANJUTA_TOKEN_LAST:
				text = anjuta_token_style_lookup (style, ANJUTA_TOKEN_LAST, FALSE);
				anjuta_token_set_flags (text, ANJUTA_TOKEN_ADDED);
				anjuta_token_insert_after (item, text);
				anjuta_token_merge (item, text);
				item = text;
				break;
			default:
				break;
			}
		}
	}
}
Exemplo n.º 2
0
/**
 * anjuta_token_stream_push:
 * @parent: a parent #AnjutaTokenStream object or NULL.
 * @root: a token or NULL
 * @content: a token list.
 *
 * Create a new stream from a list of tokens. If a parent stream is passed,
 * the new stream keep a link on it, so we can return it when the new stream
 * will be destroyed.
 *
 * Return value: The newly created stream.
 */
AnjutaTokenStream *
anjuta_token_stream_push (AnjutaTokenStream *parent, AnjutaToken *root, AnjutaToken *content, GFile *file)
{
	AnjutaTokenStream *child;

	child = g_new (AnjutaTokenStream, 1);
	child->first = content;
	child->pos = 0;
	child->begin = 0;
	child->parent = parent;

	child->next = anjuta_token_next (content);
	child->start = child->next;
	child->last = anjuta_token_last (content);
	if (child->last == content) child->last = NULL;

	child->root = root == NULL ? anjuta_token_new_static (ANJUTA_TOKEN_FILE, NULL) : root;
	if (file == NULL)
	{
		child->current_directory = parent == NULL ? NULL : (parent->current_directory == NULL ? NULL : g_object_ref (parent->current_directory));
		child->current_file = NULL;
	}
	else
	{
		child->current_directory = g_file_get_parent (file);
		child->current_file = g_object_ref (file);
	}

	return child;
}
Exemplo n.º 3
0
/**
 * anjuta_token_stream_push:
 * @parent: a parent #AnjutaTokenStream object or NULL.
 * @root: a token or NULL
 * @content: a token list.
 *
 * Create a new stream from a list of tokens. If a parent stream is passed,
 * the new stream keep a link on it, so we can return it when the new stream
 * will be destroyed.
 *
 * Return value: The newly created stream.
 */
AnjutaTokenStream *
anjuta_token_stream_push (AnjutaTokenStream *parent, AnjutaToken *root, AnjutaToken *content, GFile *file)
{
	AnjutaTokenStream *child;
	AnjutaTokenStream *stream;

	/* Check if content is not already parsed to avoid endless parsing loop */
	for (stream = parent; stream != NULL; stream = stream->parent)
	{
		if (stream->content == content) return NULL;
	}

	/* Create new stream */
	child = g_new (AnjutaTokenStream, 1);
	child->first = content;
	child->pos = 0;
	child->begin = 0;
	child->parent = parent;
	child->content = content;
	child->token = content;
	child->start = child->token;
	child->last = content == NULL ? NULL : anjuta_token_last (content);

	child->root = root == NULL ? anjuta_token_new_static (ANJUTA_TOKEN_FILE, NULL) : root;
	if (file == NULL)
	{
		child->current_directory = parent == NULL ? NULL : (parent->current_directory == NULL ? NULL : g_object_ref (parent->current_directory));
		child->current_file = NULL;
	}
	else
	{
		child->current_directory = g_file_get_parent (file);
		child->current_file = g_object_ref (file);
	}

	return child;
}