Blame SOURCES/ctags-5.8-css.patch

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