LeaVerou / brep

Write batch find & replace scripts that transform files with a simple human-readable syntax
12 stars 0 forks source link

Shorthand syntax? #1

Closed LeaVerou closed 2 months ago

LeaVerou commented 2 months ago

For a given bafr script (replacing bibliography ids) we have a long series of:

[[ replace ]]
from = "@Bakke:2011:SUI:1978942.1979313"
to = "@Bakke2011AData"

[[ replace ]]
from = "@chang2016using"
to = "@Chang2016UsingSpreadsheets"

# ...

What if we supported a shorthand syntax for these kinds of replacements which don’t need any config and just have a from and a to? E.g. something like:

[[ replacements ]]

"@Bakke:2011:SUI:1978942.1979313" = "@Bakke2011AData"
"@chang2016using" = "@Chang2016UsingSpreadsheets"
# ...

The problem is that with that, these cannot take part in the flow of other replacements due to how TOML is converted to JSON (they’d be a separate array).

Alternatively it could be a replacement flag:

shorthand = true
"@Bakke:2011:SUI:1978942.1979313" = "@Bakke2011AData"
"@chang2016using" = "@Chang2016UsingSpreadsheets"
# ...

When that flag is on, any unknown key would be considered a replacement.

Or an array:

pairs = [
    "@Bakke:2011:SUI:1978942.1979313", "@Bakke2011AData",
    "@chang2016using", "@Chang2016UsingSpreadsheets",
]

Worth it or not?

LeaVerou commented 2 months ago

The [from, to] shorthand syntax has been implemented, and it’s pretty compact, so I don’t think the additional complexity and limitations of this is worth it.