Refactored the textual parser, to allow easy extensions in Python.
This commit is contained in:
parent
3c0e2138fc
commit
c96635fe60
4 changed files with 703 additions and 553 deletions
1114
src/textual.cc
1114
src/textual.cc
File diff suppressed because it is too large
Load diff
127
src/textual.h
127
src/textual.h
|
|
@ -37,20 +37,113 @@
|
||||||
|
|
||||||
namespace ledger {
|
namespace ledger {
|
||||||
|
|
||||||
|
#define TIMELOG_SUPPORT 1
|
||||||
|
|
||||||
|
#if defined(TIMELOG_SUPPORT)
|
||||||
|
class time_log_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
class textual_parser_t : public journal_t::parser_t
|
class textual_parser_t : public journal_t::parser_t
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual bool test(std::istream& in) const;
|
virtual bool test(std::istream& in) const;
|
||||||
|
|
||||||
virtual unsigned int parse(std::istream& in,
|
virtual std::size_t parse(std::istream& in,
|
||||||
session_t& session,
|
session_t& session,
|
||||||
journal_t& journal,
|
journal_t& journal,
|
||||||
account_t * master = NULL,
|
account_t * master = NULL,
|
||||||
const path * original_file = NULL);
|
const path * original_file = NULL);
|
||||||
};
|
|
||||||
|
|
||||||
xact_t * parse_xact_text(char * line, account_t * account);
|
protected:
|
||||||
xact_t * parse_xact(std::istream& in, account_t * account);
|
class instance_t : public noncopyable, public scope_t
|
||||||
|
{
|
||||||
|
static const std::size_t MAX_LINE = 1024;
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::list<account_t *>& account_stack;
|
||||||
|
#if defined(TIMELOG_SUPPORT)
|
||||||
|
time_log_t& timelog;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
instance_t * parent;
|
||||||
|
std::istream& in;
|
||||||
|
session_t& session;
|
||||||
|
journal_t& journal;
|
||||||
|
account_t * master;
|
||||||
|
const path * original_file;
|
||||||
|
accounts_map account_aliases;
|
||||||
|
|
||||||
|
path pathname;
|
||||||
|
std::size_t linenum;
|
||||||
|
std::size_t src_idx;
|
||||||
|
istream_pos_type beg_pos;
|
||||||
|
istream_pos_type end_pos;
|
||||||
|
unsigned long beg_line;
|
||||||
|
std::size_t count;
|
||||||
|
std::size_t errors;
|
||||||
|
|
||||||
|
char linebuf[MAX_LINE + 1];
|
||||||
|
|
||||||
|
scoped_ptr<auto_entry_finalizer_t> auto_entry_finalizer;
|
||||||
|
|
||||||
|
instance_t(std::list<account_t *>& _account_stack,
|
||||||
|
#if defined(TIMELOG_SUPPORT)
|
||||||
|
time_log_t& _timelog,
|
||||||
|
#endif
|
||||||
|
std::istream& _in,
|
||||||
|
session_t& _session,
|
||||||
|
journal_t& _journal,
|
||||||
|
account_t * _master = NULL,
|
||||||
|
const path * _original_file = NULL,
|
||||||
|
instance_t * _parent = NULL);
|
||||||
|
|
||||||
|
~instance_t();
|
||||||
|
|
||||||
|
void parse();
|
||||||
|
void read_next_directive();
|
||||||
|
|
||||||
|
#if defined(TIMELOG_SUPPORT)
|
||||||
|
void clock_in_directive(char * line, bool capitalized);
|
||||||
|
void clock_out_directive(char * line, bool capitalized);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void default_commodity_directive(char * line);
|
||||||
|
void default_account_directive(char * line);
|
||||||
|
void price_conversion_directive(char * line);
|
||||||
|
void price_entry_directive(char * line);
|
||||||
|
void nomarket_directive(char * line);
|
||||||
|
void year_directive(char * line);
|
||||||
|
void option_directive(char * line);
|
||||||
|
void automated_entry_directive(char * line);
|
||||||
|
void period_entry_directive(char * line);
|
||||||
|
void entry_directive(char * line);
|
||||||
|
void include_directive(char * line);
|
||||||
|
void account_directive(char * line);
|
||||||
|
void end_directive(char * line);
|
||||||
|
void alias_directive(char * line);
|
||||||
|
void define_directive(char * line);
|
||||||
|
void general_directive(char * line);
|
||||||
|
|
||||||
|
xact_t * parse_xact(char * line,
|
||||||
|
account_t * account,
|
||||||
|
entry_t * entry);
|
||||||
|
|
||||||
|
bool parse_xacts(std::istream& in,
|
||||||
|
account_t * account,
|
||||||
|
entry_base_t& entry,
|
||||||
|
const string& kind,
|
||||||
|
istream_pos_type beg_pos);
|
||||||
|
|
||||||
|
entry_t * parse_entry(std::istream& in,
|
||||||
|
char * line,
|
||||||
|
account_t * master,
|
||||||
|
istream_pos_type& pos);
|
||||||
|
|
||||||
|
virtual expr_t::ptr_op_t lookup(const string& name);
|
||||||
|
};
|
||||||
|
|
||||||
|
friend class instance_t;
|
||||||
|
};
|
||||||
|
|
||||||
void write_textual_journal(journal_t& journal,
|
void write_textual_journal(journal_t& journal,
|
||||||
const path& pathname,
|
const path& pathname,
|
||||||
|
|
@ -58,24 +151,6 @@ void write_textual_journal(journal_t& journal,
|
||||||
const string& write_hdr_format,
|
const string& write_hdr_format,
|
||||||
std::ostream& out);
|
std::ostream& out);
|
||||||
|
|
||||||
#if 0
|
|
||||||
class include_context : public file_context
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
include_context(const path& file, unsigned long line,
|
|
||||||
const string& desc = "") throw()
|
|
||||||
: file_context(file, line, desc) {}
|
|
||||||
virtual ~include_context() throw() {}
|
|
||||||
|
|
||||||
virtual void describe(std::ostream& out) const throw() {
|
|
||||||
if (! desc.empty())
|
|
||||||
out << desc << ": ";
|
|
||||||
out << "\"" << file.string() << "\", line " << line << ":"
|
|
||||||
<< std::endl;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace ledger
|
} // namespace ledger
|
||||||
|
|
||||||
#endif // _TEXTUAL_H
|
#endif // _TEXTUAL_H
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "timelog.h"
|
||||||
|
|
||||||
namespace ledger {
|
namespace ledger {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
@ -119,8 +121,8 @@ time_log_t::~time_log_t()
|
||||||
}
|
}
|
||||||
|
|
||||||
void time_log_t::clock_in(const datetime_t& checkin,
|
void time_log_t::clock_in(const datetime_t& checkin,
|
||||||
account_t * account = NULL,
|
account_t * account,
|
||||||
const string& desc = "")
|
const string& desc)
|
||||||
{
|
{
|
||||||
time_entry_t event(checkin, account, desc);
|
time_entry_t event(checkin, account, desc);
|
||||||
|
|
||||||
|
|
@ -133,13 +135,14 @@ void time_log_t::clock_in(const datetime_t& checkin,
|
||||||
}
|
}
|
||||||
|
|
||||||
void time_log_t::clock_out(const datetime_t& checkin,
|
void time_log_t::clock_out(const datetime_t& checkin,
|
||||||
account_t * account = NULL,
|
account_t * account,
|
||||||
const string& desc = "")
|
const string& desc)
|
||||||
{
|
{
|
||||||
if (time_entries.empty())
|
if (time_entries.empty())
|
||||||
throw std::logic_error("Timelog check-out event without a check-in");
|
throw std::logic_error("Timelog check-out event without a check-in");
|
||||||
|
|
||||||
clock_out_from_timelog(time_entries, checkin, account, desc, journal);
|
clock_out_from_timelog(time_entries, checkin, account, desc.c_str(),
|
||||||
|
journal);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ledger
|
} // namespace ledger
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@
|
||||||
#ifndef _TIMELOG_H
|
#ifndef _TIMELOG_H
|
||||||
#define _TIMELOG_H
|
#define _TIMELOG_H
|
||||||
|
|
||||||
|
#include "journal.h"
|
||||||
|
|
||||||
namespace ledger {
|
namespace ledger {
|
||||||
|
|
||||||
class time_entry_t
|
class time_entry_t
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue