Zooce / zomb-file

The ZOMB File Format Specification
MIT License
1 stars 0 forks source link

[Feature Request] Add a way to apply/append a value or macro to a set (i.e. batching) #12

Closed Zooce closed 3 years ago

Zooce commented 3 years ago

I'm noticing that even with macros (as they are currently defined), there's still a lot of repetition in the color theme JSON file I'm prototyping with, for example:

// ... snip ...
tokenColors = [
    //===--- PUNCTUATION ---===//
    $colorize("punctuation.definition.arguments", $color.text)
    $colorize("punctuation.section.arguments", $color.text)
    $colorize("punctuation.separator", $color.text)
    $colorize("punctuation.definition.logical-expression", $color.teal)
    //===--- COMMENT ---===//
    $colorize("comment.line.number-sign.git-commit", $color.muted_text)
    $colorize("comment.line.message", #8EB1E5)
    $colorize("comment.line", #ff43a1)
    $colorize(comment, $color.muted_text)
    //===--- ENTITY ---===//
    $colorize("entity.name.function.decorator", $color.muted_text)
    $colorize("entity.name.function.preprocessor", $color.muted_text)
    $colorize("entity.name.tag", #b26ef7)
    $colorize("entity.name.function", $color.teal)
    $colorize("entity.name.type", $color.teal)
    $colorize("entity.other.attribute-name", $color.teal)
    $colorize("entity.name.section", $color.teal)
    $colorize("entity.scope.name", $color.muted_text)
    //===--- STRING ---===//
    $colorize("string.quoted.docstring", $color.muted_text)
    $colorize(string, #8EB1E5)
    $colorize("string.quoted.double.shell variable.other.normal.shell", #D0FF00)
    //===--- SOURCE ---===//
    $colorize("source.ini", #ff43a1)
    //===--- CONSTANT ---===//
    $colorize("constant.numeric", #D0FF00)
    $colorize("constant.language", #D0FF00)
    $colorize("constant.character", #D0FF00)
    $colorize("constant.other", #D0FF00)
    //===--- VARIABLE ---===//
    $colorize("variable.other.bracket", #D0FF00)
    $colorize("variable.language", #ff43a1)
    $colorize("variable.other.special", #D0FF00)
    $colorize("variable.other.positional", #D0FF00)
    $colorize("variable.other.normal.shell", #72aafd)
    $colorize("variable.parameter.function.language.special", #ff43a1)
// ... snip ...

In some ways the macros help, but they haven't fully solved the problem of eliminating unwieldy repetition.

Maybe a batching functionality would fix this? Here's my initial idea for this pattern:

$colorize(?, #ff0000) % [
    ["punctuation.definition.arguments"]
    ["punctuation.section.arguments"]
    ["punctuation.separator"]
]

Here I'm saying that I want to use the $colorize macro with three different arguments for the first parameter, so without batching this would look like this (notice the array):

[
    $colorize("punctuation.definition.arguments", #ff0000)
    $colorize("punctuation.section.arguments", #ff0000)
    $colorize("punctuation.separator", #ff0000)
]

Obviously we can accomplish the same thing with both patterns, but the batching is much nicer to maintain in this context. Also, the reason we have arrays of parameters is for multiple arguments:

$macro(?, hello, ?) % [
    [#00ff00, Zooce]
    [#f3f4f6, Jamie]
    [#112233, Bart]
]

A note about using % -- it's already a special delimiter and is also associated with parameters, so I'm thinking it conceptually makes sense. The ? would need to be a new special delimiter, so it's one more character that cannot be used in a bare string.