Skip to content

Commit

Permalink
r: Remove regex parser and focus updates on line parser
Browse files Browse the repository at this point in the history
Add support for global and function variables to match functionality of
the regex parser.
  • Loading branch information
vhda committed Sep 3, 2015
1 parent 7fb0203 commit 6522399
Showing 1 changed file with 25 additions and 43 deletions.
68 changes: 25 additions & 43 deletions parsers/r.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,53 +22,26 @@
#include "read.h"
#include "vstring.h"

#define R_REGEX

#define SKIPSPACE(ch) while (isspace((int)*ch)) \
ch++

#ifndef R_REGEX
typedef enum {
K_FUNCTION,
K_LIBRARY,
K_SOURCE,
K_GLOBALVAR,
K_FUNCVAR,
KIND_COUNT
} rKind;

static kindOption RKinds[KIND_COUNT] = {
{TRUE, 'f', "function", "functions"},
{TRUE, 's', "other", "libraries"},
{TRUE, 's', "other", "sources"},
{TRUE, 'l', "library", "libraries"},
{TRUE, 's', "source", "sources"},
{TRUE, 'g', "globalVar", "global variables"},
{TRUE, 'v', "functionVar", "function variables"},
};
#endif

#ifdef R_REGEX
static void installRRegex (const langType language)
{
/* This is a function, looks as follows:
* itent <- function(arg1, arg2) {
* do_something;
* }
*/
addTagRegex (language,
"^[ \t]*\"?([.a-zA-Z][.a-zA-Z0-9_]+)\"?[ \t]*<-[ \t]*function[ \t]*\\(", "\\1",
"f,function,functions", NULL);
/* Global variables */
addTagRegex (language,
"^\"?([.a-zA-Z][.a-zA-Z0-9_]*)\"?[ \t]*<-[ \t][^\(]+$", "\\1",
"g,globalVar,global variables", NULL);
/* Function local variable
* Assumes that code in functions is indented
*/
addTagRegex (language,
"[ \t]\"?([.A-Za-z][.A-Za-z0-9_]*)\"?[ \t]*<-[ \t][^\(]+$", "\\1",
"v,functionVar,function variables", NULL);
/* This loads someting, e.g. a library, simply: library(libname) */
addTagRegex (language,
"^[ \t]*(library|source|load|data)[\\(]([a-zA-Z0-9_]+)[\\)]", "\\2",
"s,other,library/source/load/data", NULL);
}
#else
static void makeRTag (const vString * const name, rKind kind)
{
tagEntryInfo e;
Expand Down Expand Up @@ -185,6 +158,23 @@ static void createRTags (void)
if (vStringLength (name) > 0)
makeRTag (name, K_FUNCTION);

/* prepare for the next iteration */
vStringClear (name);
break;
}
else
{
/* it's a variable: ident <- value */
vStringTerminate (name);
/* 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);
}

/* prepare for the next iteration */
vStringClear (name);
break;
Expand All @@ -207,7 +197,6 @@ static void createRTags (void)
vStringDelete (name);
vStringDelete (vLine);
}
#endif

extern parserDefinition *RParser (void)
{
Expand All @@ -216,17 +205,10 @@ extern parserDefinition *RParser (void)
*/
static const char *const extensions[] = { "r", "s", "q", NULL };
parserDefinition *const def = parserNew ("R");
#ifndef R_REGEX
def->kinds = RKinds;
def->kindCount = 4;
#endif
def->extensions = extensions;
#ifndef R_REGEX
def->kinds = RKinds;
def->kindCount = KIND_COUNT;
def->parser = createRTags;
#else
def->initialize = installRRegex;
def->method = METHOD_NOT_CRAFTED | METHOD_REGEX;
#endif
return def;
}

Expand Down

0 comments on commit 6522399

Please sign in to comment.