parseSwitch method

Statement parseSwitch()

Implementation

Statement parseSwitch() {
  int start = token?.startOffset??0;
  int line = token?.line??0;
  assert(token?.text == 'switch');
  consume(Token.NAME);
  consume(Token.LPAREN);
  Expression argument = parseExpression();
  consume(Token.RPAREN);
  consume(Token.LBRACE);
  List<SwitchCase> cases = <SwitchCase>[];
  cases.add(parseSwitchCaseHead());
  while (token?.type != Token.RBRACE) {
    if (peekName('case') || peekName('default')) {
      cases.add(parseSwitchCaseHead());
    } else {
      cases.last.body.add(parseStatement());
      cases.last.end = endOffset;
    }
  }
  consume(Token.RBRACE);
  return new SwitchStatement(argument, cases)
    ..start = start
    ..end = endOffset
    ..line = line;
}