diff -rupN geany-1.26/src/symbols.c geany-1.26-ctags-scss-fix/src/symbols.c
--- geany-1.26/src/symbols.c	2015-11-01 17:44:11.000000000 +0100
+++ geany-1.26-ctags-scss-fix/src/symbols.c	2016-02-14 14:47:00.000000000 +0100
@@ -331,6 +331,7 @@ const gchar *symbols_get_context_separat
 		case GEANY_FILETYPES_GLSL:	/* for structs */
 		/*case GEANY_FILETYPES_RUBY:*/ /* not sure what to use atm*/
 		case GEANY_FILETYPES_PHP:
+		case GEANY_FILETYPES_CSS:
 		case GEANY_FILETYPES_POWERSHELL:
 		case GEANY_FILETYPES_RUST:
 		case GEANY_FILETYPES_ZEPHIR:
@@ -781,9 +782,12 @@ static void add_top_level_items(GeanyDoc
 		case GEANY_FILETYPES_CSS:
 		{
 			tag_list_add_groups(tag_store,
+				&(tv_iters.tag_interface), _("ID Selectors"), ICON_STRUCT,
 				&(tv_iters.tag_class), _("Classes"), ICON_CLASS,
-				&(tv_iters.tag_variable), _("ID Selectors"), ICON_VAR,
-				&(tv_iters.tag_struct), _("Type Selectors"), ICON_STRUCT, NULL);
+				&(tv_iters.tag_struct), _("Type Selectors"), ICON_STRUCT,
+				&(tv_iters.tag_function), _("Mixins"), ICON_METHOD,
+				&(tv_iters.tag_variable), _("Variables"), ICON_VAR,
+				NULL);
 			break;
 		}
 		case GEANY_FILETYPES_REST:
diff -rupN geany-1.26/tagmanager/ctags/css.c geany-1.26-ctags-scss-fix/tagmanager/ctags/css.c
--- geany-1.26/tagmanager/ctags/css.c	2015-11-01 17:44:11.000000000 +0100
+++ geany-1.26-ctags-scss-fix/tagmanager/ctags/css.c	2016-02-17 16:17:34.000000000 +0100
@@ -1,270 +1,893 @@
-/***************************************************************************
- * css.c
- * Token-based parser for CSS definitions
- * Author - Colomban Wendling <colomban@geany.org>
- **************************************************************************/
-#include "general.h"
+/*
+*   Copyright (c) 2013, Colomban Wendling <ban@herbesfolles.org>
+*
+*   This source code is released for free distribution under the terms of the
+*   GNU General Public License.
+*
+*   This module contains code for generating tags for the CSS scripting
+*   language.
+*/
+
+/*
+* Improved SCSS by Robert Zajda february 2016 ( see http://geany.robert.dvu.pl/ )
+* TODO: More cleanups
+*/
+
+/*
+*   INCLUDE FILES
+*/
+#include "general.h"  /* must always come first */
+#include "main.h"
+#include "parse.h"
+#include "read.h"
+#include "vstring.h"
+#include "keyword.h"
+#include "entry.h"
 
-#include <string.h> 
-#include <ctype.h> 
 
