Permalink
Browse files

Line directive additions from July -- incomplete

git-svn-id: https://svn.r-project.org/R/branches/djm-source@42736 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information...
1 parent 1d612c0 commit ee2ad5396c1baffad4c914426416b2570099d8af murdoch committed Sep 2, 2007
Showing with 68 additions and 8 deletions.
  1. +9 −0 src/library/tools/R/Rd.R
  2. +1 −0 src/library/tools/R/admin.R
  3. +46 −1 src/main/gram.y
  4. +6 −0 src/main/platform.c
  5. +6 −7 src/main/source.c
View
@@ -405,6 +405,11 @@ function(package, dir, lib.loc = NULL)
sub("^% --- Source file: (.+) ---$", "\\1", paths)
else
NULL
+ if (!is.null(names(db)))
+ db <- lapply(db, function(Rd) {
+ names(Rd) <- (1:length(Rd)) - 1
+ Rd
+ })
}
else {
if(missing(dir))
@@ -422,6 +427,10 @@ function(package, dir, lib.loc = NULL)
docsFiles <- list_files_with_type(docsDir, "docs")
db <- lapply(docsFiles, .read_Rd_lines_quietly)
names(db) <- docsFiles
+ db <- lapply(db, function(Rd) {
+ names(Rd) <- 1:length(Rd)
+ Rd
+ })
}
db
@@ -268,6 +268,7 @@ function(dir, outDir)
if(any(is.na(tmp)))
stop(gettextf("unable to re-encode '%s'", basename(f)),
domain = NA, call. = FALSE)
+ writeLines(paste("#line(1, \"", f, "\")", sep=""), con)
writeLines(tmp, con)
}
} else {
View
@@ -72,6 +72,7 @@ static int KeywordLookup(const char *);
static SEXP NewList(void);
static SEXP NextArg(SEXP, SEXP, SEXP);
static SEXP TagArg(SEXP, SEXP);
+static int processLineDirective(int);
/* These routines allocate constants */
@@ -96,6 +97,8 @@ static SEXP SrcFile = NULL;
static SEXP SrcRefs = NULL;
static PROTECT_INDEX srindex;
+#define min(a, b) (a<b?a:b)
+
#if defined(SUPPORT_MBCS)
# include <R_ext/Riconv.h>
# include <R_ext/rlocale.h>
@@ -1778,8 +1781,14 @@ static int SkipComment(void)
DECLARE_YYTEXT_BUFP(yyp);
int c;
YYTEXT_PUSH('#', yyp);
- while ((c = xxgetc()) != '\n' && c != R_EOF)
+ while (isalpha(c = xxgetc())) YYTEXT_PUSH(c, yyp);
+ if (!strncmp(yytext, "#line", yyp - yytext)) {
+ c = processLineDirective(c);
+ }
+ while (c != '\n' && c != R_EOF) {
YYTEXT_PUSH(c, yyp);
+ c = xxgetc();
+ }
YYTEXT_PUSH('\0', yyp);
if (c == R_EOF) EndOfFile = 2;
return c;
@@ -2198,6 +2207,42 @@ static int SymbolValue(int c)
return SYMBOL;
}
+static void setParseFilename(char* newname) {
+ if (SrcFile && isEnvironment(SrcFile)) {
+ SEXP filename;
+ PROTECT(filename = ScalarString(mkChar(newname)));
+ defineVar(install("filename"), filename, SrcFile);
+ UNPROTECT(1);
+ }
+}
+
+static int processLineDirective(int c)
+{
+ int tok, linenumber;
+ xxungetc(c);
+ c = SkipSpace();
+ if (c != '(') return(c);
+ c = SkipSpace();
+ if (!isdigit(c)) return(c);
+ tok = NumericValue(c);
+ linenumber = atoi(yytext);
+ c = SkipSpace();
+ if (c == ',') {
+ c = SkipSpace();
+ if (c == '"' || c == '\'') {
+ tok = StringValue(c);
+ c = SkipSpace();
+ } else return(c);
+ }
+ if (c == ')') {
+ if (tok == STR_CONST) setParseFilename(yytext);
+ while ((c = xxgetc()) != '\n' && c != R_EOF) /* skip */ ;
+ xxlineno = linenumber;
+ R_ParseContext[R_ParseContextLast] = '\0'; /* Context report shouldn't show the directive */
+ }
+ return(c);
+}
+
/* Split the input stream into tokens. */
/* This is the lowest of the parsing levels. */
View
@@ -390,6 +390,12 @@ SEXP attribute_hidden do_fileappend(SEXP call, SEXP op, SEXP args, SEXP rho)
for(i = 0; i < n; i++) {
status = 0;
if(!(fp2 = RC_fopen(STRING_ELT(f2, i), "rb", TRUE))) continue;
+ if(PRIMVAL(op) == 1) {
+ strcpy(buf, "#line 1 \"");
+ strcat(buf, CHAR(STRING_ELT(f2, i)));
+ strcat(buf, "\"\n");
+ fwrite(buf, 1, strlen(buf), fp2);
+ }
while((nchar = fread(buf, 1, APPENDBUFSIZE, fp2)) == APPENDBUFSIZE)
if(fwrite(buf, 1, APPENDBUFSIZE, fp1) != APPENDBUFSIZE)
goto append_error;
View
@@ -100,21 +100,20 @@ void attribute_hidden parseError(SEXP call, int linenum)
char filename[128];
if (linenum) {
getParseFilename(filename, sizeof(filename)-2);
- if (strlen(filename)) strcpy(filename + strlen(filename), ": ");
switch (len) {
case 0:
- error(_("%s%s on line %d"),
- filename, R_ParseErrorMsg, linenum);
+ error("%s:%d: %s",
+ filename, linenum, R_ParseErrorMsg);
break;
case 1:
- error(_("%s%s at\n%d: %s"),
- filename, R_ParseErrorMsg, linenum,
+ error("%s:%d: %s\n%d: %s",
+ filename, linenum, R_ParseErrorMsg, linenum,
CHAR(STRING_ELT(context, 0)));
break;
default:
- error(_("%s%s at\n%d: %s\n%d: %s"),
- filename, R_ParseErrorMsg, linenum-1,
+ error("%s:%d: %s\n%d: %s\n%d: %s",
+ filename, linenum, R_ParseErrorMsg, linenum-1,
CHAR(STRING_ELT(context, len-2)),
linenum, CHAR(STRING_ELT(context, len-1)));
break;

0 comments on commit ee2ad53

Please sign in to comment.