vim.c - ctags-5.8
Global variables defined
Data types defined
Functions defined
Source code
#include "general.h"
#include <string.h>
#include <setjmp.h>
#ifdef DEBUG
#include <stdio.h>
#endif
#include "parse.h"
#include "read.h"
#include "vstring.h"
#if 0
#endif
typedef enum {
K_AUGROUP,
K_COMMAND,
K_FUNCTION,
K_MAP,
K_VARIABLE
} vimKind;
static kindOption VimKinds [] = {
{ TRUE, 'a', "augroup", "autocommand groups" },
{ TRUE, 'c', "command", "user-defined commands" },
{ TRUE, 'f', "function", "function definitions" },
{ TRUE, 'm', "map", "maps" },
{ TRUE, 'v', "variable", "variable definitions" },
};
#if 0
#endif
#if 0
#endif
static const unsigned char* skipPrefix (const unsigned char* name, int *scope)
{
const unsigned char* result = name;
int counter;
size_t length;
length = strlen((const char*)name);
if (scope != NULL)
*scope = '\0';
if (length > 3 && name[1] == ':')
{
if (scope != NULL)
*scope = *name;
result = name + 2;
}
else if (length > 5 && strncasecmp ((const char*) name, "<SID>", (size_t) 5) == 0)
{
if (scope != NULL)
*scope = *name;
result = name + 5;
}
else
{
counter = 0;
do
{
switch ( name[counter] )
{
case '.':
*scope = 'd';
break;
case '#':
*scope = 'a';
break;
}
++counter;
} while (isalnum ((int) name[counter]) ||
name[counter] == '_' ||
name[counter] == '.' ||
name[counter] == '#'
);
}
return result;
}
static boolean isMap (const unsigned char* line)
{
if (
strncmp ((const char*) line, "map", (size_t) 3) == 0 ||
strncmp ((const char*) line, "nm", (size_t) 2) == 0 ||
strncmp ((const char*) line, "nma", (size_t) 3) == 0 ||
strncmp ((const char*) line, "nmap", (size_t) 4) == 0 ||
strncmp ((const char*) line, "vm", (size_t) 2) == 0 ||
strncmp ((const char*) line, "vma", (size_t) 3) == 0 ||
strncmp ((const char*) line, "vmap", (size_t) 4) == 0 ||
strncmp ((const char*) line, "om", (size_t) 2) == 0 ||
strncmp ((const char*) line, "oma", (size_t) 3) == 0 ||
strncmp ((const char*) line, "omap", (size_t) 4) == 0 ||
strncmp ((const char*) line, "im", (size_t) 2) == 0 ||
strncmp ((const char*) line, "ima", (size_t) 3) == 0 ||
strncmp ((const char*) line, "imap", (size_t) 4) == 0 ||
strncmp ((const char*) line, "lm", (size_t) 2) == 0 ||
strncmp ((const char*) line, "lma", (size_t) 3) == 0 ||
strncmp ((const char*) line, "lmap", (size_t) 4) == 0 ||
strncmp ((const char*) line, "cm", (size_t) 2) == 0 ||
strncmp ((const char*) line, "cma", (size_t) 3) == 0 ||
strncmp ((const char*) line, "cmap", (size_t) 4) == 0 ||
strncmp ((const char*) line, "no", (size_t) 2) == 0 ||
strncmp ((const char*) line, "nor", (size_t) 3) == 0 ||
strncmp ((const char*) line, "nore", (size_t) 4) == 0 ||
strncmp ((const char*) line, "norem", (size_t) 5) == 0 ||
strncmp ((const char*) line, "norema", (size_t) 6) == 0 ||
strncmp ((const char*) line, "noremap", (size_t) 7) == 0 ||
strncmp ((const char*) line, "nno", (size_t) 3) == 0 ||
strncmp ((const char*) line, "nnor", (size_t) 4) == 0 ||
strncmp ((const char*) line, "nnore", (size_t) 5) == 0 ||
strncmp ((const char*) line, "nnorem", (size_t) 6) == 0 ||
strncmp ((const char*) line, "nnorema", (size_t) 7) == 0 ||
strncmp ((const char*) line, "nnoremap", (size_t) 8) == 0 ||
strncmp ((const char*) line, "vno", (size_t) 3) == 0 ||
strncmp ((const char*) line, "vnor", (size_t) 4) == 0 ||
strncmp ((const char*) line, "vnore", (size_t) 5) == 0 ||
strncmp ((const char*) line, "vnorem", (size_t) 6) == 0 ||
strncmp ((const char*) line, "vnorema", (size_t) 7) == 0 ||
strncmp ((const char*) line, "vnoremap", (size_t) 8) == 0 ||
strncmp ((const char*) line, "ono", (size_t) 3) == 0 ||
strncmp ((const char*) line, "onor", (size_t) 4) == 0 ||
strncmp ((const char*) line, "onore", (size_t) 5) == 0 ||
strncmp ((const char*) line, "onorem", (size_t) 6) == 0 ||
strncmp ((const char*) line, "onorema", (size_t) 7) == 0 ||
strncmp ((const char*) line, "onoremap", (size_t) 8) == 0 ||
strncmp ((const char*) line, "ino", (size_t) 3) == 0 ||
strncmp ((const char*) line, "inor", (size_t) 4) == 0 ||
strncmp ((const char*) line, "inore", (size_t) 5) == 0 ||
strncmp ((const char*) line, "inorem", (size_t) 6) == 0 ||
strncmp ((const char*) line, "inorema", (size_t) 7) == 0 ||
strncmp ((const char*) line, "inoremap", (size_t) 8) == 0 ||
strncmp ((const char*) line, "lno", (size_t) 3) == 0 ||
strncmp ((const char*) line, "lnor", (size_t) 4) == 0 ||
strncmp ((const char*) line, "lnore", (size_t) 5) == 0 ||
strncmp ((const char*) line, "lnorem", (size_t) 6) == 0 ||
strncmp ((const char*) line, "lnorema", (size_t) 7) == 0 ||
strncmp ((const char*) line, "lnoremap", (size_t) 8) == 0 ||
strncmp ((const char*) line, "cno", (size_t) 3) == 0 ||
strncmp ((const char*) line, "cnor", (size_t) 4) == 0 ||
strncmp ((const char*) line, "cnore", (size_t) 5) == 0 ||
strncmp ((const char*) line, "cnorem", (size_t) 6) == 0 ||
strncmp ((const char*) line, "cnorema", (size_t) 7) == 0 ||
strncmp ((const char*) line, "cnoremap", (size_t) 8) == 0
)
return TRUE;
return FALSE;
}
static const unsigned char * readVimLine (void)
{
const unsigned char *line;
while ((line = fileReadLine ()) != NULL)
{
while (isspace ((int) *line))
++line;
if ((int) *line == '"')
continue;
break;
}
return line;
}
static void parseFunction (const unsigned char *line)
{
vString *name = vStringNew ();
int scope;
const unsigned char *cp = line + 1;
if ((int) *++cp == 'n' && (int) *++cp == 'c' &&
(int) *++cp == 't' && (int) *++cp == 'i' &&
(int) *++cp == 'o' && (int) *++cp == 'n')
++cp;
if ((int) *cp == '!')
++cp;
if (isspace ((int) *cp))
{
while (*cp && isspace ((int) *cp))
++cp;
if (*cp)
{
cp = skipPrefix (cp, &scope);
if (isupper ((int) *cp) ||
scope == 's' || scope == '<' || scope == 'd' || scope == 'a') {
do
{
vStringPut (name, (int) *cp);
++cp;
} while (isalnum ((int) *cp) || *cp == '_' || *cp == '.' || *cp == '#');
vStringTerminate (name);
makeSimpleTag (name, VimKinds, K_FUNCTION);
vStringClear (name);
}
}
}
TODO while ((line = readVimLine ()) != NULL)
{
if ( (!strncmp ((const char*) line, "endfo", (size_t) 5) == 0) &&
(strncmp ((const char*) line, "endf", (size_t) 4) == 0) )
break;
TODO }
vStringDelete (name);
}
static void parseAutogroup (const unsigned char *line)
{
vString *name = vStringNew ();
const unsigned char *cp = line + 2;
if ((int) *++cp == 'r' && (int) *++cp == 'o' &&
(int) *++cp == 'u' && (int) *++cp == 'p')
++cp;
if (isspace ((int) *cp))
{
while (*cp && isspace ((int) *cp))
++cp;
if (*cp)
{
if (strncasecmp ((const char*) cp, "end", (size_t) 3) != 0)
{
do
{
vStringPut (name, (int) *cp);
++cp;
} while (isalnum ((int) *cp) || *cp == '_');
vStringTerminate (name);
makeSimpleTag (name, VimKinds, K_AUGROUP);
vStringClear (name);
}
}
}
vStringDelete (name);
}
static boolean parseCommand (const unsigned char *line)
{
vString *name = vStringNew ();
boolean cmdProcessed = TRUE;
const unsigned char *cp = line;
if ( (int) *cp == '\\' )
{
if ((int) *cp == '\\')
++cp;
while (*cp && isspace ((int) *cp))
++cp;
}
else if ( (!strncmp ((const char*) line, "comp", (size_t) 4) == 0) &&
(!strncmp ((const char*) line, "comc", (size_t) 4) == 0) &&
(strncmp ((const char*) line, "com", (size_t) 3) == 0) )
{
cp += 2;
if ((int) *++cp == 'm' && (int) *++cp == 'a' &&
(int) *++cp == 'n' && (int) *++cp == 'd')
++cp;
if ((int) *cp == '!')
++cp;
while (*cp && isspace ((int) *cp))
++cp;
}
else
{
cmdProcessed = FALSE;
goto cleanUp;
}
do
{
if (isspace ((int) *cp))
{
++cp;
}
else if (*cp == '-')
{
while (*cp && !isspace ((int) *cp))
++cp;
}
} while ( *cp && !isalnum ((int) *cp) );
if ( ! *cp )
{
line = readVimLine();
parseCommand(line);
goto cleanUp;
}
do
{
vStringPut (name, (int) *cp);
++cp;
} while (isalnum ((int) *cp) || *cp == '_');
vStringTerminate (name);
makeSimpleTag (name, VimKinds, K_COMMAND);
vStringClear (name);
cleanUp:
vStringDelete (name);
return cmdProcessed;
}
static void parseLet (const unsigned char *line)
{
vString *name = vStringNew ();
const unsigned char *cp = line + 3;
const unsigned char *np = line;
if (isspace ((int) *cp))
{
while (*cp && isspace ((int) *cp))
++cp;
if (!*cp || *cp == '&' || *cp == '@' || *cp == '[' )
goto cleanUp;
np = cp;
++np;
if ((int) *cp == 'v' && (int) *np == ':' )
goto cleanUp;
while (*cp && *cp != '$' && !isalnum ((int) *cp))
++cp;
if (!*cp)
goto cleanUp;
do
{
if (!*cp)
break;
vStringPut (name, (int) *cp);
++cp;
} while (isalnum ((int) *cp) || *cp == '_' || *cp == '#' || *cp == ':' || *cp == '$');
vStringTerminate (name);
makeSimpleTag (name, VimKinds, K_VARIABLE);
vStringClear (name);
}
cleanUp:
vStringDelete (name);
}
static boolean parseMap (const unsigned char *line)
{
vString *name = vStringNew ();
const unsigned char *cp = line;
while (*cp && isalnum ((int) *cp))
++cp;
if ((int) *cp == '!')
++cp;
do
{
while (*cp && isspace ((int) *cp))
++cp;
if (strncmp ((const char*) cp, "<Leader>", (size_t) 8) == 0)
break;
if (
strncmp ((const char*) cp, "<buffer>", (size_t) 8) == 0 ||
strncmp ((const char*) cp, "<silent>", (size_t) 8) == 0 ||
strncmp ((const char*) cp, "<script>", (size_t) 8) == 0 ||
strncmp ((const char*) cp, "<unique>", (size_t) 8) == 0
)
{
cp += 8;
continue;
}
if (strncmp ((const char*) cp, "<expr>", (size_t) 6) == 0)
{
cp += 6;
continue;
}
if (strncmp ((const char*) cp, "<special>", (size_t) 9) == 0)
{
cp += 9;
continue;
}
break;
} while (*cp);
do
{
vStringPut (name, (int) *cp);
++cp;
} while (*cp && *cp != ' ');
vStringTerminate (name);
makeSimpleTag (name, VimKinds, K_MAP);
vStringClear (name);
vStringDelete (name);
return TRUE;
}
static boolean parseVimLine (const unsigned char *line)
{
boolean readNextLine = TRUE;
if ( (!strncmp ((const char*) line, "comp", (size_t) 4) == 0) &&
(!strncmp ((const char*) line, "comc", (size_t) 4) == 0) &&
(strncmp ((const char*) line, "com", (size_t) 3) == 0) )
{
readNextLine = parseCommand(line);
TODO }
if (isMap(line))
{
parseMap(line);
}
if (strncmp ((const char*) line, "fu", (size_t) 2) == 0)
{
parseFunction(line);
}
if (strncmp ((const char*) line, "aug", (size_t) 3) == 0)
{
parseAutogroup(line);
}
if ( strncmp ((const char*) line, "let", (size_t) 3) == 0 )
{
parseLet(line);
}
return readNextLine;
}
static void parseVimFile (const unsigned char *line)
{
boolean readNextLine = TRUE;
line = readVimLine();
while (line != NULL)
{
readNextLine = parseVimLine(line);
if ( readNextLine )
line = readVimLine();
}
}
static void findVimTags (void)
{
const unsigned char *line;
TODO
line = '\0';
parseVimFile (line);
}
extern parserDefinition* VimParser (void)
{
static const char *const extensions [] = { "vim", NULL };
parserDefinition* def = parserNew ("Vim");
def->kinds = VimKinds;
def->kindCount = KIND_COUNT (VimKinds);
def->extensions = extensions;
def->parser = findVimTags;
return def;
}