예제 #1
0
        private static void ApplyWhere(DSLTranslation translation, StringBuilder builder)
        {
            IList <OutputFragment> joinCollection = translation.GetCollection("where");

            if (joinCollection.Count > 0)
            {
                builder.Append(LINE_SEPARATOR);
                // builder.Append("  -------- WHERE ---------");
                int item_count = 0;

                foreach (OutputFragment fragment in joinCollection)
                {
                    builder.Append(LINE_SEPARATOR);
                    if (item_count == 0)
                    {
                        builder.Append(" WHERE ");
                    }
                    else
                    {
                        builder.Append("   AND ");
                    }
                    builder.Append(fragment.RenderedOutput);
                    item_count++;
                }
            }
        }
예제 #2
0
        private MatchingDefinition ProcessLine(string line, DSLTranslation translation, List <ScopeItem> scopeItems)
        {
            // match the line to a lineDefinition
            List <MatchingDefinition> matchingDefinitions = FindMatchingDefinitions(line);
            List <MatchingDefinition> errorFreeMatch      = new List <MatchingDefinition>();

            foreach (MatchingDefinition testMatch in matchingDefinitions)
            {
                String errorMessage = PreflightCheck(testMatch, scopeItems, true); // true = dryRun;
                if (errorMessage != null)
                {
                    testMatch.ErrorMessage = errorMessage;
                }
                else
                {
                    errorFreeMatch.Add(testMatch);
                }
            }

            if (errorFreeMatch.Count == 0)
            {
                throw new DSLTemplateException("No match for line");
            }
            else if (errorFreeMatch.Count > 1)
            {
                throw new DSLTemplateException("Multiple matches for line");
            }

            // Single match!
            PreflightCheck(errorFreeMatch[0], scopeItems, false); // false = not a dry run.
            return(errorFreeMatch[0]);
        }
예제 #3
0
        public static string Format(DSLTranslation translation)
        {
            StringBuilder builder = new StringBuilder();

            ApplyFrom(translation, builder);
            ApplyJoin(translation, builder);
            ApplyWhere(translation, builder);

            return(builder.ToString());
        }
예제 #4
0
        private static void ApplyFrom(DSLTranslation translation, StringBuilder builder)
        {
            IList <OutputFragment> fromCollection = translation.GetCollection("from");

            if (fromCollection.Count != 1)
            {
                throw new DSLTemplateException($"Currently, only one 'initial' item is allowed.");
            }

            builder.Append(fromCollection[0].RenderedOutput);
        }
예제 #5
0
        private static void ApplyJoin(DSLTranslation translation, StringBuilder builder)
        {
            IList <OutputFragment> joinCollection = translation.GetCollection("join");

            if (joinCollection.Count > 0)
            {
                builder.Append(LINE_SEPARATOR);
                // builder.Append("  -------- JOINs ---------");
                foreach (OutputFragment fragment in joinCollection)
                {
                    builder.Append(LINE_SEPARATOR);
                    builder.Append(fragment.RenderedOutput);
                }
            }
        }
예제 #6
0
        internal void RenderInto(DSLTranslation result)
        {
            foreach (OutputItem outputItem in lineDefinition.OutputItems)
            {
                String workingOutput = outputItem.OutputPattern;

                int placeholderIndex = 0;
                foreach (String placeholderValue in placeholderValues)
                {
                    String placeholderPattern = $"\\({placeholderIndex}\\)";
                    workingOutput = Regex.Replace(workingOutput, placeholderPattern, placeholderValue);
                    placeholderIndex++;
                }

                result.AddToCollection(outputItem.CollectionName, new OutputFragment(workingOutput));
            }
        }
예제 #7
0
        public DSLTranslation Process(string input)
        {
            DSLTranslation            result      = new DSLTranslation();
            List <ScopeItem>          scopeItems  = new List <ScopeItem>();
            List <MatchingDefinition> lineMatches = new List <MatchingDefinition>();

            foreach (string rawLine in input.Split('\n', StringSplitOptions.RemoveEmptyEntries))
            {
                string line = rawLine.Trim();
                if (line.Length > 0)
                {
                    MatchingDefinition match = ProcessLine(line, result, scopeItems);
                    lineMatches.Add(match);
                }
            }

            // render step
            foreach (MatchingDefinition lineMatch in lineMatches)
            {
                lineMatch.RenderInto(result);
            }

            return(result);
        }