moodymudskipper / debugverse

Brainstorming ideas for debugging workflow and tools, not a package (yet ?)
1 stars 0 forks source link

detecting code patterns #27

Open moodymudskipper opened 2 years ago

moodymudskipper commented 2 years ago

Can we have a generalised regex for code ?

We could have regular variable names be fixed, and then have special placeholders like *ANY_CALL or *ANY_SYM, *ANY_STR, which might have a regular express as an arg (applied to caller for *ANY_CALL). *N_ARGS might be use to simulate several args (or lines in {). it might have a n arg to limit those (where n might be 0) *ANY can really be anything but has a function arg to limit the scope, all other functions are wrapped around it.

Maybe we don't need N_ARGS, n is just a parameter of ANY.

It's easy enough to define new helpers, the detecting function considers as matching functions those that obey a certain fixed pattern. e.g. :

ANY_FUNCTION_DEFINITION <- function(x) is.call(x) && x[1] %in% expression(`<-`, `=`) && is.call(x[[2]]) && identical(x[[c(2,1)]], quote(`function`)

We might provide a min and max depth to look for a match, the most useful besides might be max = 0 for top level only.

We'd use source markers to spot those but we might also output as data.