[Github-comments] [geany/geany] R outline improved for environments and R6 classes, = sign added as well (#2376)
Matthew Brush
notifications at xxxxx
Mon Oct 21 23:56:23 UTC 2019
> we are trying to not diverge from those
Too late:
```diff
--- r-geany.c 2019-10-21 16:54:35.032407824 -0700
+++ r-upstream.c 2019-10-21 16:53:25.426404697 -0700
@@ -19,10 +19,10 @@
#include "debug.h"
#include "entry.h"
+#include "parse.h"
#include "read.h"
+#include "selectors.h"
#include "vstring.h"
-#include "routines.h"
-
#define SKIPSPACE(ch) while (isspace((int)*ch)) \
ch++
@@ -31,22 +31,27 @@
K_FUNCTION,
K_LIBRARY,
K_SOURCE,
+ K_GLOBALVAR,
+ K_FUNCVAR,
KIND_COUNT
} rKind;
-static kindDefinition RKinds [KIND_COUNT] = {
+static kindDefinition RKinds[KIND_COUNT] = {
{true, 'f', "function", "functions"},
{true, 'l', "library", "libraries"},
{true, 's', "source", "sources"},
+ {true, 'g', "globalVar", "global variables"},
+ {true, 'v', "functionVar", "function variables"},
};
static void makeRTag (const vString * const name, rKind kind)
{
tagEntryInfo e;
- initTagEntry(&e, vStringValue(name), kind);
Assert (kind < KIND_COUNT);
+ initTagEntry (&e, vStringValue (name), kind);
+
makeTagEntry (&e);
}
@@ -66,93 +71,124 @@
{
/* iterate to the end of line or to a comment */
ikind = -1;
- switch (*cp) {
- case 'l':
- case 's':
- if (strncasecmp((const char*)cp, "library", (size_t)7) == 0) {
- /* load a library: library(tools) */
- cp += 7;
- SKIPSPACE(cp);
- if (*cp == '(')
- ikind = K_LIBRARY;
- else
- cp -= 7;
- } else if (strncasecmp((const char*)cp, "source", (size_t)6) == 0) {
- /* load a source file: source("myfile.r") */
- cp += 6;
- SKIPSPACE(cp);
- if (*cp == '(')
- ikind = K_SOURCE;
- else
- cp -= 6;
- }
- if (ikind != -1) {
+ switch (*cp)
+ {
+ case 'l':
+ case 's':
+ if (strncasecmp ((const char *) cp, "library", (size_t) 7) == 0)
+ {
+ /* load a library: library(tools) */
+ cp += 7;
+ SKIPSPACE (cp);
+ if (*cp == '(')
+ ikind = K_LIBRARY;
+ else
+ cp -= 7;
+ }
+ else if (strncasecmp ((const char *) cp, "source",
+ (size_t) 6) == 0)
+ {
+ /* load a source file: source("myfile.r") */
+ cp += 6;
+ SKIPSPACE (cp);
+ if (*cp == '(')
+ ikind = K_SOURCE;
+ else
+ cp -= 6;
+ }
+ if (ikind != -1)
+ {
+ cp++;
+
+ vStringClear (name);
+ while ((!isspace ((int) *cp)) && *cp != '\0' && *cp != ')')
+ {
+ vStringPut (name, (int) *cp);
cp++;
+ }
+
+ /* if the string really exists, make a tag of it */
+ if (vStringLength (name) > 0)
+ makeRTag (name, ikind);
+
+ /* prepare for the next iteration */
+ vStringClear (name);
+ }
+ else
+ {
+ vStringPut (name, (int) *cp);
+ cp++;
+ }
+ break;
+ case '<':
+ cp++;
+ if (*cp == '-')
+ {
+ /* assignment: ident <- someval */
+ cp++;
+ SKIPSPACE (cp);
- vStringClear(name);
- while ((!isspace((int)*cp)) && *cp != '\0' && *cp != ')') {
- vStringPut(name, (int)*cp);
- cp++;
+ if (*cp == '\0')
+ {
+ /* not in this line, read next */
+ /* sometimes functions are declared this way:
+ * ident <-
+ * function(...)
+ * {
+ * ...
+ * }
+ * I don't know if there is a reason to write the function keyword
+ * in a new line
+ */
+ if ((line = readLineFromInputFile ()) != NULL)
+ {
+ cp = (const unsigned char *) line;
+ SKIPSPACE (cp);
}
+ else
+ break;
+ }
+ if (strncasecmp ((const char *) cp, "function",
+ (size_t) 8) == 0)
+ {
+ /* it's a function: ident <- function(args) */
+ cp += 8;
/* if the string really exists, make a tag of it */
- if (vStringLength(name) > 0)
- makeRTag(name, ikind);
+ if (vStringLength (name) > 0)
+ makeRTag (name, K_FUNCTION);
/* prepare for the next iteration */
- vStringClear(name);
- } else {
- vStringPut(name, (int)*cp);
- cp++;
+ vStringClear (name);
+ break;
}
- break;
- case '<':
- cp++;
- if (*cp == '-') {
- /* assignment: ident <- someval */
- cp++;
- SKIPSPACE(cp);
-
- if (*cp == '\0') {
- /* not in this line, read next */
- /* sometimes functions are declared this way:
- ident <-
- function(...)
- {
- ...
- }
- I don't know if there is a reason to write the function keyword
- in a new line
- */
- if ((line = readLineFromInputFile()) != NULL) {
- cp = (const unsigned char*)line;
- SKIPSPACE(cp);
- }
+ else
+ {
+ /* it's a variable: ident <- value */
+ /* if the string really exists, make a tag of it */
+ if (vStringLength (name) > 0)
+ {
+ if (line[0] == ' ' || line[0] == '\t')
+ makeRTag (name, K_FUNCVAR);
+ else
+ makeRTag (name, K_GLOBALVAR);
}
- if (strncasecmp((const char*)cp, "function", (size_t)8) == 0) {
- /* it's a function: ident <- function(args) */
- cp += 8;
- /* if the string really exists, make a tag of it */
- if (vStringLength(name) > 0)
- makeRTag(name, K_FUNCTION);
-
- /* prepare for the next iteration */
- vStringClear(name);
- break;
- }
+ /* prepare for the next iteration */
+ vStringClear (name);
+ break;
}
- /* fall through */
- case ' ':
- case '\x009':
- /* skip whitespace */
- cp++;
- break;
- default:
- /* collect all characters that could be a part of an identifier */
- vStringPut(name, (int)*cp);
- cp++;
- break;
+ }
+ case ' ':
+ case '\x009':
+ /* skip whitespace */
+ cp++;
+ break;
+ default:
+ /* collect all characters that could be a part of an identifier */
+ vStringPut (name, (int) *cp);
+ cp++;
+ break;
}
}
}
@@ -163,14 +199,17 @@
extern parserDefinition *RParser (void)
{
- /* *.r: R files
+ /* *.r;*.R: R files
* *.s;*.q: S files
*/
- static const char *const extensions [] = { "r", "s", "q", NULL };
+ static const char *const extensions[] = { "r", "R", "s", "q", NULL };
parserDefinition *const def = parserNew ("R");
- def->kindTable = RKinds;
- def->kindCount = ARRAY_SIZE (RKinds);
+ static selectLanguage selectors[] = { selectByArrowOfR,
+ NULL };
def->extensions = extensions;
- def->parser = createRTags;
+ def->kindTable = RKinds;
+ def->kindCount = KIND_COUNT;
+ def->parser = createRTags;
+ def->selectLanguage = selectors;
return def;
}
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/2376#issuecomment-544755845
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/github-comments/attachments/20191021/ee041f16/attachment-0001.html>
More information about the Github-comments
mailing list