/// <inheritdoc /> public override async IAsyncEnumerable <string> Execute(string expr, Session session) { Template temp = null; if (ParsingF.Token(ref expr, true, t => (temp = GetTemplate(t)) != null) == null) { throw new ArgumentException("找不到模板", nameof(expr)); } var regex = new Regex(@"^[A-Za-z]{3}$"); var currency = Parsing.Token(ref expr, false, regex.IsMatch)?.ToUpperInvariant() ?? BaseCurrency.Now; DateFilter the; if (string.IsNullOrWhiteSpace(expr)) { the = DateRange(temp.Day, session.Client.Today); } else { the = ParsingF.Range(ref expr, session.Client) ?? throw new ArgumentException("语法错误", nameof(expr)); ParsingF.Eof(expr); } yield return((await DoInquiry(the, temp, currency, session)).Item1); }
/// <inheritdoc /> public override IQueryResult Execute(string expr, IEntitiesSerializer serializer) { Template temp = null; if (ParsingF.Token(ref expr, true, t => (temp = GetTemplate(t)) != null) == null) { throw new ArgumentException("找不到模板", nameof(expr)); } var regex = new Regex(@"^[A-Za-z]{3}$"); var currency = Parsing.Token(ref expr, false, regex.IsMatch)?.ToUpperInvariant() ?? BaseCurrency.Now; DateFilter the; if (string.IsNullOrWhiteSpace(expr)) { the = DateRange(temp.Day); } else { the = ParsingF.Range(ref expr) ?? throw new ArgumentException("语法错误", nameof(expr)); ParsingF.Eof(expr); } return(DoInquiry(the, temp, out _, currency, serializer)); }
/// <inheritdoc /> public Voucher ParseVoucher(string expr) { if (!expr.StartsWith(TheToken, StringComparison.Ordinal)) { throw new FormatException("格式错误"); } expr = expr.Substring(TheToken.Length); if (ParsingF.Token(ref expr, false, s => s == "!") == null) { throw new NotImplementedException(); } var v = GetVoucher(ref expr); Parsing.TrimStartComment(ref expr); if (Parsing.Token(ref expr, false) != "}") { throw new FormatException("格式错误"); } Parsing.Eof(expr); return(v); }
/// <inheritdoc /> public override IQueryResult Execute(string expr, IEntitiesSerializer serializer) { var csv = expr; expr = ParsingF.Line(ref csv); var parsed = new CsvParser(ParsingF.Optional(ref expr, "-")); var sb = new StringBuilder(); if (ParsingF.Optional(ref expr, "mark")) { var filt = Regularize(ParsingF.DetailQuery(ref expr)); ParsingF.Optional(ref expr, "as"); var marker = ParsingF.Token(ref expr); ParsingF.Eof(expr); if (string.IsNullOrWhiteSpace(marker)) { throw new FormatException("格式错误"); } parsed.Parse(csv); sb.AppendLine($"{parsed.Items.Count} parsed"); RunMark(filt, parsed, marker, sb); } else if (ParsingF.Optional(ref expr, "unmark")) { var filt = Regularize(ParsingF.DetailQuery(ref expr)); ParsingF.Eof(expr); RunUnmark(filt, sb); } else if (ParsingF.Optional(ref expr, "check")) { var filt = Regularize(ParsingF.DetailQuery(ref expr)); ParsingF.Eof(expr); parsed.Parse(csv); sb.AppendLine($"{parsed.Items.Count} parsed"); RunCheck(filt, parsed, sb); } else { ParsingF.Optional(ref expr, "auto"); var filt = Regularize(ParsingF.DetailQuery(ref expr)); ParsingF.Optional(ref expr, "as"); var marker = ParsingF.Token(ref expr); ParsingF.Eof(expr); if (string.IsNullOrWhiteSpace(marker)) { throw new FormatException("格式错误"); } parsed.Parse(csv); sb.AppendLine($"{parsed.Items.Count} parsed"); var markerFilt = new StmtVoucherDetailQuery( filt.VoucherQuery, new IntersectQueries <IDetailQueryAtom>( filt.DetailEmitFilter.DetailFilter, new StmtDetailQuery(marker))); var nullFilt = new StmtVoucherDetailQuery( filt.VoucherQuery, new IntersectQueries <IDetailQueryAtom>( filt.DetailEmitFilter.DetailFilter, new StmtDetailQuery(""))); var nmFilt = new StmtVoucherDetailQuery( filt.VoucherQuery, new IntersectQueries <IDetailQueryAtom>( filt.DetailEmitFilter.DetailFilter, new UnionQueries <IDetailQueryAtom>( new StmtDetailQuery(""), new StmtDetailQuery(marker)))); RunUnmark(markerFilt, sb); RunMark(nullFilt, parsed, marker, sb); RunCheck(nmFilt, parsed, sb); } return(new PlainText(sb.ToString())); }
private List <Item> ParseItem(string currency, ref string expr) { var lst = new List <(VoucherDetail Detail, bool Actual)>(); while (true) { var actual = Parsing.Optional(ref expr, "!"); var vd = ParseVoucherDetail(currency, ref expr); if (vd == null) { break; } lst.Add((vd, actual)); } if (ParsingF.Token(ref expr, false, s => s == ":") == null) { return(null); } var resLst = new List <Item>(); var reg = new Regex( @"(?<num>[0-9]+(?:\.[0-9]+)?)(?:(?<equals>=[0-9]+(?:\.[0-9]+)?)|(?<plus>(?:\+[0-9]+(?:\.[0-9]+)?)+)|(?<minus>(?:-[0-9]+(?:\.[0-9]+)?)+))?"); while (true) { var res = Parsing.Token(ref expr, false, reg.IsMatch); if (res == null) { break; } var m = reg.Match(res); var fund0 = Convert.ToDouble(m.Groups["num"].Value); var fundd = 0D; if (m.Groups["equals"].Success) { fundd = fund0 - Convert.ToDouble(m.Groups["equals"].Value.Substring(1)); } else if (m.Groups["plus"].Success) { var sreg = new Regex(@"\+[0-9]+(?:\.[0-9]+)?"); foreach (Match sm in sreg.Matches(m.Groups["plus"].Value)) { fundd += Convert.ToDouble(sm.Value); } fund0 += fundd; } else if (m.Groups["minus"].Success) { var sreg = new Regex(@"-[0-9]+(?:\.[0-9]+)?"); foreach (Match sm in sreg.Matches(m.Groups["minus"].Value)) { fundd -= Convert.ToDouble(sm.Value); } } resLst.AddRange( lst.Select( d => new Item { Currency = d.Detail.Currency, Title = d.Detail.Title, SubTitle = d.Detail.SubTitle, Content = d.Detail.Content, Fund = fund0 / lst.Count, DiscountFund = fundd / lst.Count, Remark = d.Detail.Remark, UseActualFund = d.Actual })); } ParsingF.Optional(ref expr, ";"); return(resLst); }
/// <inheritdoc /> public override async IAsyncEnumerable <string> Execute(string expr, Session session) { var csv = expr; expr = ParsingF.Line(ref csv); var parsed = new CsvParser(ParsingF.Optional(ref expr, "-")); if (ParsingF.Optional(ref expr, "mark")) { var filt = ParsingF.DetailQuery(ref expr, session.Client); ParsingF.Optional(ref expr, "as"); var marker = ParsingF.Token(ref expr); ParsingF.Eof(expr); if (string.IsNullOrWhiteSpace(marker)) { throw new FormatException("格式错误"); } parsed.Parse(csv); yield return($"{parsed.Items.Count} parsed\n"); await foreach (var s in RunMark(session, filt, parsed, marker)) { yield return(s); } } else if (ParsingF.Optional(ref expr, "unmark")) { var filt = ParsingF.DetailQuery(ref expr, session.Client); ParsingF.Eof(expr); await foreach (var s in RunUnmark(session, filt)) { yield return(s); } } else if (ParsingF.Optional(ref expr, "check")) { var filt = ParsingF.DetailQuery(ref expr, session.Client); ParsingF.Eof(expr); parsed.Parse(csv); yield return($"{parsed.Items.Count} parsed\n"); await foreach (var s in RunCheck(session, filt, parsed)) { yield return(s); } } else { ParsingF.Optional(ref expr, "auto"); var filt = ParsingF.DetailQuery(ref expr, session.Client); ParsingF.Optional(ref expr, "as"); var marker = ParsingF.Token(ref expr); ParsingF.Eof(expr); if (string.IsNullOrWhiteSpace(marker)) { throw new FormatException("格式错误"); } parsed.Parse(csv); yield return($"{parsed.Items.Count} parsed\n"); var markerFilt = new StmtVoucherDetailQuery( filt.VoucherQuery, new IntersectQueries <IDetailQueryAtom>( filt.ActualDetailFilter(), new StmtDetailQuery(marker))); var nullFilt = new StmtVoucherDetailQuery( filt.VoucherQuery, new IntersectQueries <IDetailQueryAtom>( filt.ActualDetailFilter(), new StmtDetailQuery(""))); var nmFilt = new StmtVoucherDetailQuery( filt.VoucherQuery, new IntersectQueries <IDetailQueryAtom>( filt.ActualDetailFilter(), new UnionQueries <IDetailQueryAtom>( new StmtDetailQuery(""), new StmtDetailQuery(marker)))); await foreach (var s in RunUnmark(session, markerFilt)) { yield return(s); } await foreach (var s in RunMark(session, nullFilt, parsed, marker)) { yield return(s); } await foreach (var s in RunCheck(session, nmFilt, parsed)) { yield return(s); } } }