begin method

  1. @override
void begin(
  1. TagContext tc,
  2. String data
)
override

Called when the beginning of a tag is encountered.

Implementation

@override
void begin(TagContext tc, String data) {
  if (!(tc.parent?.tag is IfTag))
    tc.error("Unexpected else tag");

  tc.unindent();

  if (data.isEmpty) {
    tc.writeln("\n${tc.pre}} else {${tc.getLineNumberComment()}");
  } else {
    String cond;
    if (data.length < 4 || !data.startsWith("if")
    || !$whitespaces.contains(data.codeUnitAt(2))
    || (cond = data.substring(3).trim()).isEmpty)
      tc.error("Unexpected $data");

    String beg, end;
    if (cond.startsWith('(') && cond.endsWith(')')) {
      beg = end = "";
    } else {
      beg = "(";
      end = ")";
    }
    tc.writeln("\n${tc.pre}} else if $beg$cond$end {${tc.getLineNumberComment()}");
  }

  tc.indent();
}