-#include "entry.h"
-#include "parse.h" 
-#include "read.h" 
+#define SCOPE_SEPARATOR "::"
 
 
-typedef enum eCssKinds {
-	K_CLASS, K_SELECTOR, K_ID
+typedef enum {
+	KEYWORD_NONE = -1,
+	KEYWORD_function,
+} keywordId;
+
+typedef enum {
+	ACCESS_UNDEFINED,
+	ACCESS_PRIVATE,
+	ACCESS_PROTECTED,
+	ACCESS_PUBLIC,
+	COUNT_ACCESS
+} accessType;
+
+typedef enum {
+	IMPL_UNDEFINED,
+	IMPL_ABSTRACT,
+	COUNT_IMPL
+} implType;
+
+typedef enum {
+	K_INTERFACE,
+	K_CLASS,
+	K_TRAIT,
+	K_FUNCTION,
+	K_VARIABLE,
+	COUNT_KIND
 } cssKind;
 
-static kindOption CssKinds [] = {
+static kindOption CssKinds[COUNT_KIND] = {
+	{ TRUE, 'i', "interface",	"interfaces" },
 	{ TRUE, 'c', "class",		"classes" },
-	{ TRUE, 's', "struct",		"selectors" },
-	{ TRUE, 'v', "variable",	"identities" }
+	{ TRUE, 's', "struct",		"traits" },
+	{ TRUE, 'f', "function",	"functions" },
+	{ TRUE, 'v', "variable",	"variables" },
 };
 
-typedef enum {
-	/* any ASCII */
-	TOKEN_EOF = 257,
-	TOKEN_SELECTOR,
-	TOKEN_STRING
+typedef struct {
+	const char *name;
+	keywordId id;
+} keywordDesc;
+
+static const keywordDesc CssKeywordTable[] = {
+	/* keyword			keyword ID */
+	{ "@mixin",		KEYWORD_function		},
+};
+
+
+typedef enum eTokenType {
+	TOKEN_UNDEFINED,
+	TOKEN_EOF,
+	TOKEN_CHARACTER,
+	TOKEN_CLOSE_PAREN,
+	TOKEN_SEMICOLON,
+	TOKEN_COLON,
+	TOKEN_COMMA,
+	TOKEN_KEYWORD,
+	TOKEN_OPEN_PAREN,
+	TOKEN_OPERATOR,
+	TOKEN_IDENTIFIER,
+	TOKEN_STRING,
+	TOKEN_PERIOD,
+	TOKEN_OPEN_CURLY,
+	TOKEN_CLOSE_CURLY,
+	TOKEN_EQUAL_SIGN,
+	TOKEN_OPEN_SQUARE,
+	TOKEN_CLOSE_SQUARE,
+	TOKEN_VARIABLE,
+	TOKEN_SELECTOR_ID,
+	TOKEN_SELECTOR_CLASS,
+	TOKEN_MIXIN,
+	TOKEN_AMPERSAND
 } tokenType;
 
 typedef struct {
-	tokenType type;
-	vString *string;
+	tokenType		type;
+	keywordId		keyword;
+	vString *		string;
+	vString *		scope;
+	unsigned long 	lineNumber;
+	MIOPos			filePosition;
+	int 			parentKind; /* -1 if none */
 } tokenInfo;
 
+static langType Lang_css;
+
+/* current statement details */
+static struct {
+	accessType access;
+	implType impl;
+} CurrentStatement;
+
+/* Current namespace */
+static vString *CurrentNamespace;
+
+
+static void buildCssKeywordHash (const langType language)
+{
+	const size_t count = sizeof (CssKeywordTable) / sizeof (CssKeywordTable[0]);
+	size_t i;
+	for (i = 0; i < count ; i++)
+	{
+		const keywordDesc* const p = &CssKeywordTable[i];
+		addKeyword (p->name, language, (int) p->id);
+	}
+}
+
+static const char *accessToString (const accessType access)
+{
+	static const char *const names[COUNT_ACCESS] = {
+		"undefined",
+		"private",
+		"protected",
+		"public"
+	};
+
+	Assert (access < COUNT_ACCESS);
+
+	return names[access];
+}
+
+static const char *implToString (const implType impl)
+{
+	static const char *const names[COUNT_IMPL] = {
+		"undefined",
+		"abstract"
+	};
+
+	Assert (impl < COUNT_IMPL);
+
+	return names[impl];
+}
+
+static void initCssEntry (tagEntryInfo *const e, const tokenInfo *const token,
+						  const cssKind kind, const accessType access)
+{
+	static vString *fullScope = NULL;
+	int parentKind = -1;
+
+	if (fullScope == NULL)
+		fullScope = vStringNew ();
+	else
+		vStringClear (fullScope);
+
+	initTagEntry (e, vStringValue (token->string));
+
+	e->lineNumber	= token->lineNumber;
+	e->filePosition	= token->filePosition;
+	e->kindName		= CssKinds[kind].name;
+	e->kind			= (char) CssKinds[kind].letter;
+
+	if (access != ACCESS_UNDEFINED)
+		e->extensionFields.access = accessToString (access);
+	if (vStringLength (token->scope) > 0)
+	{
+		parentKind = token->parentKind;
+		if (vStringLength (fullScope) > 0)
+			vStringCatS (fullScope, SCOPE_SEPARATOR);
+		vStringCat (fullScope, token->scope);
+	}
+	if (vStringLength (fullScope) > 0 && kind != K_VARIABLE)
+	{
+		Assert (parentKind >= 0);
+
+		vStringTerminate (fullScope);
+		e->extensionFields.scope[0] = CssKinds[parentKind].name;
+		e->extensionFields.scope[1] = vStringValue (fullScope);
+	}
+}
+
+static void makeSimpleCssTag (const tokenInfo *const token, const cssKind kind,
+							  const accessType access)
+{
+	if (CssKinds[kind].enabled)
+	{
+		tagEntryInfo e;
+
+		initCssEntry (&e, token, kind, access);
+		makeTagEntry (&e);
+	}
+}
+
+static void makeFunctionTag (const tokenInfo *const token,
+							 const vString *const arglist,
+							 const accessType access, const implType impl)
+{
+	if (CssKinds[K_FUNCTION].enabled)
+	{
+		tagEntryInfo e;
+
+		initCssEntry (&e, token, K_FUNCTION, access);
+
+		if (impl != IMPL_UNDEFINED)
+			e.extensionFields.implementation = implToString (impl);
+		if (arglist)
+			e.extensionFields.arglist = vStringValue (arglist);
+
+		makeTagEntry (&e);
+	}
+}
+
+static tokenInfo *newToken (void)
+{
+	tokenInfo *const token = xMalloc (1, tokenInfo);
+
+	token->type			= TOKEN_UNDEFINED;
+	token->keyword		= KEYWORD_NONE;
+	token->string		= vStringNew ();
+	token->scope		= vStringNew ();
+	token->lineNumber   = getSourceLineNumber ();
+	token->filePosition = getInputFilePosition ();
+	token->parentKind	= -1;
+
+	return token;
+}
+
+static void deleteToken (tokenInfo *const token)
+{
+	vStringDelete (token->string);
+	vStringDelete (token->scope);
+	eFree (token);
+}
+
+static void copyToken (tokenInfo *const dest, const tokenInfo *const src,
+					   boolean scope)
+{
+	dest->lineNumber = src->lineNumber;
+	dest->filePosition = src->filePosition;
+	dest->type = src->type;
+	dest->keyword = src->keyword;
+	vStringCopy(dest->string, src->string);
+	dest->parentKind = src->parentKind;
+	if (scope)
+		vStringCopy(dest->scope, src->scope);
+}
+
+#if 0
+#include <stdio.h>
+
+static const char *tokenTypeName (const tokenType type)
+{
+	switch (type)
+	{
+		case TOKEN_UNDEFINED:		return "undefined";
+		case TOKEN_EOF:				return "EOF";
+		case TOKEN_CHARACTER:		return "character";
+		case TOKEN_CLOSE_PAREN:		return "')'";
+		case TOKEN_SEMICOLON:		return "';'";
+		case TOKEN_COLON:			return "':'";
+		case TOKEN_COMMA:			return "','";
+		case TOKEN_OPEN_PAREN:		return "'('";
+		case TOKEN_OPERATOR:		return "operator";
+		case TOKEN_IDENTIFIER:		return "identifier";
+		case TOKEN_KEYWORD:			return "keyword";
+		case TOKEN_STRING:			return "string";
+		case TOKEN_PERIOD:			return "'.'";
+		case TOKEN_OPEN_CURLY:		return "'{'";
+		case TOKEN_CLOSE_CURLY:		return "'}'";
+		case TOKEN_EQUAL_SIGN:		return "'='";
+		case TOKEN_OPEN_SQUARE:		return "'['";
+		case TOKEN_CLOSE_SQUARE:	return "']'";
+		case TOKEN_VARIABLE:		return "variable";
+	}
+	return NULL;
+}
+
+static void printToken (const tokenInfo *const token)
+{
+	fprintf (stderr, "%p:\n\ttype:\t%s\n\tline:\t%lu\n\tscope:\t%s\n", (void *) token,
+			 tokenTypeName (token->type),
+			 token->lineNumber,
+			 vStringValue (token->scope));
+	switch (token->type)
+	{
+		case TOKEN_IDENTIFIER:
+		case TOKEN_STRING:
+		case TOKEN_VARIABLE:
+			fprintf (stderr, "\tcontent:\t%s\n", vStringValue (token->string));
+			break;
+
+		case TOKEN_KEYWORD:
+		{
+			size_t n = sizeof CssKeywordTable / sizeof CssKeywordTable[0];
+			size_t i;
+
+			fprintf (stderr, "\tkeyword:\t");
+			for (i = 0; i < n; i++)
+			{
+				if (CssKeywordTable[i].id == token->keyword)
+				{
+					fprintf (stderr, "%s\n", CssKeywordTable[i].name);
+					break;
+				}
+			}
+			if (i >= n)
+				fprintf (stderr, "(unknown)\n");
+		}
+
+		default: break;
+	}
+}
+#endif
 
-static boolean isSelectorChar (const int c)
+static void addToScope (tokenInfo *const token, const vString *const extra)
 {
-	/* attribute selectors are handled separately */
-	return (isalnum (c) ||
-			c == '_' || // allowed char
-			c == '-' || // allowed char
-			c == '+' || // allow all sibling in a single tag
-			c == '>' || // allow all child in a single tag
-			c == '|' || // allow namespace separator
-			c == '(' || // allow pseudo-class arguments
-			c == ')' ||
-			c == '.' || // allow classes and selectors
-			c == ':' || // allow pseudo classes
-			c == '*' || // allow globs as P + *
-			c == '#');  // allow ids
+	if (vStringLength (token->scope) > 0)
+		vStringCatS (token->scope, SCOPE_SEPARATOR);
+	vStringCatS (token->scope, vStringValue (extra));
+	vStringTerminate(token->scope);
 }
 
-static void parseSelector (vString *const string, const int firstChar)
+static boolean isIdentChar (const int c)
+{
+	return (isalnum (c) || c == '_' || c == '-' || c == '@' || c >= 0x80);
+}
+
+static int skipToCharacter (const int c)
+{
+	int d;
+	do
+	{
+		d = fileGetc ();
+	} while (d != EOF  &&  d != c);
+	return d;
+}
+
+static void parseString (vString *const string, const int delimiter)
+{
+	while (TRUE)
+	{
+		int c = fileGetc ();
+
+		if (c == '\\' && (c = fileGetc ()) != EOF)
+			vStringPut (string, (char) c);
+		else if (c == EOF || c == delimiter)
+			break;
+		else
+			vStringPut (string, (char) c);
+	}
+	vStringTerminate (string);
+}
+
+static void parseIdentifier (vString *const string, const int firstChar)
 {
 	int c = firstChar;
 	do
 	{
 		vStringPut (string, (char) c);
 		c = fileGetc ();
-	} while (isSelectorChar (c));
+	} while (isIdentChar (c));
 	fileUngetc (c);
 	vStringTerminate (string);
 }
 
+static keywordId analyzeToken (vString *const name, langType language)
+{
+	vString *keyword = vStringNew ();
+	keywordId result;
+	vStringCopyToLower (keyword, name);
+	result = lookupKeyword (vStringValue (keyword), language);
+	vStringDelete (keyword);
+	return result;
+}
+
+static boolean isSpace (int c)
+{
+	return (c == '\t' || c == ' ' || c == '\v' ||
+			c == '\n' || c == '\r' || c == '\f');
+}
+
+static int skipWhitespaces (int c)
+{
+	while (isSpace (c))
+		c = fileGetc ();
+	return c;
+}
+
+static int skipSingleComment (void)
+{
+	int c;
+	do
+	{
+		c = fileGetc ();
+		if (c == '\r')
+		{
+			int next = fileGetc ();
+			if (next != '\n')
+				fileUngetc (next);
+			else
+				c = next;
+		}
+		else
+		{
+			int next = fileGetc ();
+			fileUngetc (next);
+		}
+	} while (c != EOF && c != '\n' && c != '\r');
+	return c;
+}
+
 static void readToken (tokenInfo *const token)
 {
 	int c;
 
+	token->type		= TOKEN_UNDEFINED;
+	token->keyword	= KEYWORD_NONE;
 	vStringClear (token->string);
 
 getNextChar:
 
 	c = fileGetc ();
-	while (isspace (c))
-		c = fileGetc ();
 
-	token->type = c;
+	c = skipWhitespaces (c);
+
+	token->lineNumber   = getSourceLineNumber ();
+	token->filePosition = getInputFilePosition ();
+
 	switch (c)
 	{
-		case EOF: token->type = TOKEN_EOF; break;
+		case EOF: token->type = TOKEN_EOF;					break;
+		case '(': token->type = TOKEN_OPEN_PAREN;			break;
+		case ')': token->type = TOKEN_CLOSE_PAREN;			break;
+		case ';': token->type = TOKEN_SEMICOLON;			break;
+		case ',': token->type = TOKEN_COMMA;				break;
+		case ':': token->type = TOKEN_COLON;				break;
+		case '{': token->type = TOKEN_OPEN_CURLY;			break;
+		case '}': token->type = TOKEN_CLOSE_CURLY;			break;
+		case '[': token->type = TOKEN_OPEN_SQUARE;			break;
+		case ']': token->type = TOKEN_CLOSE_SQUARE;			break;
+		case '&': token->type = TOKEN_AMPERSAND;			break;
 
-		case '\'':
-		case '"':
+		case '=':
 		{
-			const int delimiter = c;
-			do
+			int d = fileGetc ();
+			if (d == '=' || d == '>')
+				token->type = TOKEN_OPERATOR;
+			else
 			{
-				vStringPut (token->string, c);
-				c = fileGetc ();
-				if (c == '\\')
-					c = fileGetc ();
-			}
-			while (c != EOF && c != delimiter);
-			if (c != EOF)
-				vStringPut (token->string, c);
+				fileUngetc (d);
+				token->type = TOKEN_EQUAL_SIGN;
+			}
+			break;
+		}
+
+		case '\'':
+		case '"':
 			token->type = TOKEN_STRING;
+			parseString (token->string, c);
+			token->lineNumber = getSourceLineNumber ();
+			token->filePosition = getInputFilePosition ();
+			break;
+
+		case '+':
+		case '-':
+		case '*':
+		case '%':
+		{
+			int d = fileGetc ();
+			if (d != '=')
+				fileUngetc (d);
+			token->type = TOKEN_OPERATOR;
 			break;
 		}
 
-		case '/': /* maybe comment start */
+		case '/': /* division or comment start */
 		{
 			int d = fileGetc ();
-			if (d != '*')
+			if (d == '/') /* single-line comment */
 			{
-				fileUngetc (d);
-				vStringPut (token->string, c);
-				token->type = c;
+				skipSingleComment ();
+				goto getNextChar;
 			}
-			else
+			else if (d == '*')
 			{
-				d = fileGetc ();
 				do
 				{
-					c = d;
-					d = fileGetc ();
-				}
-				while (d != EOF && ! (c == '*' && d == '/'));
+					c = skipToCharacter ('*');
+					if (c != EOF)
+					{
+						c = fileGetc ();
+						if (c == '/')
+							break;
+						else
+							fileUngetc (c);
+					}
+				} while (c != EOF && c != '\0');
 				goto getNextChar;
 			}
+			else
+			{
+				if (d != '=')
+					fileUngetc (d);
+				token->type = TOKEN_OPERATOR;
+			}
 			break;
 		}
 
-		default:
-			if (! isSelectorChar (c))
+		case '$': /* variable start */
+		{
+			int d = fileGetc ();
+			if (! isIdentChar (d))
 			{
-				vStringPut (token->string, c);
-				token->type = c;
+				fileUngetc (d);
+				token->type = TOKEN_UNDEFINED;
 			}
 			else
 			{
-				parseSelector (token->string, c);
-				token->type = TOKEN_SELECTOR;
+				parseIdentifier (token->string, d);
+				token->type = TOKEN_VARIABLE;
 			}
 			break;
+		}
+
+		case '#': /* variable start */
+		{
+			int d = fileGetc ();
+			if (! isIdentChar (d))
+			{
+				fileUngetc (d);
+				token->type = TOKEN_UNDEFINED;
+			}
+			else
+			{
+				parseIdentifier (token->string, d);
+				token->type = TOKEN_SELECTOR_ID;
+			}
+			break;
+		}
+
+		case '.': /* variable start */
+		{
+			int d = fileGetc ();
+			if (! isIdentChar (d))
+			{
+				fileUngetc (d);
+				token->type = TOKEN_UNDEFINED;
+			}
+			else
+			{
+				parseIdentifier (token->string, d);
+				token->type = TOKEN_SELECTOR_CLASS;
+			}
+			break;
+		}
+
+		case '@': /* mixin start */
+		{
+			int d = fileGetc ();
+			if (! isIdentChar (d) || 	tolower (d)                         != 'm' ||
+										tolower ((d = fileGetc ()))         != 'i' ||
+										tolower ((d = fileGetc ()))         != 'x' ||
+										tolower ((d = fileGetc ()))         != 'i' ||
+										tolower ((d = fileGetc ()))         != 'n')
+			{
+				fileUngetc (d);
+//				fileUngetc (d);
+//				fileUngetc (d);
+//				fileUngetc (d);
+//				fileUngetc (d);
+				token->type = TOKEN_UNDEFINED;
+			}
+			else
+			{
+				parseIdentifier (token->string, d);
+				token->type = TOKEN_MIXIN;
+			}
+			break;
+		}
+/**/
+
+		default:
+			if (! isIdentChar (c))
+				token->type = TOKEN_UNDEFINED;
+			else
+			{
+				parseIdentifier (token->string, c);
+				token->keyword = analyzeToken (token->string, getSourceLanguage ());
+				if (token->keyword == KEYWORD_NONE)
+					token->type = TOKEN_IDENTIFIER;
+				else
+					token->type = TOKEN_KEYWORD;
+			}
+			break;
+	}
+
+	if (token->type == TOKEN_SEMICOLON ||
+		token->type == TOKEN_OPEN_CURLY ||
+		token->type == TOKEN_CLOSE_CURLY)
+	{
+		/* reset current statement details on statement end, and when entering
+		 * a deeper scope.
+		 * it is a bit ugly to do this in readToken(), but it makes everything
+		 * a lot simpler. */
+		CurrentStatement.access = ACCESS_UNDEFINED;
+		CurrentStatement.impl = IMPL_UNDEFINED;
 	}
 }
 
