Пример #1
0
        public static GrammarParseResult Combine(string rawText, GrammarParseResult x, GrammarParseResult y, BoolCombine isSuccessfulCombine = BoolCombine.Or, ArithCombine valueCombine = ArithCombine.Add, StrCombine outputCombine = StrCombine.Ignore)
        {
            GrammarParseResult combined = new GrammarParseResult(rawText);

            combined.IsSuccessful = CombineSuccessful(x.IsSuccessful, y.IsSuccessful, isSuccessfulCombine);
            combined.Value        = CombineValue(x.Value, y.Value, valueCombine);
            combined.Output       = CombineOutput(x.Output, y.Output, outputCombine);

            combined.Children.Add(x);
            combined.Children.Add(y);

            return(combined);
        }
Пример #2
0
        private static bool CombineSuccessful(bool isSuccessfulX, bool isSuccessfulY, BoolCombine combine)
        {
            switch (combine)
            {
            case BoolCombine.Or:
                return(isSuccessfulX || isSuccessfulY);

            case BoolCombine.And:
                return(isSuccessfulX && isSuccessfulY);

            default:
                throw new ArgumentException($"No combine logic defined for combine type: {Enum.GetName(typeof(BoolCombine), combine)}");
            }
        }