Revision: 3798 http://geany.svn.sourceforge.net/geany/?rev=3798&view=rev Author: eht16 Date: 2009-05-17 17:16:39 +0000 (Sun, 17 May 2009)
Log Message: ----------- Backport change from CTags SVN to keep the parser more in sync: Add support for Cython constructs to the Python parser.
Modified Paths: -------------- trunk/ChangeLog trunk/tagmanager/python.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2009-05-17 17:16:24 UTC (rev 3797) +++ trunk/ChangeLog 2009-05-17 17:16:39 UTC (rev 3798) @@ -3,6 +3,8 @@ * tagmanager/python.c: Fix missing symbols for variables when an equal sign is used in a comment on the same line as the variable declaration. + Backport change from CTags SVN to keep the parser more in sync: + Add support for Cython constructs to the Python parser. * src/search.c: Remember the additional Find in Files search flags at startup. * src/dialogs.c:
Modified: trunk/tagmanager/python.c =================================================================== --- trunk/tagmanager/python.c 2009-05-17 17:16:24 UTC (rev 3797) +++ trunk/tagmanager/python.c 2009-05-17 17:16:39 UTC (rev 3798) @@ -188,7 +188,8 @@ while (*cp) { cp = skipEverything (cp); - if (!strncmp(cp, "def", 3) || !strncmp(cp, "class", 5)) + if (!strncmp(cp, "def", 3) || !strncmp(cp, "class", 5) || + !strncmp(cp, "cdef", 4) || !strncmp(cp, "cpdef", 5)) { return cp; } @@ -426,6 +427,37 @@ return start; }
+/* Skip type declaration that optionally follows a cdef/cpdef */ +static const char *skipTypeDecl (const char *cp, boolean *is_class) +{ + const char *lastStart = cp, *ptr = cp; + int loopCount = 0; + ptr = skipSpace(cp); + if (!strncmp("extern", ptr, 6)) { + ptr += 6; + ptr = skipSpace(ptr); + if (!strncmp("from", ptr, 4)) { return NULL; } + } + if (!strncmp("class", ptr, 5)) { + ptr += 5 ; + *is_class = TRUE; + ptr = skipSpace(ptr); + return ptr; + } + /* limit so that we don't pick off "int item=obj()" */ + while (*ptr && loopCount++ < 2) { + while (*ptr && *ptr != '=' && *ptr != '(' && !isspace(*ptr)) ptr++; + if (!*ptr || *ptr == '=') return NULL; + if (*ptr == '(') { + return lastStart; /* if we stopped on a '(' we are done */ + } + ptr = skipSpace(ptr); + lastStart = ptr; + while (*lastStart == '*') lastStart++; /* cdef int *identifier */ + } + return NULL; +} + static void findPythonTags (void) { vString *const continuation = vStringNew (); @@ -440,7 +472,7 @@
while ((line = (const char *) fileReadLine ()) != NULL) { - const char *cp = line; + const char *cp = line, *candidate; char const *longstring; char const *keyword, *variable; int indent; @@ -506,7 +538,28 @@ found = TRUE; is_class = TRUE; } + else if (!strncmp (keyword, "cdef ", 5)) + { + cp = skipSpace(keyword + 4); + candidate = skipTypeDecl (cp, &is_class); + if (candidate) + { + found = TRUE; + cp = candidate; + }
+ } + else if (!strncmp (keyword, "cpdef ", 6)) + { + cp = skipSpace(keyword + 5); + candidate = skipTypeDecl (cp, &is_class); + if (candidate) + { + found = TRUE; + cp = candidate; + } + } + if (found) { boolean is_parent_class; @@ -554,7 +607,7 @@
extern parserDefinition *PythonParser (void) { - static const char *const extensions[] = { "py", "pyx", "pxd", "scons", "python", NULL }; + static const char *const extensions[] = { "py", "pyx", "pxd", "pxi" ,"scons", NULL }; parserDefinition *def = parserNew ("Python"); def->kinds = PythonKinds; def->kindCount = KIND_COUNT (PythonKinds);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.