Пример #1
0
        public void Run(SyneryParser.EachStatementContext context)
        {
            string parameterName        = context.Identifier().GetText();
            string tableName            = context.tableIdentifier().GetText();
            var    recordTypeDefinition = Controller.Interpret <SyneryParser.RecordTypeContext, KeyValuePair <SyneryType, IRecordType> >(context.recordType());

            if (Memory.Database.IsTable(tableName))
            {
                ITable table = Memory.Database.LoadTable(tableName);

                foreach (var row in table)
                {
                    // initialize a new scope for this block and push it on the scope stack

                    INestedScope blockScope = new BlockScope(Memory.CurrentScope);

                    // create the record from the row and declare/assign it as local variable

                    IRecord record = GetRecordFromTableRow(recordTypeDefinition.Value, row, table.Schema);

                    blockScope.DeclareVariable(parameterName, recordTypeDefinition.Key);
                    blockScope.AssignVariable(parameterName, record);

                    Controller.Interpret <SyneryParser.BlockContext, INestedScope, INestedScope>(context.block(), blockScope);

                    // stop execution if return was called
                    if (blockScope.IsTerminated == true)
                    {
                        break;
                    }
                }
            }
        }
        public static void InterpretHandleBlock(IInterpretationController controller, IHandleBlockData data, IValue eventRecord)
        {
            SyneryParser.BlockContext blockContext = data.Context as SyneryParser.BlockContext;

            if (blockContext != null)
            {
                // create a new block scope and set the parent scope of the OBSERVE-block as parent
                INestedScope blockScope = new BlockScope(data.ParentScope);

                // add the event record as local variable
                blockScope.DeclareVariable(data.ParameterName, eventRecord.Type);
                blockScope.AssignVariable(data.ParameterName, eventRecord.Value);

                // start interpreting the given HANDLE-block
                controller.Interpret <SyneryParser.BlockContext, INestedScope, INestedScope>(blockContext, blockScope);
            }
            else
            {
                throw new SyneryException("Can not interpret handle block because the given context is not a BlockContext");
            }
        }