parseSwitchCaseHead method

SwitchCase parseSwitchCaseHead()

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

Implementation

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