pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/R2pkg/files pkgtools/R2pkg: code cleanup



details:   https://anonhg.NetBSD.org/pkgsrc/rev/698a57bc974f
branches:  trunk
changeset: 402991:698a57bc974f
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sat Oct 19 13:55:09 2019 +0000

description:
pkgtools/R2pkg: code cleanup

diffstat:

 pkgtools/R2pkg/files/R2pkg.R      |  48 +++++++++++++--------------------------
 pkgtools/R2pkg/files/R2pkg_test.R |  16 ++++++------
 2 files changed, 24 insertions(+), 40 deletions(-)

diffs (103 lines):

diff -r 6c62f2296c9a -r 698a57bc974f pkgtools/R2pkg/files/R2pkg.R
--- a/pkgtools/R2pkg/files/R2pkg.R      Sat Oct 19 13:54:29 2019 +0000
+++ b/pkgtools/R2pkg/files/R2pkg.R      Sat Oct 19 13:55:09 2019 +0000
@@ -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 @@
 
 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 -r 6c62f2296c9a -r 698a57bc974f pkgtools/R2pkg/files/R2pkg_test.R
--- a/pkgtools/R2pkg/files/R2pkg_test.R Sat Oct 19 13:54:29 2019 +0000
+++ b/pkgtools/R2pkg/files/R2pkg_test.R Sat Oct 19 13:55:09 2019 +0000
@@ -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 @@
         '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', {



Home | Main Index | Thread Index | Old Index