diff options
author | John Wiegley <johnw@newartisans.com> | 2008-08-02 06:42:36 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-08-02 06:42:36 -0400 |
commit | 9a9e06554eb9f57be8c839fb0af49a0473614172 (patch) | |
tree | c31019afc5a482ff3daeb8cf672af22a0910d5a3 /parser.cc | |
parent | 5bf3f536b37e77b5dd663fffbd32e71b403d2c7a (diff) | |
download | ledger-9a9e06554eb9f57be8c839fb0af49a0473614172.tar.gz ledger-9a9e06554eb9f57be8c839fb0af49a0473614172.tar.bz2 ledger-9a9e06554eb9f57be8c839fb0af49a0473614172.zip |
Formatting now relies exclusively on value expressions.
What this means is that the utility code, basic math, value expressions,
string formatting and option handling are now entirely decoupled from the rest
of the code. This decoupling not only greatly simplifies the more basic parts
of Ledger, but makes it much easier to test and verify its completeness.
For example, when the formatting code %X is seen by the format parser, it
turns into a call to the expression function fmt_X, which must be defined when
the format string is first compiled against an object. If that object is a
transaction, the transaction's scope will be the first to have a chance at
providing a definition. If an account is being reported, it will. If neither
does, the next scope in sequence -- soon to be the current report -- will, and
then the session object that "owns" the current Ledger session.
In 2.6, the formatting code new everything about transaction and accounts, and
relied on flags to communicate special details between them. Now the
transaction will offer the details for its own reporting, while the formatter
worries only about strings and how to output them.
Diffstat (limited to 'parser.cc')
-rw-r--r-- | parser.cc | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -49,22 +49,15 @@ expr_t::parser_t::parse_value_term(std::istream& in, case token_t::MASK: { // A /mask/ is just a shorthand for calling match(). - node = new op_t(op_t::O_CALL); - - ptr_op_t ident = new op_t(op_t::IDENT); - ident->set_ident("match"); - node->set_left(ident); - - ptr_op_t args = new op_t(op_t::O_COMMA); - node->set_right(args); + node = new op_t(op_t::O_MATCH); ptr_op_t mask = new op_t(op_t::MASK); mask->set_mask(tok.value.as_string()); - ident = new op_t(op_t::IDENT); + ptr_op_t ident = new op_t(op_t::IDENT); - args->set_left(mask); - args->set_right(ident); + node->set_left(mask); + node->set_right(ident); switch (tok.flags()) { case TOKEN_SHORT_ACCOUNT_MASK: @@ -301,6 +294,12 @@ expr_t::parser_t::parse_logic_expr(std::istream& in, case token_t::NEQUAL: kind = op_t::O_NEQ; break; + case token_t::MATCH: + kind = op_t::O_MATCH; + assert(node->kind == op_t::O_MATCH); + node = node->left(); + assert(node->kind == op_t::MASK); + break; case token_t::LESS: kind = op_t::O_LT; break; |