private void parseSwitch(int indent,boolean firstContent,String header,Layout layout,List<Elem> elems){
  TokenStream tokens=new TokenStream(header);
  Elem selector=parseExpr(tokens);
  tokens.checkAtEnd();
  ImmutableList.Builder<Case> cases=ImmutableList.builder();
  List<Elem> defaultElems=null;
  boolean done;
  String line=getNextLine();
  Matcher matcher=COMMAND_LINE.matcher(line);
  String command;
  String rest;
  if (matcher.find()) {
    command=matcher.group(COMMAND_NAME_GROUP);
    rest=line.substring(matcher.end());
    done=false;
  }
 else {
    error("expected '@end', '@case' or '@default' command after 'switch'");
    done=true;
    command=null;
    rest=null;
  }
  while (!done) {
switch (command) {
case END_COMMAND:
      checkHeaderEmpty(command,rest);
    done=true;
  break;
case DEFAULT_COMMAND:
checkHeaderEmpty(command,rest);
if (defaultElems != null) {
error("duplicate '@default' in @switch");
}
defaultElems=parseUntil(indent,layout,END_COMMAND);
command=lastTerminator;
rest=lastTerminatorHeader;
done=lastTerminator == null;
break;
case CASE_COMMAND:
tokens=new TokenStream(rest);
Elem value=parseExpr(tokens);
tokens.checkAtEnd();
List<Elem> caseElems=parseUntil(indent,layout,END_COMMAND,CASE_COMMAND,DEFAULT_COMMAND);
if (value != null) {
cases.add(Case.create(value,caseElems));
}
command=lastTerminator;
rest=lastTerminatorHeader;
done=lastTerminator == null;
break;
default :
unexpectedCommandError(command);
done=true;
break;
}
}
if (selector != null) {
elems.add(Block.create(!firstContent,Switch.create(input.location(),selector,cases.build(),defaultElems)));
}
}

private void parseSwitch ( int indent , boolean firstContent , String header , Layout layout , List < Elem > elems ) { TokenStream tokens = new TokenStream ( header ) ; Elem selector = parseExpr ( tokens ) ; tokens . checkAtEnd ( ) ; ImmutableList . Builder < Case > cases = ImmutableList . builder ( ) ; List < Elem > defaultElems = null ; boolean done ; String line = getNextLine ( ) ; Matcher matcher = COMMAND_LINE . matcher ( line ) ; String command ; String rest ; if ( matcher . find ( ) ) { command = matcher . group ( COMMAND_NAME_GROUP ) ; rest = line . substring ( matcher . end ( ) ) ; done = false ; } else { error ( "expected '@end', '@case' or '@default' command after 'switch'" ) ; done = true ; command = null ; rest = null ; } while ( ! done ) { switch ( command ) { case END_COMMAND : checkHeaderEmpty ( command , rest ) ; done = true ; break ; case DEFAULT_COMMAND : checkHeaderEmpty ( command , rest ) ; if ( defaultElems != null ) { error ( "duplicate '@default' in @switch" ) ; } defaultElems = parseUntil ( indent , layout , END_COMMAND ) ; command = lastTerminator ; rest = lastTerminatorHeader ; done = lastTerminator == null ; break ; case CASE_COMMAND : tokens = new TokenStream ( rest ) ; Elem value = parseExpr ( tokens ) ; tokens . checkAtEnd ( ) ; List < Elem > caseElems = parseUntil ( indent , layout , END_COMMAND , CASE_COMMAND , DEFAULT_COMMAND ) ; if ( value != null ) { cases . add ( Case . create ( value , caseElems ) ) ; } command = lastTerminator ; rest = lastTerminatorHeader ; done = lastTerminator == null ; break ; default : unexpectedCommandError ( command ) ; done = true ; break ; } } if ( selector != null ) { elems . add ( Block . create ( ! firstContent , Switch . create ( input . location ( ) , selector , cases . build ( ) , defaultElems ) ) ) ; } }
parse a switch command .
