Example #1
0
        protected override Maybe <IReportNode> Execute(TextParser p)
        {
            var prefix = p.After("Can Study:").SkipWhitespaces();

            if (!prefix)
            {
                return(Error(prefix));
            }

            List <IReportNode> skills = new List <IReportNode>();

            while (!p.EOF)
            {
                if (skills.Count > 0)
                {
                    if (!Mem(p.After(",").SkipWhitespaces()))
                    {
                        return(Error(LastResult));
                    }
                }

                var skill = skillParser.Parse(p);
                if (!skill)
                {
                    return(Error(skill));
                }

                skills.Add(skill.Value);
            }

            return(Ok(ReportNode.Bag(
                          ReportNode.Key("canStudy", ReportNode.Array(skills))
                          )));
        }
Example #2
0
 private T Parse(EmailMessageInfo emailMessageInfo)
 {
     try
     {
         return(_reportParser.Parse(emailMessageInfo));
     }
     catch (Exception e)
     {
         _log.Error($"Failed to process {emailMessageInfo.EmailMetadata.Filename} with error {e.Message} {System.Environment.NewLine} {e.StackTrace}");
         return(null);
     }
 }
        public Task <Result <TDomain> > ProcessEmailMessage(EmailMessageInfo messageInfo)
        {
            try
            {
                _log.Info($"Parsing email message, message Id: {messageInfo.EmailMetadata.MessageId}, request Id: {messageInfo.EmailMetadata.RequestId}.");

                TDomain report = _parser.Parse(messageInfo);

                _log.Info($"Successfully parsed email message, message Id: {messageInfo.EmailMetadata.MessageId}, request Id: {messageInfo.EmailMetadata.RequestId}.");

                return(Task.FromResult(new Result <TDomain>(report, true, false)));
            }
            catch (Exception e)
            {
                _log.Error($"Failed to process email message, message Id: {messageInfo.EmailMetadata.MessageId}, request Id: {messageInfo.EmailMetadata.RequestId} with error {e.Message}{System.Environment.NewLine}{e.StackTrace}");
                return(Task.FromResult(Result <TDomain> .FailedResult));
            }
        }
Example #4
0
 public static Maybe <IReportNode[]> List(this TextParser p, ReadOnlySpan <char> separator, IReportParser itemParser)
 => List(p, separator, x => itemParser.Parse(x));
Example #5
0
 public static Maybe <IReportNode> ParseMaybe(this IReportParser parser, Maybe <TextParser> p)
 => p?parser.Parse(p.Value) : p.Convert <IReportNode>();
Example #6
0
        protected override Maybe <IReportNode> Execute(TextParser p)
        {
            // don't need dot at the end of line
            p = p.BeforeBackwards(".");

            bool own = false;

            if (p.Match("*"))
            {
                own = true;
            }
            else if (!Mem(p.Match("-")))
            {
                return(Error(LastResult));
            }

            p = p.SkipWhitespaces();

            // unit name
            // Legatus Legionis Marcus (640)
            var name = nameParser.Parse(p);

            if (!name)
            {
                return(Error(name));
            }

            // optional on guard flag
            // , on guard
            var onGuard = p.Try(parser => parser.After(",").SkipWhitespaces().Match("on guard"));

            // optional faction name unless this is own unit
            // , Avalon Empire (15)
            var faction = p.Try(parser => factionParser.Parse(parser.After(",").SkipWhitespaces()));

            if (!faction && own)
            {
                return(Error(faction));
            }

            // now check for description, it must start with `;`
            Maybe <string> description = Maybe <string> .NA;

            p.PushBookmark();
            if (p.After(";"))
            {
                var descPos = p.Pos - 2;
                description = new Maybe <string>(p.SkipWhitespaces().SkipWhitespacesBackwards().AsString());

                // w/o description
                p.PopBookmark();
                p = p.Slice(descPos - p.Pos + 1);
            }
            else
            {
                p.RemoveBookmark();
            }

            List <string>      flags = new List <string>();
            List <IReportNode> items = new List <IReportNode>();

            // all element after faction name till first item are flags
            while (items.Count == 0 && !p.EOF)
            {
                // , flag
                if (!Mem(p.After(",").SkipWhitespaces()))
                {
                    return(Error(LastResult));
                }

                // there could be no flags
                var flagOrItem = p.Before(",", ".").RecoverWith(() => p);

                var item = itemParser.Parse(flagOrItem);
                if (item)
                {
                    items.Add(item.Value);
                }
                else
                {
                    flags.Add(flagOrItem.Reset().AsString());
                }
            }

            var remainingItems = p.Before(".").RecoverWith(() => p).Value;

            while (!remainingItems.EOF)
            {
                var nextItem = remainingItems.After(",").SkipWhitespaces();
                if (!nextItem)
                {
                    break;
                }

                var item = itemParser.ParseMaybe(nextItem.Before(",").RecoverWith(() => nextItem));
                if (item)
                {
                    items.Add(item.Value);
                }
            }

            List <IReportNode> props = new List <IReportNode>();

            while (!p.EOF)
            {
                var nextProp = p.After(".").SkipWhitespaces();
                if (!nextProp)
                {
                    break;
                }

                var notSuccess = !nextProp.Success;

                nextProp = nextProp.Before(".").RecoverWith(() => nextProp);
                var prop = nextProp.OneOf(
                    weightParser,
                    capacityParser,
                    canStudyParser,
                    skillsParser
                    );
                if (prop)
                {
                    props.Add(prop.Value);
                }
            }

            var result = ReportNode.Object();

            result.Add(ReportNode.Bool("own", own));
            result.Add(name.Value);
            result.Add(ReportNode.Key("faction", faction ? ReportNode.Object(faction.Value) : ReportNode.Null()));
            result.Add(ReportNode.Key("description", description ? ReportNode.Str(description) : ReportNode.Null()));
            result.Add(ReportNode.Bool("onGuard", onGuard));
            result.Add(ReportNode.Key("flags", ReportNode.Array(flags.Select(x => ReportNode.Str(x)))));
            result.Add(ReportNode.Key("items", ReportNode.Array(items)));
            result.AddRange(props);

            return(new Maybe <IReportNode>(result));
        }
Example #7
0
        public int ParseReport()
        {
            int simianDuplicates = _reportParser.Parse(simianReportPath);

            return(simianDuplicates);
        }
Example #8
0
        public int ParseReport()
        {
            int ticsErrors = _reportParser.Parse(ticsReportPath);

            return(ticsErrors);
        }