Add reStructuredText scope information for tags (for symbol list

grouping).
Add nestingLevelsPush(), nestingLevelsPop(),
nestingLevelsGetCurrent().



git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/unstable@3779 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2009-05-11 15:36:46 +00:00
parent 95f99f4034
commit 58b5c053bc
4 changed files with 89 additions and 13 deletions

View File

@ -4,6 +4,11 @@
tagmanager/nestlevel.h, tagmanager/python.c, tagmanager/Makefile.am, tagmanager/nestlevel.h, tagmanager/python.c, tagmanager/Makefile.am,
wscript: wscript:
Move NestingLevel code into a separate file. Move NestingLevel code into a separate file.
* tagmanager/nestlevel.c, tagmanager/nestlevel.h, tagmanager/rest.c:
Add reStructuredText scope information for tags (for symbol list
grouping).
Add nestingLevelsPush(), nestingLevelsPop(),
nestingLevelsGetCurrent().
2009-05-01 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com> 2009-05-01 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>

View File

@ -37,8 +37,9 @@ extern void freeNestingLevels(NestingLevels *nls)
eFree(nls); eFree(nls);
} }
/* currently only for indentation langs e.g. python */
extern void addNestingLevel(NestingLevels *nls, int indentation, extern void addNestingLevel(NestingLevels *nls, int indentation,
vString *name, boolean is_class) const vString *name, boolean is_class)
{ {
int i; int i;
NestingLevel *nl = NULL; NestingLevel *nl = NULL;
@ -66,4 +67,42 @@ extern void addNestingLevel(NestingLevels *nls, int indentation,
nl->is_class = is_class; nl->is_class = is_class;
} }
extern void nestingLevelsPush(NestingLevels *nls,
const vString *name, int type)
{
NestingLevel *nl = NULL;
if (nls->n >= nls->allocated)
{
nls->allocated++;
nls->levels = xRealloc(nls->levels,
nls->allocated, NestingLevel);
nls->levels[nls->n].name = vStringNew();
}
nl = &nls->levels[nls->n];
nls->n++;
vStringCopy(nl->name, name);
nl->type = type;
}
extern void nestingLevelsPop(NestingLevels *nls)
{
const NestingLevel *nl = nestingLevelsGetCurrent(nls);
Assert (nl != NULL);
vStringClear(nl->name);
nls->n--;
}
extern NestingLevel *nestingLevelsGetCurrent(NestingLevels *nls)
{
Assert (nls != NULL);
if (nls->n < 1)
return NULL;
return &nls->levels[nls->n - 1];
}
/* vi:set tabstop=4 shiftwidth=4: */ /* vi:set tabstop=4 shiftwidth=4: */

View File

@ -29,23 +29,28 @@ struct NestingLevel
{ {
int indentation; int indentation;
vString *name; vString *name;
boolean is_class; int type;
boolean is_class; /* should be replaced by type field */
}; };
struct NestingLevels struct NestingLevels
{ {
NestingLevel *levels; NestingLevel *levels;
int n; int n; /* number of levels in use */
int allocated; int allocated;
}; };
/* /*
* FUNCTION PROTOTYPES * FUNCTION PROTOTYPES
*/ */
NestingLevels *newNestingLevels(void); extern NestingLevels *newNestingLevels(void);
void freeNestingLevels(NestingLevels *nls); extern void freeNestingLevels(NestingLevels *nls);
void addNestingLevel(NestingLevels *nls, int indentation, extern void addNestingLevel(NestingLevels *nls, int indentation,
vString *name, boolean is_class); const vString *name, boolean is_class);
extern void nestingLevelsPush(NestingLevels *nls,
const vString *name, int type);
extern void nestingLevelsPop(NestingLevels *nls);
extern NestingLevel *nestingLevelsGetCurrent(NestingLevels *nls);
#endif /* _NESTLEVEL_H */ #endif /* _NESTLEVEL_H */

View File

@ -19,6 +19,7 @@
#include "parse.h" #include "parse.h"
#include "read.h" #include "read.h"
#include "vstring.h" #include "vstring.h"
#include "nestlevel.h"
/* /*
* DATA DEFINITIONS * DATA DEFINITIONS
@ -40,24 +41,48 @@ static kindOption RestKinds[] = {
static char kindchars[SECTION_COUNT]; static char kindchars[SECTION_COUNT];
static NestingLevels *nestingLevels = NULL;
/* /*
* FUNCTION DEFINITIONS * FUNCTION DEFINITIONS
*/ */
static void makeRestTag (const vString* const name, static NestingLevel *getNestingLevel(const int kind)
kindOption* const kinds, const int kind)
{ {
if (name != NULL && vStringLength (name) > 0) NestingLevel *nl;
while (1)
{
nl = nestingLevelsGetCurrent(nestingLevels);
if (nl && nl->type >= kind)
nestingLevelsPop(nestingLevels);
else
break;
}
return nl;
}
static void makeRestTag (const vString* const name, const int kind)
{
const NestingLevel *const nl = getNestingLevel(kind);
if (vStringLength (name) > 0)
{ {
tagEntryInfo e; tagEntryInfo e;
initTagEntry (&e, vStringValue (name)); initTagEntry (&e, vStringValue (name));
e.lineNumber--; /* we want the line before the '---' underline chars */ e.lineNumber--; /* we want the line before the '---' underline chars */
e.kindName = kinds [kind].name; e.kindName = RestKinds [kind].name;
e.kind = kinds [kind].letter; e.kind = RestKinds [kind].letter;
if (nl && nl->type < kind)
{
e.extensionFields.scope [0] = RestKinds [nl->type].name;
e.extensionFields.scope [1] = vStringValue (nl->name);
}
makeTagEntry (&e); makeTagEntry (&e);
} }
nestingLevelsPush(nestingLevels, name, kind);
} }
@ -105,6 +130,7 @@ static void findRestTags (void)
const unsigned char *line; const unsigned char *line;
memset(kindchars, 0, sizeof kindchars); memset(kindchars, 0, sizeof kindchars);
nestingLevels = newNestingLevels();
while ((line = fileReadLine ()) != NULL) while ((line = fileReadLine ()) != NULL)
{ {
@ -120,7 +146,7 @@ static void findRestTags (void)
if (kind >= 0) if (kind >= 0)
{ {
makeRestTag(name, RestKinds, kind); makeRestTag(name, kind);
continue; continue;
} }
} }
@ -130,6 +156,7 @@ static void findRestTags (void)
vStringTerminate(name); vStringTerminate(name);
} }
vStringDelete (name); vStringDelete (name);
freeNestingLevels(nestingLevels);
} }
extern parserDefinition* RestParser (void) extern parserDefinition* RestParser (void)