Blame SOURCES/ctags-5.8-css.patch

96f760
diff -up ctags-5.8/css.c.me ctags-5.8/css.c
96f760
--- ctags-5.8/css.c.me	2012-02-08 13:59:35.000000000 +0100
96f760
+++ ctags-5.8/css.c	2012-02-08 13:55:16.000000000 +0100
96f760
@@ -0,0 +1,226 @@
96f760
+/***************************************************************************
96f760
+ * css.c
96f760
+ * Character-based parser for Css definitions
96f760
+ * Author - Iago Rubio <iagorubio(at)users.sourceforge.net>
96f760
+ **************************************************************************/
96f760
+#include "general.h"
96f760
+
96f760
+#include <string.h> 
96f760
+#include <ctype.h> 
96f760
+
96f760
+#include "parse.h" 
96f760
+#include "read.h" 
96f760
+
96f760
+
96f760
+typedef enum eCssKinds {
96f760
+    K_NONE = -1, K_CLASS, K_SELECTOR, K_ID
96f760
+} cssKind;
96f760
+
96f760
+static kindOption CssKinds [] = {
96f760
+    { TRUE, 'c', "class", "classes" },
96f760
+    { TRUE, 's', "selector",  "selectors"  },
96f760
+    { TRUE, 'i', "id",  "identities"  }
96f760
+};
96f760
+
96f760
+typedef enum _CssParserState {  // state of parsing
96f760
+  P_STATE_NONE,         // default state
96f760
+  P_STATE_IN_COMMENT,     // into a comment, only multi line in CSS
96f760
+  P_STATE_IN_SINGLE_STRING, // into a single quoted string
96f760
+  P_STATE_IN_DOUBLE_STRING, // into a double quoted string
96f760
+  P_STATE_IN_DEFINITION,    // on the body of the style definition, nothing for us
96f760
+  P_STATE_IN_MEDIA,     // on a @media declaration, can be multi-line
96f760
+  P_STATE_IN_IMPORT,      // on a @import declaration, can be multi-line
96f760
+  P_STATE_IN_NAMESPACE,   // on a @namespace declaration  
96f760
+  P_STATE_IN_PAGE,      // on a @page declaration
96f760
+  P_STATE_IN_FONTFACE,    // on a @font-face declaration
96f760
+  P_STATE_AT_END        // end of parsing
96f760
+} CssParserState;
96f760
+
96f760
+static void makeCssSimpleTag( vString *name, cssKind kind, boolean delete )
96f760
+{
96f760
+  vStringTerminate (name);
96f760
+  makeSimpleTag (name, CssKinds, kind);
96f760
+  vStringClear (name);
96f760
+  if( delete )
96f760
+    vStringDelete (name);
96f760
+}
96f760
+
96f760
+static boolean isCssDeclarationAllowedChar( const unsigned char *cp )
96f760
+{
96f760
+  return  isalnum ((int) *cp) ||
96f760
+      isspace ((int) *cp) ||
96f760
+      *cp == '_' || // allowed char
96f760
+      *cp == '-' || // allowed char     
96f760
+      *cp == '+' ||   // allow all sibling in a single tag
96f760
+      *cp == '>' ||   // allow all child in a single tag 
96f760
+      *cp == '{' ||   // allow the start of the declaration
96f760
+      *cp == '.' ||   // allow classes and selectors
96f760
+      *cp == ',' ||   // allow multiple declarations
96f760
+      *cp == ':' ||   // allow pseudo classes
96f760
+      *cp == '*' ||   // allow globs as P + *
96f760
+      *cp == '#';   // allow ids 
96f760
+}
96f760
+
96f760
+static CssParserState parseCssDeclaration( const unsigned char **position, cssKind kind )
96f760
+{
96f760
+  vString *name = vStringNew ();
96f760
+  const unsigned char *cp = *position;
96f760
+
96f760
+  // pick to the end of line including children and sibling
96f760
+  // if declaration is multiline go for the next line 
96f760
+  while ( isCssDeclarationAllowedChar(cp) || 
96f760
+      *cp == '\0' )   // track the end of line into the loop
96f760
+  {
96f760
+    if( (int) *cp == '\0' )
96f760
+    { 
96f760
+      cp = fileReadLine ();
96f760
+      if( cp == NULL ){
96f760
+        makeCssSimpleTag(name, kind, TRUE);
96f760
+        *position = cp;
96f760
+        return P_STATE_AT_END;
96f760
+      }
96f760
+    }
96f760
+    else if( *cp == ',' )
96f760
+    {
96f760
+      makeCssSimpleTag(name, kind, TRUE);
96f760
+      *position = ++cp;
96f760
+      return P_STATE_NONE;
96f760
+    }
96f760
+    else if( *cp == '{' )
96f760
+    {
96f760
+      makeCssSimpleTag(name, kind, TRUE);
96f760
+      *position = ++cp;
96f760
+      return P_STATE_IN_DEFINITION;
96f760
+    }
96f760
+
96f760
+    vStringPut (name, (int) *cp);
96f760
+    ++cp;
96f760
+  }
96f760
+  
96f760
+  makeCssSimpleTag(name, kind, TRUE);
96f760
+  *position = cp;
96f760
+
96f760
+  return P_STATE_NONE;
96f760
+}
96f760
+
96f760
+static CssParserState parseCssLine( const unsigned char *line, CssParserState state )
96f760
+{
96f760
+  vString *aux;
96f760
+
96f760
+  while( *line != '\0' ) // fileReadLine returns NULL terminated strings
96f760
+  {
96f760
+    while (isspace ((int) *line))
96f760
+      ++line;
96f760
+    switch( state )
96f760
+    {
96f760
+      case P_STATE_NONE:
96f760
+        // pick first char if alphanumeric is a selector
96f760
+        if( isalnum ((int) *line) )
96f760
+          state = parseCssDeclaration( &line, K_SELECTOR );
96f760
+        else if( *line == '.' ) // a class
96f760
+          state = parseCssDeclaration( &line, K_CLASS );
96f760
+        else if( *line == '#' ) // an id
96f760
+          state = parseCssDeclaration( &line, K_ID );
96f760
+        else if( *line == '@' ) // at-rules, we'll ignore them
96f760
+        {
96f760
+          ++line;
96f760
+          aux = vStringNew();
96f760
+          while( !isspace((int) *line) )
96f760
+          {
96f760
+            vStringPut (aux, (int) *line);
96f760
+            ++line;         
96f760
+          }
96f760
+          vStringTerminate (aux);
96f760
+          if( strcmp( aux->buffer, "media" ) == 0 )
96f760
+            state = P_STATE_IN_MEDIA;
96f760
+          else if ( strcmp( aux->buffer, "import" ) == 0 )
96f760
+            state = P_STATE_IN_IMPORT;
96f760
+          else if ( strcmp( aux->buffer, "namespace" ) == 0 )
96f760
+            state = P_STATE_IN_NAMESPACE; 
96f760
+          else if ( strcmp( aux->buffer, "page" ) == 0 )
96f760
+            state = P_STATE_IN_PAGE;
96f760
+          else if ( strcmp( aux->buffer, "font-face" ) == 0 )
96f760
+            state = P_STATE_IN_FONTFACE;
96f760
+          vStringDelete (aux);
96f760
+        }
96f760
+        else if( *line == '*' && *(line-1) == '/' ) // multi-line comment
96f760
+          state = P_STATE_IN_COMMENT;
96f760
+      break;
96f760
+      case P_STATE_IN_COMMENT:
96f760
+        if( *line == '/' && *(line-1) == '*')
96f760
+          state = P_STATE_NONE;
96f760
+      break;
96f760
+      case  P_STATE_IN_SINGLE_STRING: 
96f760
+        if( *line == '\'' && *(line-1) != '\\' )
96f760
+          state = P_STATE_IN_DEFINITION; // PAGE, FONTFACE and DEFINITION are treated the same way
96f760
+      break;
96f760
+      case  P_STATE_IN_DOUBLE_STRING:
96f760
+        if( *line=='"' && *(line-1) != '\\' )
96f760
+          state = P_STATE_IN_DEFINITION; // PAGE, FONTFACE and DEFINITION are treated the same way
96f760
+      break;
96f760
+      case  P_STATE_IN_MEDIA:
96f760
+        // skip to start of media body or line end
96f760
+        while( *line != '{' )
96f760
+        {
96f760
+          if( *line == '\0' )
96f760
+            break;
96f760
+          ++line;
96f760
+        }
96f760
+        if( *line == '{' )
96f760
+            state = P_STATE_NONE;
96f760
+      break;
96f760
+      case  P_STATE_IN_IMPORT:
96f760
+      case  P_STATE_IN_NAMESPACE:
96f760
+        // skip to end of declaration or line end
96f760
+        while( *line != ';' )
96f760
+        {
96f760
+          if( *line == '\0' )
96f760
+            break;
96f760
+          ++line;
96f760
+        }
96f760
+        if( *line == ';' )
96f760
+          state = P_STATE_NONE;
96f760
+      break;
96f760
+      case P_STATE_IN_PAGE:
96f760
+      case P_STATE_IN_FONTFACE:
96f760
+      case P_STATE_IN_DEFINITION:
96f760
+        if( *line == '}' )
96f760
+          state = P_STATE_NONE;
96f760
+        else if( *line == '\'' )
96f760
+          state = P_STATE_IN_SINGLE_STRING;
96f760
+        else if( *line == '"' )
96f760
+          state = P_STATE_IN_DOUBLE_STRING;
96f760
+      break;
96f760
+      case P_STATE_AT_END:
96f760
+        return state;
96f760
+      break;
96f760
+    }   
96f760
+    line++;
96f760
+  }
96f760
+  return state;
96f760
+}
96f760
+
96f760
+static void findCssTags (void)
96f760
+{
96f760
+    const unsigned char *line;
96f760
+  CssParserState state = P_STATE_NONE;
96f760
+
96f760
+    while ( (line = fileReadLine ()) != NULL )
96f760
+    {
96f760
+    state = parseCssLine( line, state );
96f760
+    if( state==P_STATE_AT_END ) return;
96f760
+    }    
96f760
+}
96f760
+
96f760
+/* parser definition */
96f760
+extern parserDefinition* CssParser (void)
96f760
+{
96f760
+    static const char *const extensions [] = { "css", NULL };
96f760
+    parserDefinition* def = parserNew ("CSS");
96f760
+    def->kinds      = CssKinds;
96f760
+    def->kindCount  = KIND_COUNT (CssKinds);
96f760
+    def->extensions = extensions;
96f760
+    def->parser     = findCssTags;
96f760
+    return def;
96f760
+}
96f760
+
96f760
diff -up ctags-5.8/parsers.h.me ctags-5.8/parsers.h
96f760
--- ctags-5.8/parsers.h.me	2012-02-08 13:56:46.000000000 +0100
96f760
+++ ctags-5.8/parsers.h	2012-02-08 13:57:25.000000000 +0100
96f760
@@ -26,6 +26,7 @@
96f760
 	CppParser, \
96f760
 	CsharpParser, \
96f760
 	CobolParser, \
96f760
+	CssParser, \
96f760
 	DosBatchParser, \
96f760
 	EiffelParser, \
96f760
 	ErlangParser, \
96f760
diff -up ctags-5.8/source.mak.me ctags-5.8/source.mak
96f760
--- ctags-5.8/source.mak.me	2012-02-08 13:58:02.000000000 +0100
96f760
+++ ctags-5.8/source.mak	2012-02-08 13:58:42.000000000 +0100
96f760
@@ -17,6 +17,7 @@ SOURCES = \
96f760
 	beta.c \
96f760
 	c.c \
96f760
 	cobol.c \
96f760
+	css.c \
96f760
 	dosbatch.c \
96f760
 	eiffel.c \
96f760
 	entry.c \
96f760
@@ -79,6 +80,7 @@ OBJECTS = \
96f760
 	beta.$(OBJEXT) \
96f760
 	c.$(OBJEXT) \
96f760
 	cobol.$(OBJEXT) \
96f760
+	css.$(OBJEXT) \
96f760
 	dosbatch.$(OBJEXT) \
96f760
 	eiffel.$(OBJEXT) \
96f760
 	entry.$(OBJEXT) \