diff options
author | John Wiegley <johnw@newartisans.com> | 2009-05-26 23:45:44 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-05-26 23:45:44 -0500 |
commit | 0e9f782a05ab9bc892af40abef84346a16d3baec (patch) | |
tree | f03ab214032d27f2989edf537bcaf8daee11cb28 /src/parser.cc | |
parent | d2062bb54cad108fe7f9e03fdb0f10d18cc721fc (diff) | |
download | fork-ledger-0e9f782a05ab9bc892af40abef84346a16d3baec.tar.gz fork-ledger-0e9f782a05ab9bc892af40abef84346a16d3baec.tar.bz2 fork-ledger-0e9f782a05ab9bc892af40abef84346a16d3baec.zip |
Added % suffix operator, as in "$1.00 * 10%"
Diffstat (limited to 'src/parser.cc')
-rw-r--r-- | src/parser.cc | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/parser.cc b/src/parser.cc index 39004758..1c78e30d 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -44,10 +44,23 @@ expr_t::parser_t::parse_value_term(std::istream& in, token_t& tok = next_token(in, tflags); switch (tok.kind) { - case token_t::VALUE: + case token_t::VALUE: { node = new op_t(op_t::VALUE); node->set_value(tok.value); + + token_t& postfix_tok = next_token(in, tflags.plus_flags(PARSE_OP_CONTEXT)); + if (postfix_tok.kind == token_t::PERCENT) { + ptr_op_t prev(node); + node = new op_t(op_t::O_DIV); + node->set_left(prev); + ptr_op_t hundred = new op_t(op_t::VALUE); + hundred->set_value(100L); + node->set_right(hundred); + } else { + push_token(postfix_tok); + } break; + } case token_t::IDENT: { string ident = tok.value.as_string(); |