diff options
author | rillig <rillig@pkgsrc.org> | 2019-10-19 13:55:09 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2019-10-19 13:55:09 +0000 |
commit | d08a9050ca38c773707120a52860b79fa318d0b3 (patch) | |
tree | 24aac347c4897579fb64331399a7735f3ebe8cf5 /pkgtools/R2pkg | |
parent | ba24bc94e76e5568a0888d6ad6884be197991f7c (diff) | |
download | pkgsrc-d08a9050ca38c773707120a52860b79fa318d0b3.tar.gz |
pkgtools/R2pkg: code cleanup
Diffstat (limited to 'pkgtools/R2pkg')
-rw-r--r-- | pkgtools/R2pkg/files/R2pkg.R | 48 | ||||
-rw-r--r-- | pkgtools/R2pkg/files/R2pkg_test.R | 16 |
2 files changed, 24 insertions, 40 deletions
diff --git a/pkgtools/R2pkg/files/R2pkg.R b/pkgtools/R2pkg/files/R2pkg.R index 52b5af13f88..2536a8fc02d 100644 --- a/pkgtools/R2pkg/files/R2pkg.R +++ b/pkgtools/R2pkg/files/R2pkg.R @@ -1,4 +1,4 @@ -# $NetBSD: R2pkg.R,v 1.17 2019/10/19 13:37:00 rillig Exp $ +# $NetBSD: R2pkg.R,v 1.18 2019/10/19 13:55:09 rillig Exp $ # # Copyright (c) 2014,2015,2016,2017,2018,2019 # Brook Milligan. All rights reserved. @@ -264,48 +264,32 @@ fix.continued.lines <- function(df,line='line') read.Makefile.as.dataframe <- function(filename = 'Makefile.orig') { - # message('===> read.Makefile.as.dataframe():') - - re.skip_blank <- '[[:blank:]]*' - re.blank <- '[[:blank:]]+' - re.anything <- '.*' - - re.key <- '[^+=[:blank:]]+' - re.operator <- '[+=]+' - re.delimiter <- re.skip_blank - re.value <- re.anything - re.optional_TODO <- '(?:#[[:blank:]]*TODO[[:blank:]]*:[[:blank:]]*)*' - - re.match <- paste0('^', - re.skip_blank, - '(',re.optional_TODO,')', - re.key, - re.skip_blank, - '(',re.operator,')', - '(',re.delimiter,')', - '(',re.value,')', + re_varassign <- paste0( + '^', + ' *', + '(', '(?:#[\t ]*TODO[\t ]*:[\t ]*)*',')', # comment + '[^+=[:blank:]]+', # varname + '[\t ]*', + '(', '[+=]+',')', # operator + '(', '[\t ]*',')', # delimiter + '(', '.*',')', '$') df <- read.file.as.dataframe(filename) df$order <- 1:nrow(df) - df$category <- NA + df$category <- NA # for DEPENDS lines df <- categorize.key_value(df) df <- fix.continued.lines(df) df <- categorize.depends(df) df <- categorize.buildlink(df) - df$operator <- sub(re.match, '\\2', df$line) - df$delimiter <- sub(re.match, '\\3', df$line) - df$old_value <- sub(re.match, '\\4', df$line) - df$old_todo <- sub(re.match, '\\1', df$line) - - df$operator[!df$key_value] <- NA - df$delimiter[!df$key_value] <- NA - df$old_value[!df$key_value] <- NA - df$old_todo[!df$key_value] <- NA - + va <- df$key_value + df$old_todo[va] <- sub(re_varassign, '\\1', df$line[va]) + df$operator[va] <- sub(re_varassign, '\\2', df$line[va]) + df$delimiter[va] <- sub(re_varassign, '\\3', df$line[va]) + df$old_value[va] <- sub(re_varassign, '\\4', df$line[va]) df } diff --git a/pkgtools/R2pkg/files/R2pkg_test.R b/pkgtools/R2pkg/files/R2pkg_test.R index 53dc3b86bc0..b11cd437e89 100644 --- a/pkgtools/R2pkg/files/R2pkg_test.R +++ b/pkgtools/R2pkg/files/R2pkg_test.R @@ -1,4 +1,4 @@ -# $NetBSD: R2pkg_test.R,v 1.12 2019/10/19 13:37:00 rillig Exp $ +# $NetBSD: R2pkg_test.R,v 1.13 2019/10/19 13:55:09 rillig Exp $ # # Copyright (c) 2019 # Roland Illig. All rights reserved. @@ -213,13 +213,13 @@ test_that('read.Makefile.as.dataframe', { '4 .include "other.mk" 4 NA FALSE <NA> FALSE FALSE', '5 .if 0 5 NA FALSE <NA> FALSE FALSE', '6 .endif 6 NA FALSE <NA> FALSE FALSE', - ' operator delimiter old_value old_todo', - '1 <NA> <NA> <NA> <NA>', - '2 = value ', - '3 <NA> <NA> <NA> <NA>', - '4 <NA> <NA> <NA> <NA>', - '5 <NA> <NA> <NA> <NA>', - '6 <NA> <NA> <NA> <NA>') + ' old_todo operator delimiter old_value', + '1 <NA> <NA> <NA> <NA>', + '2 = value', + '3 <NA> <NA> <NA> <NA>', + '4 <NA> <NA> <NA> <NA>', + '5 <NA> <NA> <NA> <NA>', + '6 <NA> <NA> <NA> <NA>') }) test_that('read.file.as.list can read an empty file', { |