parseSwitchCaseHead method

SwitchCase parseSwitchCaseHead()

Parses a single 'case E:' or 'default:' without the following statements

Implementation

SwitchCase parseSwitchCaseHead() {
  int? start = token!.startOffset;
  int? line = token!.line;
  Token tok = requireNext(Token.NAME);
  if (tok.text == 'case') {
    Expression value = parseExpression();
    consume(Token.COLON);
    return SwitchCase(value, <Statement>[])
      ..start = start
      ..end = endOffset
      ..line = line;
  } else if (tok.text == 'default') {
    consume(Token.COLON);
    return SwitchCase(null, <Statement>[])
      ..start = start
      ..end = endOffset
      ..line = line;
  } else {
    throw fail();
  }
}