Search in sources :

Example 1 with CaseClauseTree

use of com.google.javascript.jscomp.parsing.parser.trees.CaseClauseTree in project closure-compiler by google.

the class Parser method parseCaseClauses.

private ImmutableList<ParseTree> parseCaseClauses() {
    boolean foundDefaultClause = false;
    ImmutableList.Builder<ParseTree> result = ImmutableList.builder();
    while (true) {
        SourcePosition start = getTreeStartLocation();
        switch(peekType()) {
            case CASE:
                eat(TokenType.CASE);
                ParseTree expression = parseExpression();
                eat(TokenType.COLON);
                ImmutableList<ParseTree> statements = parseCaseStatementsOpt();
                result.add(new CaseClauseTree(getTreeLocation(start), expression, statements));
                break;
            case DEFAULT:
                if (foundDefaultClause) {
                    reportError("Switch statements may have at most one default clause");
                } else {
                    foundDefaultClause = true;
                }
                eat(TokenType.DEFAULT);
                eat(TokenType.COLON);
                result.add(new DefaultClauseTree(getTreeLocation(start), parseCaseStatementsOpt()));
                break;
            default:
                return result.build();
        }
    }
}
Also used : DefaultClauseTree(com.google.javascript.jscomp.parsing.parser.trees.DefaultClauseTree) ImmutableList(com.google.common.collect.ImmutableList) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) CaseClauseTree(com.google.javascript.jscomp.parsing.parser.trees.CaseClauseTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 CaseClauseTree (com.google.javascript.jscomp.parsing.parser.trees.CaseClauseTree)1 DefaultClauseTree (com.google.javascript.jscomp.parsing.parser.trees.DefaultClauseTree)1 ParseTree (com.google.javascript.jscomp.parsing.parser.trees.ParseTree)1 SourcePosition (com.google.javascript.jscomp.parsing.parser.util.SourcePosition)1