summaryrefslogtreecommitdiff
path: root/src/op.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-11-04 20:40:07 -0500
committerJohn Wiegley <johnw@newartisans.com>2009-11-04 20:40:48 -0500
commit78e6770c4c276db3647952f21a6bf3ea465edb88 (patch)
tree64190d80ea0c3933dffaee3cf0e43cde5ea0e6a6 /src/op.cc
parent4a14f3224b9063202ca39a67c9aff42ae4274942 (diff)
downloadfork-ledger-78e6770c4c276db3647952f21a6bf3ea465edb88.tar.gz
fork-ledger-78e6770c4c276db3647952f21a6bf3ea465edb88.tar.bz2
fork-ledger-78e6770c4c276db3647952f21a6bf3ea465edb88.zip
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)
Diffstat (limited to 'src/op.cc')
-rw-r--r--src/op.cc14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/op.cc b/src/op.cc
index 67db5136..c4925143 100644
--- a/src/op.cc
+++ b/src/op.cc
@@ -43,7 +43,7 @@ expr_t::ptr_op_t expr_t::op_t::compile(scope_t& scope, const int depth)
if (is_ident()) {
DEBUG("expr.compile", "lookup: " << as_ident());
- if (ptr_op_t def = scope.lookup(as_ident())) {
+ if (ptr_op_t def = scope.lookup(symbol_t::FUNCTION, as_ident())) {
// Identifier references are first looked up at the point of
// definition, and then at the point of every use if they could
// not be found there.
@@ -65,11 +65,11 @@ expr_t::ptr_op_t expr_t::op_t::compile(scope_t& scope, const int depth)
if (kind == O_DEFINE) {
switch (left()->kind) {
case IDENT:
- scope.define(left()->as_ident(), right());
+ scope.define(symbol_t::FUNCTION, left()->as_ident(), right());
break;
case O_CALL:
if (left()->left()->is_ident())
- scope.define(left()->left()->as_ident(), this);
+ scope.define(symbol_t::FUNCTION, left()->left()->as_ident(), this);
else
throw_(compile_error, _("Invalid function definition"));
break;
@@ -152,9 +152,10 @@ value_t expr_t::op_t::calc(scope_t& scope, ptr_op_t * locus, const int depth)
if (! varname->is_ident())
throw_(calc_error, _("Invalid function definition"));
else if (args_index == args_count)
- local_scope.define(varname->as_ident(), wrap_value(false));
+ local_scope.define(symbol_t::FUNCTION, varname->as_ident(),
+ wrap_value(false));
else
- local_scope.define(varname->as_ident(),
+ local_scope.define(symbol_t::FUNCTION, varname->as_ident(),
wrap_value(call_args[args_index++]));
}
@@ -178,7 +179,8 @@ value_t expr_t::op_t::calc(scope_t& scope, ptr_op_t * locus, const int depth)
_("Left operand of . operator is NULL"));
} else {
scope_t& objscope(*obj.as_scope());
- if (ptr_op_t member = objscope.lookup(right()->as_ident())) {
+ if (ptr_op_t member =
+ objscope.lookup(symbol_t::FUNCTION, right()->as_ident())) {
result = member->calc(objscope, NULL, depth + 1);
break;
}