예제 #1
0
        public StringParseResult <TResult> Parse(CoreParserParameter parameter)
        {
            var(successfullyParsed, remaining, result) = _inner.Parse(parameter);

            if (remaining.EndsWith(ItemConstants.HiddenStatSuffix, StringComparison.OrdinalIgnoreCase))
            {
                remaining = remaining.Remove(remaining.Length - ItemConstants.HiddenStatSuffix.Length);
            }

            remaining = remaining.Trim();
            return(successfullyParsed && remaining.Length == 0, remaining, result);
        }
예제 #2
0
        public string Calculate(string equation)
        {
            _logger.Log(
                TraceLevel.Info,
                $"Start processing equation {equation}");

            var sides = ValidateEquation(equation);

            var leftSide = _stringParser
                           .Parse(sides[0])
                           .Select(_termParser.Parse)
                           .ToArray();

            var rightSide = _stringParser
                            .Parse(sides[1])
                            .Select(_termParser.Parse)
                            .ToArray();

            var terms = new List <Term>();

            // Add left side terms to resulting list
            foreach (var left in leftSide)
            {
                AddToResult(terms, left);
            }

            // Add right side terms to resulting list
            foreach (var right in rightSide)
            {
                AddToResult(terms, right * -1);
            }

            var result = ConvertToCanonical(terms);

            _logger.Log(
                TraceLevel.Info,
                $"Equation has been successfully converted");

            return(result);
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StringPackageInfo"/> class.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="sourceParser">The source parser.</param>
        public StringPackageInfo(string source, IStringParser sourceParser)
        {
            string key;
            string body;

            string[] parameters;

            sourceParser.Parse(source, out key, out body, out parameters);

            Key        = key;
            Body       = body;
            Parameters = parameters;
        }
        /// <summary>
        /// Initializes the string package's data.
        /// </summary>
        /// <param name="source">The source string.</param>
        /// <param name="sourceParser">The source parser.</param>
        protected void InitializeData(string source, IStringParser sourceParser)
        {
            string key;
            string body;

            string[] parameters;

            sourceParser.Parse(source, out key, out body, out parameters);

            Key        = key;
            Body       = body;
            Parameters = parameters;
        }
예제 #5
0
        public void OneTimeSetUp()
        {
            _logger = Substitute.For <ILogger>();

            _stringParser = Substitute.For <IStringParser>();
            _stringParser.Parse(Arg.Any <string>())
            .Returns(new[] { FakeValidString, FakeValidString });

            _termParser = Substitute.For <ITermParser>();
            _termParser.Parse(Arg.Any <string>())
            .Returns(FakeValidTerm);

            _termConverter = Substitute.For <ITermConverter>();
            _termConverter.ToCanonical(Arg.Any <Term>())
            .Returns(FakeValidString);
        }
        public DataProvider(SelectList list, IDbConnection con, IBackupData backupData,
                            IDataFromDatabaseReader databaseReader, int chunkSize, int recordsOnScreen, IStringParser parser)
        {
            string query = parser.Parse(list);

            _chunkSize       = chunkSize;
            _recordsOnScreen = recordsOnScreen;
            _backupData      = backupData;
            _backupData.ClearBackup();
            _databaseAccess = databaseReader;
            var connection = (DbConnection)con;

            if (connection != null)
            {
                _databaseAccess.OpenConnection(connection, query);
            }
        }
예제 #7
0
        public StringParseResult <IIntermediateModifier> Parse(CoreParserParameter parameter)
        {
            var(successfullyParsed, remaining, innerResult) = _innerParser.Parse(parameter);
            IIntermediateModifier result;

            if (successfullyParsed)
            {
                var groups  = innerResult.RegexGroups;
                var context = CreateContext(groups, "");
                result = _modifierResolver.Resolve(innerResult.Modifier, context);
            }
            else
            {
                result = innerResult?.Modifier;
            }

            return(successfullyParsed, remaining, result);
        }
예제 #8
0
        /// <summary>
        /// Resolves a resource. The resource is then parsed, before it's returned. Returns null if no match is found.
        /// </summary>
        public static string?GetResource(this IStringParser stringParser, IResourceService resourceService, ReadOnlySpan <char> key, params StringTagPair[] args)
        {
            if (stringParser is null)
            {
                throw new ArgumentNullException(nameof(stringParser));
            }
            if (resourceService is null)
            {
                throw new ArgumentNullException(nameof(resourceService));
            }

            string?resource = resourceService.GetString(key);

            if (resource is null)
            {
                return(null);
            }

            return(stringParser.Parse(resource, args));
        }
예제 #9
0
 public static StringParseResult <TResult> Parse <TResult>(this IStringParser <TResult> @this,
                                                           string modifierLine)
 => @this.Parse(modifierLine, default, default);
        public StringParseResult <TResult> Parse(string modifierLine)
        {
            var normalized = StringNormalizer.MergeWhiteSpace(modifierLine.Trim());

            return(_inner.Parse(normalized));
        }
예제 #11
0
        public void Import(string source, IStringParser <TModel> stringParser, string sourceName)
        {
            var list = stringParser.Parse(source);

            _handler.BulkInsert(list, sourceName);
        }
예제 #12
0
 public string this[string value] => _stringParser.Parse(value);
예제 #13
0
        public static string ParseAndFormat <TResult>(IStringParser <TResult> parser, FormatterEx.IValueFormatter <TResult> formatter, string text, Nparams param)
        {
            var value = parser.Parse(text, default(TResult), param);

            return(value != null ? formatter.Format(value, param) : string.Empty);
        }
예제 #14
0
 public static TResult Parse <TResult>(IStringParser <TResult> parser, string text, TResult defaultValue, Nparams param)
 {
     return(parser.Parse(text, defaultValue, param));
 }
예제 #15
0
        public StringParseResult <TResult> Parse(CoreParserParameter parameter)
        {
            var modifierLine = MergeWhiteSpace(parameter.ModifierLine.Trim());

            return(_inner.Parse(modifierLine, parameter));
        }
예제 #16
0
 public StringParseResult <TResult> Parse(CoreParserParameter parameter)
 {
     var(successfullyParsed, remaining, innerResult) = _inner.Parse(parameter);
     return(successfullyParsed, remaining, _mapper(parameter, innerResult));
 }
예제 #17
0
 public static StringParseResult <TResult> Parse <TResult>(this IStringParser <TResult> @this,
                                                           string modifierLine, CoreParserParameter previousParameter)
 => @this.Parse(modifierLine, previousParameter.ModifierSource, previousParameter.ModifierSourceEntity);