diff options
author | John Wiegley <johnw@newartisans.com> | 2009-03-03 13:26:27 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-03-03 13:26:27 -0400 |
commit | 0f9d919367ada929daa6fc8d8a176a4ba63308b2 (patch) | |
tree | 71f2674b7785d0754572600791c7ca5d8c2869ed /src/parser.cc | |
parent | d7b9f9e068d6817944854a31df1fc34258707a1a (diff) | |
download | fork-ledger-0f9d919367ada929daa6fc8d8a176a4ba63308b2.tar.gz fork-ledger-0f9d919367ada929daa6fc8d8a176a4ba63308b2.tar.bz2 fork-ledger-0f9d919367ada929daa6fc8d8a176a4ba63308b2.zip |
Added Python-style if/else expression keywords
Diffstat (limited to 'src/parser.cc')
-rw-r--r-- | src/parser.cc | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/parser.cc b/src/parser.cc index 396d3a64..b3457f08 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -382,7 +382,41 @@ expr_t::parser_t::parse_querycolon_expr(std::istream& in, _("%1 operator not followed by argument") << tok.symbol); node->set_right(subnode); - } else { + } + else if (tok.kind == token_t::KW_IF) { + ptr_op_t if_op(parse_or_expr(in, tflags)); + if (! if_op) + throw_(parse_error, _("'if' keyword not followed by argument")); + + tok = next_token(in, tflags.plus_flags(PARSE_OP_CONTEXT)); + if (tok.kind == token_t::KW_ELSE) { + ptr_op_t else_op(parse_or_expr(in, tflags)); + if (! else_op) + throw_(parse_error, _("'else' keyword not followed by argument")); + + ptr_op_t subnode = new op_t(op_t::O_COLON); + subnode->set_left(node); + subnode->set_right(else_op); + + node = new op_t(op_t::O_QUERY); + node->set_left(if_op); + node->set_right(subnode); + } else { + ptr_op_t null_node = new op_t(op_t::VALUE); + null_node->set_value(NULL_VALUE); + + ptr_op_t subnode = new op_t(op_t::O_COLON); + subnode->set_left(node); + subnode->set_right(null_node); + + node = new op_t(op_t::O_QUERY); + node->set_left(if_op); + node->set_right(subnode); + + push_token(tok); + } + } + else { push_token(tok); } } |