Esempio n. 1
0
        private static void CompileRule(LanguageRule languageRule,
                                        StringBuilder regex,
                                        ICollection <string> captures,
                                        bool isFirstRule)
        {
            if (!isFirstRule)
            {
                regex.AppendLine();
                regex.AppendLine();
                regex.AppendLine("|");
                regex.AppendLine();
            }

            regex.AppendFormat("(?-xis)(?m)({0})(?x)", languageRule.Regex);

            int numberOfCaptures = GetNumberOfCaptures(languageRule.Regex);

            for (int i = 0; i <= numberOfCaptures; i++)
            {
                string scope = null;

                foreach (int captureIndex in languageRule.Captures.Keys)
                {
                    if (i == captureIndex)
                    {
                        scope = languageRule.Captures[captureIndex];
                        break;
                    }
                }

                captures.Add(scope);
            }
        }
            public void It_will_set_the_regex_and_captures()
            {
                const string regex = "theRegex";
                Dictionary<int, string> captures = new Dictionary<int, string> { {0, "theFirstCapture"} };

                LanguageRule languageRule = new LanguageRule(regex, captures);

                Assert.Equal("theRegex", languageRule.Regex);
                Assert.Equal("theFirstCapture", languageRule.Captures[0]);
            }
            public void It_will_set_the_regex_and_captures()
            {
                const string             regex    = "theRegex";
                Dictionary <int, string> captures = new Dictionary <int, string> {
                    { 0, "theFirstCapture" }
                };

                LanguageRule languageRule = new LanguageRule(regex, captures);

                Assert.Equal("theRegex", languageRule.Regex);
                Assert.Equal("theFirstCapture", languageRule.Captures[0]);
            }
Esempio n. 4
0
        // include configuration
        private static void RunTool(string sourceFile, string targetFile)
        {
            Log.Info("Conversion Tool is now running.");

            // Define the type of Rules by language type
            sourceRules = RulesFactory.GenerateRule(sourceFile);
            targetRules = RulesFactory.GenerateRule(targetFile);

            ConvertSourceFile();
            CreateTargetFile();

            // Convert target file to Desired file.
            Log.Success($"File is converted. Please check {Path.GetFileName(targetFile)}.");
        }
Esempio n. 5
0
        private static void CompileRule(LanguageRule languageRule,
            StringBuilder regex,
            ICollection<string> captures,
            bool isFirstRule)
        {
            if (!isFirstRule)
            {
                regex.AppendLine();
                regex.AppendLine();
                regex.AppendLine("|");
                regex.AppendLine();
            }

            regex.AppendFormat("(?-xis)(?m)({0})(?x)", languageRule.Regex);

            int numberOfCaptures = GetNumberOfCaptures(languageRule.Regex);

            for (int i = 0; i <= numberOfCaptures; i++)
            {
                string scope = null;

                foreach (var captureIndex in languageRule.Captures.Keys)
                {
                    if (i == captureIndex)
                    {
                        scope = languageRule.Captures[captureIndex];
                        break;
                    }
                }

                captures.Add(scope);
            }
        }