public ExprOp Parse(InputTextStream inStream, AmountParseFlagsEnum flags = AmountParseFlagsEnum.PARSE_DEFAULT, string originalString = null) { try { ExprOp topNode = ParseValueExpr(inStream, flags); if (UseLookahead) { UseLookahead = false; Lookahead.Rewind(inStream); } Lookahead.Clear(); return(topNode); } catch { if (!String.IsNullOrEmpty(originalString)) { ErrorContext.Current.AddErrorContext("While parsing value expression:"); int endPos = inStream.Pos; int pos = endPos > 0 ? endPos - Lookahead.Length : 0; ErrorContext.Current.AddErrorContext(ErrorContext.LineContext(originalString, pos, endPos)); } throw; } }
public ExprOp Parse(InputTextStream inStream, AmountParseFlagsEnum flags = AmountParseFlagsEnum.PARSE_DEFAULT, string originalString = null) { try { ExprOp topNode = ParseValueExpr(inStream, flags); if (UseLookahead) { UseLookahead = false; Lookahead.Rewind(inStream); } Lookahead.Clear(); return(topNode); } catch { if (!String.IsNullOrEmpty(originalString)) { ErrorContext.Current.AddErrorContext("While parsing value expression:"); int endPos = inStream.Pos; int pos = endPos > 0 ? endPos - Lookahead.Length : 0; Logger.Current.Debug("parser.error", () => String.Format("original_string = '{0}'", originalString)); Logger.Current.Debug("parser.error", () => String.Format(" pos = {0}", pos)); Logger.Current.Debug("parser.error", () => String.Format(" end_pos = {0}", endPos)); Logger.Current.Debug("parser.error", () => String.Format(" token kind = {0}", Lookahead.Kind)); Logger.Current.Debug("parser.error", () => String.Format(" token length = {0}", Lookahead.Length)); ErrorContext.Current.AddErrorContext(ErrorContext.LineContext(originalString, pos, endPos)); } throw; } }
public Value ConvertCommand(CallScope args) { Report report = args.Context <Report>(); Journal journal = report.Session.Journal; string bucketName; if (report.AccountHandler.Handled) { bucketName = report.AccountHandler.Str(); } else { bucketName = "Equity:Unknown"; } Account bucket = journal.Master.FindAccount(bucketName); Account unknown = journal.Master.FindAccount("Expenses:Unknown"); // Create a flat list IList <Xact> currentXacts = new List <Xact>(journal.Xacts); // Read in the series of transactions from the CSV file PrintXacts formatter = new PrintXacts(report); string csvFilePath = args.Get <string>(0); report.Session.ParsingContext.Push(csvFilePath); ParseContext context = report.Session.ParsingContext.GetCurrent(); context.Journal = journal; context.Master = bucket; CsvReader reader = new CsvReader(context); try { Xact xact; while ((xact = reader.ReadXact(report.RichDataHandler.Handled)) != null) { if (report.InvertHandler.Handled) { foreach (Post post in xact.Posts) { post.Amount.InPlaceNegate(); } } string sref = xact.HasTag("UUID") ? xact.GetTag("UUID").ToString() : SHA1.GetHash(reader.LastLine); if (journal.ChecksumMapping.ContainsKey(sref)) { continue; } if (report.RichDataHandler.Handled && !xact.HasTag("UUID")) { xact.SetTag("UUID", Value.StringValue(sref)); } if (xact.Posts.First().Account == null) { Account acct = report.AutoMatchHandler.Handled ? Lookup.LookupProbableAccount(xact.Payee, currentXacts.Reverse(), bucket).Item2 : null; if (acct != null) { xact.Posts.First().Account = acct; } else { xact.Posts.First().Account = unknown; } } if (!journal.AddXact(xact)) { throw new RuntimeError(RuntimeError.ErrorMessageFailedToFinalizeDerivedTransactionCheckCommodities); } else { XactPostsIterator xactIter = new XactPostsIterator(xact); foreach (Post post in xactIter.Get()) { formatter.Handle(post); } } } formatter.Flush(); } catch { ErrorContext.Current.AddErrorContext(String.Format("While parsing file {0}", ErrorContext.FileContext(reader.PathName, reader.LineNum))); ErrorContext.Current.AddErrorContext("While parsing CSV line:"); ErrorContext.Current.AddErrorContext(ErrorContext.LineContext(reader.LastLine)); throw; } // If not, transform the payee according to regexps // Set the account to a default vaule, then transform the account according // to the payee // Print out the final form of the transaction return(Value.True); }