Example #1
0
        /// <summary>
        /// Configures the engine using the specified script.
        /// </summary>
        /// <param name="script">The script.</param>
        public void Configure(string script)
        {
            CheckDisposed();
            if (_configured)
            {
                throw new InvalidOperationException("Configuration has already been performed.");
            }
            _configured = true;

            // Parse the script (or use an empty result if no script)
            DirectiveParser directiveParser = new DirectiveParser(_preprocessor);

            if (script != null)
            {
                directiveParser.Parse(script);
            }

            // Process preprocessor directives
            _preprocessor.ProcessDirectives(this, directiveParser.DirectiveValues);

            // Initialize everything (order here is very important)
            AddRecipePackageAndSetTheme();
            AddThemePackagesAndPath();
            InstallPackages();
            LoadAssemblies();
            CatalogClasses();
            AddNamespaces();
            AddFileProviders();
            ApplyRecipe();
            SetMetadata();

            // Finally evaluate the script
            Evaluate(directiveParser.Code);
        }
 private void EnsureParsed()
 {
     if (_parseResult is null)
     {
         _parseResult = DirectiveParser.Parse(Node.Text);
     }
 }
Example #3
0
            public void ReturnsAndCommentsValidDirectives()
            {
                // Given
                IPreprocessor   preprocessor    = new TestPreprocessor();
                DirectiveParser directiveParser = new DirectiveParser(preprocessor);
                string          configScript    = @"#valid a b c
#invalid a b c
#validx y z
A=
=B
#valid   x y z  
C";

                // When
                directiveParser.Parse(configScript);

                // Then
                Assert.AreEqual(@"//#valid a b c
#invalid a b c
#validx y z
A=
=B
//#valid   x y z  
C", directiveParser.Code);
                CollectionAssert.AreEqual(new[]
                {
                    Tuple.Create((int?)1, "valid", "a b c"),
                    Tuple.Create((int?)6, "valid", "x y z")
                }, directiveParser.DirectiveValues.Select(x => Tuple.Create(x.Line, x.Name, x.Value)));
            }
            public void ReturnsAndCommentsValidDirectives()
            {
                // Given
                IPreprocessor   preprocessor    = new TestPreprocessor();
                DirectiveParser directiveParser = new DirectiveParser(preprocessor);
                const string    configScript    = @"#valid a b c
#invalid a b c
#validx y z
A=
=B
#valid   x y z  
C";

                // When
                directiveParser.Parse(configScript);

                // Then
                directiveParser.Code.ShouldBe(
                    @"//#valid a b c
#invalid a b c
#validx y z
A=
=B
//#valid   x y z  
C", StringCompareShould.IgnoreLineEndings);

                directiveParser.DirectiveValues
                .Select(x => Tuple.Create(x.Line, x.Name, x.Value))
                .ShouldBe(
                    new[]
                {
                    Tuple.Create((int?)1, "valid", "a b c"),
                    Tuple.Create((int?)6, "valid", "x y z")
                });
            }
Example #5
0
            public void DoesNotProcessDirectivesWithSpaceAfterHash()
            {
                // Given
                IPreprocessor   preprocessor    = new TestPreprocessor();
                DirectiveParser directiveParser = new DirectiveParser(preprocessor);
                string          configScript    = @"# valid a b c
            A";

                // When
                directiveParser.Parse(configScript);

                // Then
                Assert.AreEqual(@"# valid a b c
            A", directiveParser.Code);
                CollectionAssert.IsEmpty(directiveParser.DirectiveValues);
            }
Example #6
0
            public void DoesNotProcessDirectivesWithSpaceAfterHash()
            {
                // Given
                IPreprocessor   preprocessor    = new TestPreprocessor();
                DirectiveParser directiveParser = new DirectiveParser(preprocessor);
                string          configScript    = @"# valid a b c
            A";

                // When
                directiveParser.Parse(configScript);

                // Then
                directiveParser.Code.ShouldBe(@"# valid a b c
            A", StringCompareShould.IgnoreLineEndings);
                directiveParser.DirectiveValues.ShouldBeEmpty();
            }
Example #7
0
            public void ReturnsSameCode()
            {
                // Given
                IPreprocessor   preprocessor    = new TestPreprocessor();
                DirectiveParser directiveParser = new DirectiveParser(preprocessor);
                string          configScript    = @"A
B
C";

                // When
                directiveParser.Parse(configScript);

                // Then
                CollectionAssert.IsEmpty(directiveParser.DirectiveValues);
                Assert.AreEqual(@"A
B
C", directiveParser.Code);
            }
Example #8
0
            public void ReturnsSameCode()
            {
                // Given
                IPreprocessor   preprocessor    = new TestPreprocessor();
                DirectiveParser directiveParser = new DirectiveParser(preprocessor);
                string          configScript    = @"A
B
C";

                // When
                directiveParser.Parse(configScript);

                // Then
                directiveParser.DirectiveValues.ShouldBeEmpty();
                directiveParser.Code.ShouldBe(@"A
B
C", StringCompareShould.IgnoreLineEndings);
            }
Example #9
0
        /// <summary>
        /// Filters out #region directives with omp parameter
        /// </summary>
        /// <param name="nodes">All #region nodes in a document syntax tree</param>
        /// <returns>#region nodes with omp parameter</returns>
        public List <DirectiveSyntaxNode> FilterOmpNodes(List <DirectiveSyntaxNode> nodes)
        {
            List <DirectiveSyntaxNode> result = new List <DirectiveSyntaxNode>();

            foreach (DirectiveSyntaxNode node in nodes)
            {
                // defining of directive type
                DirectiveType type = DirectiveParser.GetDirectiveType(node.RegionDirective.ToFullString());
                if (type == DirectiveType.UNKNOWN)
                {
                    continue;
                }

                DirectiveParser parser = _factory.GetParser(type);
                // parsing of OpenMP-style parameters
                node.DirectiveInfo = parser.Parse(node.RegionDirective.ToFullString());
                result.Add(node);
            }

            return(result);
        }