2 * Copyright (c) 2003-2004, Ascher Stefan <stievie@utanet.at>
4 * This source code is released for free distribution under the terms of the
5 * GNU General Public License version 2 or (at your option) any later version.
7 * This module contains functions for generating tags for R language files.
8 * R is a programming language for statistical computing.
9 * R is GPL Software, get it from http://www.r-project.org/
15 #include "general.h" /* must always come first */
18 #include <ctype.h> /* to define isalpha(), isalnum(), isspace() */
27 #define SKIPSPACE(ch) while (isspace((int)*ch)) \
37 static kindOption RKinds
[KIND_COUNT
] = {
38 {true, 'f', "function", "functions"},
39 {true, 'l', "library", "libraries"},
40 {true, 's', "source", "sources"},
43 static void makeRTag (const vString
* const name
, rKind kind
)
46 initTagEntry(&e
, vStringValue(name
), &(RKinds
[kind
]));
48 Assert (kind
< KIND_COUNT
);
53 static void createRTags (void)
55 vString
*vLine
= vStringNew ();
56 vString
*name
= vStringNew ();
58 const unsigned char *line
;
60 while ((line
= readLineFromInputFile ()) != NULL
)
62 const unsigned char *cp
= (const unsigned char *) line
;
65 while ((*cp
!= '\0') && (*cp
!= '#'))
67 /* iterate to the end of line or to a comment */
72 if (strncasecmp((const char*)cp
, "library", (size_t)7) == 0) {
73 /* load a library: library(tools) */
80 } else if (strncasecmp((const char*)cp
, "source", (size_t)6) == 0) {
81 /* load a source file: source("myfile.r") */
93 while ((!isspace((int)*cp
)) && *cp
!= '\0' && *cp
!= ')') {
94 vStringPut(name
, (int)*cp
);
98 /* if the string really exists, make a tag of it */
99 if (vStringLength(name
) > 0)
100 makeRTag(name
, ikind
);
102 /* prepare for the next iteration */
105 vStringPut(name
, (int)*cp
);
112 /* assignment: ident <- someval */
117 /* not in this line, read next */
118 /* sometimes functions are declared this way:
124 I don't know if there is a reason to write the function keyword
127 if ((line
= readLineFromInputFile()) != NULL
) {
128 cp
= (const unsigned char*)line
;
133 if (strncasecmp((const char*)cp
, "function", (size_t)8) == 0) {
134 /* it's a function: ident <- function(args) */
136 /* if the string really exists, make a tag of it */
137 if (vStringLength(name
) > 0)
138 makeRTag(name
, K_FUNCTION
);
140 /* prepare for the next iteration */
148 /* skip whitespace */
152 /* collect all characters that could be a part of an identifier */
153 vStringPut(name
, (int)*cp
);
160 vStringDelete (name
);
161 vStringDelete (vLine
);
164 extern parserDefinition
*RParser (void)
169 static const char *const extensions
[] = { "r", "s", "q", NULL
};
170 parserDefinition
*const def
= parserNew ("R");
172 def
->kindCount
= ARRAY_SIZE (RKinds
);
173 def
->extensions
= extensions
;
174 def
->parser
= createRTags
;