Пример #1
0
        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.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.statement() != null)
                {
                    elements.Add(new SwitchElement(DeltinScript.GetStatement(parseInfo, scope, switchElement.statement())));
                }
                // Get the case
                else if (switchElement.@case() != null)
                {
                    elements.Add(new SwitchElement(DocRange.GetRange(switchElement.@case().CASE()), DeltinScript.GetExpression(parseInfo, scope, switchElement.@case().expr())));
                }
                // Get default
                else if (switchElement.DEFAULT() != null)
                {
                    elements.Add(new SwitchElement(DocRange.GetRange(switchElement.DEFAULT())));
                }
            }

            return(elements.ToArray());
        }
Пример #2
0
        public BlockAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.S_blockContext blockContext)
        {
            Scope blockScope = scope.Child();

            if (blockContext.statement() == null)
            {
                Statements = new IStatement[0];
            }
            else
            {
                Statements = new IStatement[blockContext.statement().Length];
                for (int i = 0; i < Statements.Length; i++)
                {
                    Statements[i] = DeltinScript.GetStatement(parseInfo, blockScope, blockContext.statement(i));
                }
            }

            parseInfo.Script.AddCompletionRange(new CompletionRange(blockScope, DocRange.GetRange(blockContext.BLOCK_START(), blockContext.BLOCK_END()), CompletionRangeKind.Catch));
        }