/// <inheritdoc /> public override IAsyncEnumerable <string> Execute(string expr, Session session) { var content = Parsing.Token(ref expr); return(ParsingF.Optional(ref expr, "q") ? Query(content, expr, session) : Create(content, expr, session)); }
/// <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())); }
/// <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); } } }
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 IQueryResult Execute(string expr, IEntitiesSerializer serializer) { var content = Parsing.Token(ref expr); return(ParsingF.Optional(ref expr, "q") ? Query(content, ref expr) : Create(content, ref expr, serializer)); }