butterfansubs / aegsc

A compiler for aegs Aegisub karaoke templates
MIT License
1 stars 0 forks source link

Allow setting defaults for blocks #2

Closed bucket3432 closed 1 year ago

bucket3432 commented 2 years ago

Declaring repeating fields like the start time in each block is tedious and violates the DRY principle. Add support for a defaults block that sets the defaults for all following blocks.

The block should have the following syntax:

%[[ ... ]%]

That is, it is a regular block where the first character in the block is a [ and the last character is a ]. It is otherwise parsed the same as a normal block with the wrapping [] removed.

All fields should be settable. If a field is specified, it should replace the old default. Fields that are not specified should keep the existing default at that position in the file. Due to the design of blocks, the Effect and Text fields will always be set by default blocks, even if they are empty.

For example:

At the beginning of the file, the aegs defaults are used.

%[ template line %]
Comment: 0,0:00:00.00,0:00:00.00,Default,,0,0,0,template line,

The following sets the default start time and end time to `0:10:04.76`, and the style to `OP-R`.
It will also set the Effect and Text fields to default to empty. 

%[[ < 0:10:04.76 > 0:10:04.76 $ OP-R ]%]

The following will now have those values without them being explicitly supplied:

%[ template line %]
Comment: 0,0:10:04.76,0:10:04.76,OP-R,,0,0,0,template line,

It is equivalent to:

%[ template line < 0:10:04.76 > 0:10:04.76 $ OP-R %]
Comment: 0,0:10:04.76,0:10:04.76,OP-R,,0,0,0,template line,

Individual fields for a single field can be overridden in the block as usual:

%[ template line $ ED-E %]
Comment: 0,0:10:04.76,0:10:04.76,ED-E,,0,0,0,template line,

The following will set the new default for the style to `OP-E`.
The start and end times remain `0:10:04.76` as previously set:

%[[ $ OP-E ]%]

The following will now use the new defaults:

%[ template line %]
Comment: 0,0:10:04.76,0:10:04.76,OP-E,,0,0,0,template line,
bucket3432 commented 1 year ago

Resolved by cd498625e824d8fb29bf236a50ca1f8b8f63aac0 via the !set-defaults directive. Directives are more flexible and more clear than the double bracket design outlined here.