From 78e6770c4c276db3647952f21a6bf3ea465edb88 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 4 Nov 2009 20:40:07 -0500 Subject: Segregated symbols into 5 separate namespaces The different namespaces are: Function Value expression functions, which receive a "context" Option Command-line options Precommand Commands which are invoked before reading the journal Command Commands which are invoked after reading the journal Directive Directives that occur at column 0 in a data file This greatly eases the ability for Python uses to add intercept hooks to change how the basic Ledger module functions. An example of what should be possible soon: import ledger def my_foo_handler(value): print "--foo received:", value ledger.add_handler(ledger.Option, "foo=", my_foo_handler) --- src/session.cc | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/session.cc') diff --git a/src/session.cc b/src/session.cc index 2b8d8d58..67f19ca9 100644 --- a/src/session.cc +++ b/src/session.cc @@ -284,23 +284,26 @@ option_t * session_t::lookup_option(const char * p) return NULL; } -expr_t::ptr_op_t session_t::lookup(const string& name) +expr_t::ptr_op_t session_t::lookup(const symbol_t::kind_t kind, + const string& name) { - const char * p = name.c_str(); - switch (*p) { - case 'o': - if (WANT_OPT()) { p += OPT_PREFIX_LEN; - if (option_t * handler = lookup_option(p)) - return MAKE_OPT_HANDLER(session_t, handler); - } + switch (kind) { + case symbol_t::FUNCTION: + // Check if they are trying to access an option's setting or value. + if (option_t * handler = lookup_option(name.c_str())) + return MAKE_OPT_FUNCTOR(session_t, handler); break; - } - // Check if they are trying to access an option's setting or value. - if (option_t * handler = lookup_option(p)) - return MAKE_OPT_FUNCTOR(session_t, handler); + case symbol_t::OPTION: + if (option_t * handler = lookup_option(name.c_str())) + return MAKE_OPT_HANDLER(session_t, handler); + break; + + default: + break; + } - return symbol_scope_t::lookup(name); + return symbol_scope_t::lookup(kind, name); } } // namespace ledger -- cgit v1.2.3