private SwitchElement[] ResolveElements(ParseInfo parseInfo, Scope scope, DeltinScriptParser.SwitchContext switchContext)
        {
            List <SwitchElement> elements = new List <SwitchElement>();
            bool inSection  = false;
            bool caseError  = false;
            bool gotDefault = false;

            // Resolve paths.
            foreach (var switchElement in switchContext.switch_element())
            {
                // Syntax error if there is a statement before a case.
                if (switchElement.documented_statement() != null && !inSection && !caseError)
                {
                    parseInfo.Script.Diagnostics.Error("Expected case or default.", DocRange.GetRange(switchElement));
                    caseError = true;
                }

                // Don't throw the syntax error multiple times in one switch.
                if (switchElement.DEFAULT() != null || switchElement.@case() != null)
                {
                    inSection = true;
                }

                // Default case.
                if (switchElement.DEFAULT() != null)
                {
                    if (gotDefault)
                    {
                        parseInfo.Script.Diagnostics.Error("Switch cannot have multiple defaults.", DocRange.GetRange(switchElement));
                    }
                    gotDefault = true;
                }

                // Get the statement
                if (switchElement.documented_statement() != null)
                {
                    elements.Add(new SwitchElement(parseInfo.GetStatement(scope, switchElement.documented_statement())));
                }
                // Get the case
                else if (switchElement.@case() != null)
                {
                    elements.Add(new SwitchElement(DocRange.GetRange(switchElement.@case().CASE()), parseInfo.GetExpression(scope, switchElement.@case().expr())));
                }
                // Get default
                else if (switchElement.DEFAULT() != null)
                {
                    elements.Add(new SwitchElement(DocRange.GetRange(switchElement.DEFAULT())));
                }
            }

            return(elements.ToArray());
        }
        public SwitchAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.SwitchContext switchContext)
        {
            // Get the expression.
            if (switchContext.expr() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(switchContext.RIGHT_PAREN()));
            }
            else
            {
                Expression = parseInfo.GetExpression(scope, switchContext.expr());
            }

            paths    = GetSections(ResolveElements(parseInfo.SetBreakHandler(this), scope, switchContext));
            pathInfo = new PathInfo[paths.Length];

            for (int i = 0; i < pathInfo.Length; i++)
            {
                pathInfo[i] = new PathInfo(paths[i].Block, paths[i].ErrorRange, paths[i].IsDefault);
            }
        }