Ejemplo n.º 1
0
        private IList <ProviderPluginConnectTask> ExtractConnectTaskDataFromCode(string code)
        {
            List <ProviderPluginConnectTask> listOfConnectTaskDataObjects = new List <ProviderPluginConnectTask>();

            SyneryParser.ProgramContext programContexts = ParserHelper.GetProgramAstFromCode(code, LexerErrorListener, ParserErrorListener);

            if (programContexts != null)
            {
                // load connect statements that are nested like that:
                // programUnit > providerPluginStatement > providerPluginConnectStatement
                foreach (var programUnitContext in programContexts.GetRuleContexts <SyneryParser.ProgramUnitContext>())
                {
                    foreach (var providerPluginStatementContext in programUnitContext.GetRuleContexts <SyneryParser.ProviderPluginStatementContext>())
                    {
                        foreach (var connectStatementContext in providerPluginStatementContext.GetRuleContexts <SyneryParser.ProviderPluginConnectStatementContext>())
                        {
                            ProviderPluginConnectTask connectTask = Controller.Interpret <SyneryParser.ProviderPluginConnectStatementContext, ProviderPluginConnectTask>(connectStatementContext);
                            listOfConnectTaskDataObjects.Add(connectTask);
                        }
                    }
                }
            }

            return(listOfConnectTaskDataObjects);
        }
        /// <summary>
        /// execute the given code
        /// </summary>
        /// <param name="code"></param>
        /// <param name="includeCode"></param>
        /// <returns></returns>
        public bool Run(string code, IDictionary <string, string> includeCode = null)
        {
            // prepare the memory that is used for the interpreation

            InitializeMemory(code, includeCode);

            // create a parser and start processing the tokenized code

            SyneryParser.ProgramContext programContext = ParserHelper.GetProgramAstFromCode(code, this, this);

            // start executing the code

            Controller.Interpret <SyneryParser.ProgramContext>(programContext);

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Runs some code validations and returns a result that contains some information about potential problems or errors.
        /// </summary>
        /// <param name="code"></param>
        /// <param name="includeFiles"></param>
        /// <returns></returns>
        public IValidationResult Run(string code, IDictionary <string, string> includeFiles = null)
        {
            _ValidationResult         = new ValidationResult();
            _ValidationResult.IsValid = true;

            // create a lexer/parser and listen for some errors
            SyneryParser.ProgramContext programContext = ParserHelper.GetProgramAstFromCode(code, this, this);

            if (_ValidationResult.Messages.Where(m => m.Category == ValidationResultMessageCategoryEnum.Error).Count() > 0)
            {
                // errors found
                _ValidationResult.IsValid = false;
            }

            return(_ValidationResult);
        }
        private IList <IFunctionData> ExtractFunctionsAndAppendThemToMemory(string code, string alias = null)
        {
            List <IFunctionData> listOfFunctionDeclarations = new List <IFunctionData>();

            SyneryParser.ProgramContext programContexts = ParserHelper.GetProgramAstFromCode(code, LexerErrorListener, ParserErrorListener);

            if (programContexts != null && programContexts.syneryFunctionBlock() != null)
            {
                foreach (SyneryParser.SyneryFunctionBlockContext context in programContexts.syneryFunctionBlock())
                {
                    IFunctionData functionData = Controller.Interpret <SyneryParser.SyneryFunctionBlockContext, IFunctionData, string>(context, alias);
                    listOfFunctionDeclarations.Add(functionData);
                }
            }

            return(listOfFunctionDeclarations);
        }
        /// <summary>
        /// Gets all RecordTypeDeclarationContexts from the given code and extracts the RecordType's full name and the name of the base record.
        /// </summary>
        /// <param name="code"></param>
        /// <param name="alias"></param>
        /// <returns></returns>
        private IList <RecordTypeDelcarationContainer> GetRecordTypeContextsFromCode(string code, string alias = null)
        {
            IList <RecordTypeDelcarationContainer> listOfRecordTypeDeclarations = new List <RecordTypeDelcarationContainer>();

            SyneryParser.ProgramContext programContext = ParserHelper.GetProgramAstFromCode(code, LexerErrorListener, ParserErrorListener);

            if (programContext != null && programContext.recordTypeDeclaration() != null)
            {
                // loop threw all RecordType declarations and collect the needed information

                foreach (var recordTypeDeclarationContext in programContext.recordTypeDeclaration())
                {
                    if (recordTypeDeclarationContext.RecordTypeIdentifier() != null)
                    {
                        // create a container for the collected information about the declaration
                        RecordTypeDelcarationContainer container = new RecordTypeDelcarationContainer();
                        // store the context
                        container.RecordTypeDeclarationContext = recordTypeDeclarationContext;

                        // get the RecordType's name and remove the leading hashtag
                        string name = RecordHelper.ParseRecordTypeName(recordTypeDeclarationContext.RecordTypeIdentifier().GetText());

                        container.Name          = name;
                        container.CodeFileAlias = alias;

                        if (recordTypeDeclarationContext.recordTypeDeclarationBaseType() != null &&
                            recordTypeDeclarationContext.recordTypeDeclarationBaseType().recordType() != null)
                        {
                            // the RecordType inherits from another RecordType -> store the base RecordType's name

                            string baseTypeName = RecordHelper.ParseRecordTypeName(
                                recordTypeDeclarationContext.recordTypeDeclarationBaseType().recordType().GetText());

                            if (alias != null && baseTypeName.IndexOf('.') == -1)
                            {
                                container.BaseRecordFullName = String.Format("{0}.{1}", alias, baseTypeName);
                            }
                            else
                            {
                                container.BaseRecordFullName = baseTypeName;
                            }
                        }

                        // verify that the FullName of the current record set is unique:
                        // try to find a record type that uses the same FullName

                        RecordTypeDelcarationContainer recordTypeWithTheSameName =
                            listOfRecordTypeDeclarations.FirstOrDefault(r => r.FullName == container.FullName);

                        if (recordTypeWithTheSameName != null)
                        {
                            throw new SyneryInterpretationException(recordTypeDeclarationContext, String.Format(
                                                                        "A record type with the name '{0}' has already been specified at line '{1}'.",
                                                                        container.FullName,
                                                                        recordTypeWithTheSameName.RecordTypeDeclarationContext.Start.Line));
                        }

                        // the record type FullName is unique
                        // append it to the list

                        listOfRecordTypeDeclarations.Add(container);
                    }
                    else
                    {
                        throw new SyneryInterpretationException(recordTypeDeclarationContext, "Record type may no be empty.");
                    }
                }
            }

            return(listOfRecordTypeDeclarations);
        }