conditionalBlock function
Implementation
Parser<Tag> conditionalBlock(
Parser elementParser,
String name,
LiquidConfig? config,
) {
final open = someTag(
name,
config: config,
content: ref0(conditionTagContent),
);
final elsif = elsifTag(config);
final otherwise = elseTag(config);
final end = someTag('end$name', config: config, hasContent: false);
final branchBody = elementParser.starLazy(elsif.or(otherwise).or(end));
final elseIfBlock = seq2(
elsif,
branchBody,
).map((parts) => (parts.$1 as Tag).copyWith(body: parts.$2.cast<ASTNode>()));
final elseBlock = seq2(
otherwise,
elementParser.starLazy(end),
).map((parts) => parts.$1.copyWith(body: parts.$2.cast<ASTNode>()));
return seq5(
open,
branchBody,
elseIfBlock.star(),
elseBlock.optional(),
end,
).map(
(parts) => parts.$1.copyWith(
body: [
...parts.$2.cast<ASTNode>(),
...parts.$3,
if (parts.$4 case final Tag otherwise) otherwise,
],
),
);
}