-/* sets selector kind in @p kind if found, otherwise don't touches @p kind */
-static cssKind classifySelector (const vString *const selector)
+static void enterScope (tokenInfo *const parentToken,
+						const vString *const extraScope,
+						const int parentKind);
+
+static boolean parseSelector (tokenInfo *const token, cssKind kind)
 {
-	size_t i;
+	tokenInfo *name;
+	boolean readNext = TRUE;
 
-	for (i = vStringLength (selector); i > 0; --i)
-	{
-		char c = vStringItem (selector, i - 1);
-		if (c == '.')
-			return K_CLASS;
-		else if (c == '#')
-			return K_ID;
+	name = newToken ();
+	copyToken (name, token, TRUE);
+
+	readToken (token);
+	if (token->type == TOKEN_OPEN_CURLY) {
+		makeSimpleCssTag (name, kind, ACCESS_UNDEFINED);
+		enterScope (token, name->string, kind);
 	}
-	return K_SELECTOR;
+	else
+		readNext = FALSE;
+
+	deleteToken (name);
+
+	return readNext;
 }
 
-static void findCssTags (void)
+static boolean parseFunction (tokenInfo *const token, const tokenInfo *name)
 {
-	boolean readNextToken = TRUE;
-	tokenInfo token;
-
-	token.string = vStringNew ();
+	boolean readNext = TRUE;
+	accessType access = CurrentStatement.access;
+	implType impl = CurrentStatement.impl;
+	tokenInfo *nameFree = NULL;
+
+	readToken (token);
+	/* skip a possible leading ampersand (return by reference) */
+	if (token->type == TOKEN_AMPERSAND)
+		readToken (token);
 
-	do
+	if (! name)
 	{
-		if (readNextToken)
-			readToken (&token);
+		if (token->type != TOKEN_IDENTIFIER)
+			return FALSE;
 
-		readNextToken = TRUE;
+		name = nameFree = newToken ();
+		copyToken (nameFree, token, TRUE);
+		readToken (token);
+	}
 
-		if (token.type == '@')
-		{ /* At-rules, from the "@" to the next block or semicolon */
-			boolean useContents;
-			readToken (&token);
-			useContents = (strcmp (vStringValue (token.string), "media") == 0 ||
-						   strcmp (vStringValue (token.string), "supports") == 0);
-			while (token.type != TOKEN_EOF &&
-				   token.type != ';' && token.type != '{')
-			{
-				readToken (&token);
-			}
-			/* HACK: we *eat* the opening '{' for medias and the like so that
-			 *       the content is parsed as if it was at the root */
-			readNextToken = useContents && token.type == '{';
-		}
-		else if (token.type == TOKEN_SELECTOR)
-		{ /* collect selectors and make a tag */
-			cssKind kind = K_SELECTOR;
-			MIOPos filePosition;
-			unsigned long lineNumber;
-			vString *selector = vStringNew ();
-			do
-			{
-				if (vStringLength (selector) > 0)
-					vStringPut (selector, ' ');
-				vStringCat (selector, token.string);
-
-				kind = classifySelector (token.string);
-				lineNumber = getSourceLineNumber ();
-				filePosition = getInputFilePosition ();
+	if (token->type == TOKEN_OPEN_PAREN)
+	{
+		vString *arglist = vStringNew ();
+		int depth = 1;
 
-				readToken (&token);
+		vStringPut (arglist, '(');
+		do
+		{
+			readToken (token);
 
-				/* handle attribute selectors */
-				if (token.type == '[')
+			switch (token->type)
+			{
+				case TOKEN_OPEN_PAREN:  depth++; break;
+				case TOKEN_CLOSE_PAREN: depth--; break;
+				default: break;
+			}
+			/* display part */
+			switch (token->type)
+			{
+				case TOKEN_AMPERSAND:		vStringPut (arglist, '&');		break;
+				case TOKEN_CLOSE_CURLY:		vStringPut (arglist, '}');		break;
+				case TOKEN_CLOSE_PAREN:		vStringPut (arglist, ')');		break;
+				case TOKEN_CLOSE_SQUARE:	vStringPut (arglist, ']');		break;
+				case TOKEN_COLON:			vStringPut (arglist, ':');		break;
+				case TOKEN_COMMA:			vStringCatS (arglist, ", ");	break;
+				case TOKEN_EQUAL_SIGN:		vStringCatS (arglist, " = ");	break;
+				case TOKEN_OPEN_CURLY:		vStringPut (arglist, '{');		break;
+				case TOKEN_OPEN_PAREN:		vStringPut (arglist, '(');		break;
+				case TOKEN_OPEN_SQUARE:		vStringPut (arglist, '[');		break;
+				case TOKEN_PERIOD:			vStringPut (arglist, '.');		break;
+				case TOKEN_SEMICOLON:		vStringPut (arglist, ';');		break;
+				case TOKEN_STRING:			vStringCatS (arglist, "'...'");	break;
+
+				case TOKEN_IDENTIFIER:
+				case TOKEN_KEYWORD:
+				case TOKEN_VARIABLE:
 				{
-					int depth = 1;
-					while (depth > 0 && token.type != TOKEN_EOF)
+					switch (vStringLast (arglist))
 					{
-						vStringCat (selector, token.string);
-						readToken (&token);
-						if (token.type == '[')
-							depth++;
-						else if (token.type == ']')
-							depth--;
+						case 0:
+						case ' ':
+						case '{':
+						case '(':
+						case '[':
+						case '.':
+							/* no need for a space between those and the identifier */
+							break;
+
+						default:
+							vStringPut (arglist, ' ');
+							break;
 					}
-					if (token.type != TOKEN_EOF)
-						vStringCat (selector, token.string);
-					readToken (&token);
+					if (token->type == TOKEN_VARIABLE)
+						vStringPut (arglist, '$');
+					vStringCat (arglist, token->string);
+					break;
 				}
+
+				default: break;
 			}
-			while (token.type == TOKEN_SELECTOR);
-			/* we already consumed the next token, don't read it twice */
-			readNextToken = FALSE;
+		}
+		while (token->type != TOKEN_EOF && depth > 0);
 
-			vStringTerminate (selector);
-			if (CssKinds[kind].enabled)
-			{
-				tagEntryInfo e;
-				initTagEntry (&e, vStringValue (selector));
+		vStringTerminate (arglist);
 
-				e.lineNumber	= lineNumber;
-				e.filePosition	= filePosition;
-				e.kindName		= CssKinds[kind].name;
-				e.kind			= (char) CssKinds[kind].letter;
+		makeFunctionTag (name, arglist, access, impl);
+		vStringDelete (arglist);
 
-				makeTagEntry (&e);
-			}
-			vStringDelete (selector);
+		readToken (token); /* normally it's an open brace or "use" keyword */
+	}
+
+	if (token->type == TOKEN_OPEN_CURLY)
+		enterScope (token, name->string, K_FUNCTION);
+	else
+		readNext = FALSE;
+
+	if (nameFree)
+		deleteToken (nameFree);
+
+	return readNext;
+}
+
+static boolean parseVariable (tokenInfo *const token)
+{
+	tokenInfo *name;
+	boolean readNext = TRUE;
+	accessType access = CurrentStatement.access;
+
+	name = newToken ();
+	copyToken (name, token, TRUE);
+
+	readToken (token);
+	if (token->type == TOKEN_COLON)
+	{
+		cssKind kind = K_VARIABLE;
+
+		readToken (token);
+		if (token->type == TOKEN_KEYWORD &&
+			token->keyword == KEYWORD_function &&
+			CssKinds[kind].enabled)
+		{
+			if (parseFunction (token, name))
+				readToken (token);
+			readNext = (boolean) (token->type == TOKEN_SEMICOLON);
 		}
-		else if (token.type == '{')
-		{ /* skip over { ... } */
-			int depth = 1;
-			while (depth > 0 && token.type != TOKEN_EOF)
-			{
-				readToken (&token);
-				if (token.type == '{')
-					depth++;
-				else if (token.type == '}')
-					depth--;
-			}
+		else
+		{
+			makeSimpleCssTag (name, kind, access);
+			readNext = FALSE;
 		}
 	}
-	while (token.type != TOKEN_EOF);
+	else
+		readNext = FALSE;
+
+	deleteToken (name);
 
-	vStringDelete (token.string);
+	return readNext;
+}
+
+static void enterScope (tokenInfo *const parentToken,
+						const vString *const extraScope,
+						const int parentKind)
+{
+	tokenInfo *token = newToken ();
+	int origParentKind = parentToken->parentKind;
+
+	copyToken (token, parentToken, TRUE);
+
+	if (extraScope)
+	{
+		addToScope (token, extraScope);
+		token->parentKind = parentKind;
+	}
+
+	readToken (token);
+	while (token->type != TOKEN_EOF &&
+		   token->type != TOKEN_CLOSE_CURLY)
+	{
+		boolean readNext = TRUE;
+
+		switch (token->type)
+		{
+			case TOKEN_OPEN_CURLY:
+				enterScope (token, NULL, -1);
+				break;
+
+			case TOKEN_SELECTOR_ID:
+				readNext = parseSelector (token, K_INTERFACE);
+				break;
+
+			case TOKEN_SELECTOR_CLASS:
+				readNext = parseSelector (token, K_CLASS);
+				break;
+
+			case TOKEN_KEYWORD:
+				switch (token->keyword)
+				{
+					case KEYWORD_function:	readNext = parseFunction (token, NULL);				break;
+					default: break;
+				}
+				break;
+
+			case TOKEN_MIXIN:
+				readNext = parseFunction (token, NULL);
+				break;
+
+			case TOKEN_VARIABLE:
+				readNext = parseVariable (token);
+				break;
+
+			default: break;
+		}
+
+		if (readNext)
+			readToken (token);
+	}
+
+	copyToken (parentToken, token, FALSE);
+	parentToken->parentKind = origParentKind;
+	deleteToken (token);
+}
+
+static void findTags (void)
+{
+	tokenInfo *const token = newToken ();
+
+	CurrentStatement.access = ACCESS_UNDEFINED;
+	CurrentStatement.impl = IMPL_UNDEFINED;
+	CurrentNamespace = vStringNew ();
+
+	do
+	{
+		enterScope (token, NULL, -1);
+	}
+	while (token->type != TOKEN_EOF); /* keep going even with unmatched braces */
+
+	vStringDelete (CurrentNamespace);
+	deleteToken (token);
+}
+
+static void initializeCssParser (const langType language)
+{
+	Lang_css = language;
+	buildCssKeywordHash (language);
 }
 
-/* parser definition */
 extern parserDefinition* CssParser (void)
 {
-    static const char *const extensions [] = { "css", NULL };
-    parserDefinition* def = parserNew ("CSS");
-    def->kinds      = CssKinds;
-    def->kindCount  = KIND_COUNT (CssKinds);
-    def->extensions = extensions;
-    def->parser     = findCssTags;
-    return def;
+	static const char *const extensions [] = { "css", "css3", "css4", "css5", "phtml", NULL };
+	parserDefinition* def = parserNew ("CSS");
+	def->kinds      = CssKinds;
+	def->kindCount  = KIND_COUNT (CssKinds);
+	def->extensions = extensions;
+	def->parser     = findTags;
+	def->initialize = initializeCssParser;
+	return def;
 }
 
+/* vi:set tabstop=4 shiftwidth=4: */
