From 58b5c053bc8314bd58748c83469bd7e4354e9c1e Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 11 May 2009 15:36:46 +0000 Subject: [PATCH] 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 --- ChangeLog | 5 +++++ tagmanager/nestlevel.c | 41 ++++++++++++++++++++++++++++++++++++++++- tagmanager/nestlevel.h | 17 +++++++++++------ tagmanager/rest.c | 39 +++++++++++++++++++++++++++++++++------ 4 files changed, 89 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 57784d2ae..c46c80dbe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,11 @@ tagmanager/nestlevel.h, tagmanager/python.c, tagmanager/Makefile.am, wscript: 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 diff --git a/tagmanager/nestlevel.c b/tagmanager/nestlevel.c index c8ee4c565..ccb26daaa 100644 --- a/tagmanager/nestlevel.c +++ b/tagmanager/nestlevel.c @@ -37,8 +37,9 @@ extern void freeNestingLevels(NestingLevels *nls) eFree(nls); } +/* currently only for indentation langs e.g. python */ extern void addNestingLevel(NestingLevels *nls, int indentation, - vString *name, boolean is_class) + const vString *name, boolean is_class) { int i; NestingLevel *nl = NULL; @@ -66,4 +67,42 @@ extern void addNestingLevel(NestingLevels *nls, int indentation, 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: */ diff --git a/tagmanager/nestlevel.h b/tagmanager/nestlevel.h index 63d63e581..aacebc4b4 100644 --- a/tagmanager/nestlevel.h +++ b/tagmanager/nestlevel.h @@ -29,23 +29,28 @@ struct NestingLevel { int indentation; vString *name; - boolean is_class; + int type; + boolean is_class; /* should be replaced by type field */ }; struct NestingLevels { NestingLevel *levels; - int n; + int n; /* number of levels in use */ int allocated; }; /* * FUNCTION PROTOTYPES */ -NestingLevels *newNestingLevels(void); -void freeNestingLevels(NestingLevels *nls); -void addNestingLevel(NestingLevels *nls, int indentation, - vString *name, boolean is_class); +extern NestingLevels *newNestingLevels(void); +extern void freeNestingLevels(NestingLevels *nls); +extern void addNestingLevel(NestingLevels *nls, int indentation, + 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 */ diff --git a/tagmanager/rest.c b/tagmanager/rest.c index 7647cec6d..21455584f 100644 --- a/tagmanager/rest.c +++ b/tagmanager/rest.c @@ -19,6 +19,7 @@ #include "parse.h" #include "read.h" #include "vstring.h" +#include "nestlevel.h" /* * DATA DEFINITIONS @@ -40,24 +41,48 @@ static kindOption RestKinds[] = { static char kindchars[SECTION_COUNT]; +static NestingLevels *nestingLevels = NULL; + /* * FUNCTION DEFINITIONS */ -static void makeRestTag (const vString* const name, - kindOption* const kinds, const int kind) +static NestingLevel *getNestingLevel(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; initTagEntry (&e, vStringValue (name)); e.lineNumber--; /* we want the line before the '---' underline chars */ - e.kindName = kinds [kind].name; - e.kind = kinds [kind].letter; + e.kindName = RestKinds [kind].name; + 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); } + nestingLevelsPush(nestingLevels, name, kind); } @@ -105,6 +130,7 @@ static void findRestTags (void) const unsigned char *line; memset(kindchars, 0, sizeof kindchars); + nestingLevels = newNestingLevels(); while ((line = fileReadLine ()) != NULL) { @@ -120,7 +146,7 @@ static void findRestTags (void) if (kind >= 0) { - makeRestTag(name, RestKinds, kind); + makeRestTag(name, kind); continue; } } @@ -130,6 +156,7 @@ static void findRestTags (void) vStringTerminate(name); } vStringDelete (name); + freeNestingLevels(nestingLevels); } extern parserDefinition* RestParser (void)