diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-15 16:34:34 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-15 16:34:34 -0400 |
commit | 6f7f87699c509131ab5ffff330ba77abbd58e829 (patch) | |
tree | 17960cb9541037bb05abed7c0b8b6cd949e72b05 /src | |
parent | fcd7f4f73b50ec02ec1f501a8ebde502c6736850 (diff) | |
download | fork-ledger-6f7f87699c509131ab5ffff330ba77abbd58e829.tar.gz fork-ledger-6f7f87699c509131ab5ffff330ba77abbd58e829.tar.bz2 fork-ledger-6f7f87699c509131ab5ffff330ba77abbd58e829.zip |
Parse '/' in an operator context as "div"
Diffstat (limited to 'src')
-rw-r--r-- | src/expr.h | 3 | ||||
-rw-r--r-- | src/op.cc | 2 | ||||
-rw-r--r-- | src/parser.cc | 25 | ||||
-rw-r--r-- | src/report.h | 2 | ||||
-rw-r--r-- | src/token.cc | 11 | ||||
-rw-r--r-- | src/token.h | 3 |
6 files changed, 22 insertions, 24 deletions
@@ -83,7 +83,8 @@ public: PARSE_NO_MIGRATE = 0x04, PARSE_NO_REDUCE = 0x08, PARSE_NO_ASSIGN = 0x10, - PARSE_NO_DATES = 0x20 + PARSE_NO_DATES = 0x20, + PARSE_OP_CONTEXT = 0x40 }; private: @@ -376,7 +376,7 @@ bool expr_t::op_t::print(std::ostream& out, const context_t& context) const out << "("; if (left() && left()->print(out, context)) found = true; - out << " // "; + out << " / "; if (has_right() && right()->print(out, context)) found = true; out << ")"; diff --git a/src/parser.cc b/src/parser.cc index f774c78d..2dab4901 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -54,7 +54,7 @@ expr_t::parser_t::parse_value_term(std::istream& in, node->set_ident(ident); // An identifier followed by ( represents a function call - tok = next_token(in, tflags); + tok = next_token(in, tflags.plus_flags(PARSE_OP_CONTEXT)); if (tok.kind == token_t::LPAREN) { ptr_op_t call_node(new op_t(op_t::O_CALL)); call_node->set_left(node); @@ -91,7 +91,7 @@ expr_t::parser_t::parse_dot_expr(std::istream& in, if (node && ! tflags.has_flags(PARSE_SINGLE)) { while (true) { - token_t& tok = next_token(in, tflags); + token_t& tok = next_token(in, tflags.plus_flags(PARSE_OP_CONTEXT)); if (tok.kind == token_t::DOT) { ptr_op_t prev(node); node = new op_t(op_t::O_LOOKUP); @@ -170,9 +170,10 @@ expr_t::parser_t::parse_mul_expr(std::istream& in, if (node && ! tflags.has_flags(PARSE_SINGLE)) { while (true) { - token_t& tok = next_token(in, tflags); + token_t& tok = next_token(in, tflags.plus_flags(PARSE_OP_CONTEXT)); - if (tok.kind == token_t::STAR || tok.kind == token_t::KW_DIV) { + if (tok.kind == token_t::STAR || tok.kind == token_t::SLASH || + tok.kind == token_t::KW_DIV) { ptr_op_t prev(node); node = new op_t(tok.kind == token_t::STAR ? op_t::O_MUL : op_t::O_DIV); @@ -199,7 +200,7 @@ expr_t::parser_t::parse_add_expr(std::istream& in, if (node && ! tflags.has_flags(PARSE_SINGLE)) { while (true) { - token_t& tok = next_token(in, tflags); + token_t& tok = next_token(in, tflags.plus_flags(PARSE_OP_CONTEXT)); if (tok.kind == token_t::PLUS || tok.kind == token_t::MINUS) { @@ -231,7 +232,7 @@ expr_t::parser_t::parse_logic_expr(std::istream& in, while (true) { op_t::kind_t kind = op_t::LAST; parse_flags_t _flags = tflags; - token_t& tok = next_token(in, tflags); + token_t& tok = next_token(in, tflags.plus_flags(PARSE_OP_CONTEXT)); bool negate = false; switch (tok.kind) { @@ -303,7 +304,7 @@ expr_t::parser_t::parse_and_expr(std::istream& in, if (node && ! tflags.has_flags(PARSE_SINGLE)) { while (true) { - token_t& tok = next_token(in, tflags); + token_t& tok = next_token(in, tflags.plus_flags(PARSE_OP_CONTEXT)); if (tok.kind == token_t::KW_AND) { ptr_op_t prev(node); @@ -330,7 +331,7 @@ expr_t::parser_t::parse_or_expr(std::istream& in, if (node && ! tflags.has_flags(PARSE_SINGLE)) { while (true) { - token_t& tok = next_token(in, tflags); + token_t& tok = next_token(in, tflags.plus_flags(PARSE_OP_CONTEXT)); if (tok.kind == token_t::KW_OR) { ptr_op_t prev(node); @@ -356,7 +357,7 @@ expr_t::parser_t::parse_querycolon_expr(std::istream& in, ptr_op_t node(parse_or_expr(in, tflags)); if (node && ! tflags.has_flags(PARSE_SINGLE)) { - token_t& tok = next_token(in, tflags); + token_t& tok = next_token(in, tflags.plus_flags(PARSE_OP_CONTEXT)); if (tok.kind == token_t::QUERY) { ptr_op_t prev(node); @@ -367,7 +368,7 @@ expr_t::parser_t::parse_querycolon_expr(std::istream& in, throw_(parse_error, tok.symbol << " operator not followed by argument"); - token_t& next_tok = next_token(in, tflags); + token_t& next_tok = next_token(in, tflags.plus_flags(PARSE_OP_CONTEXT)); if (next_tok.kind != token_t::COLON) next_tok.expected(':'); @@ -394,7 +395,7 @@ expr_t::parser_t::parse_value_expr(std::istream& in, ptr_op_t node(parse_querycolon_expr(in, tflags)); if (node && ! tflags.has_flags(PARSE_SINGLE)) { - token_t& tok = next_token(in, tflags); + token_t& tok = next_token(in, tflags.plus_flags(PARSE_OP_CONTEXT)); if (tok.kind == token_t::COMMA) { ptr_op_t prev(node); @@ -404,7 +405,7 @@ expr_t::parser_t::parse_value_expr(std::istream& in, if (! node->right()) throw_(parse_error, tok.symbol << " operator not followed by argument"); - tok = next_token(in, tflags); + tok = next_token(in, tflags.plus_flags(PARSE_OP_CONTEXT)); } if (tok.kind != token_t::TOK_EOF) { diff --git a/src/report.h b/src/report.h index 32523b07..9356deed 100644 --- a/src/report.h +++ b/src/report.h @@ -231,7 +231,7 @@ public: OPTION(report_t, ansi_invert); OPTION_(report_t, average, DO() { // -A - parent->HANDLER(display_total_).set_expr("total//count"); + parent->HANDLER(display_total_).set_expr("total/count"); }); OPTION(report_t, balance_format_); diff --git a/src/token.cc b/src/token.cc index 9311f60a..6286870b 100644 --- a/src/token.cc +++ b/src/token.cc @@ -272,14 +272,9 @@ void expr_t::token_t::next(std::istream& in, const uint_least8_t pflags) case '/': { in.get(c); - c = in.peek(); - if (c == '/') { - in.get(c); - symbol[1] = c; - symbol[2] = '\0'; - kind = KW_DIV; - length = 2; - } else { + if (pflags & PARSE_OP_CONTEXT) { // operator context + kind = SLASH; + } else { // terminal context // Read in the regexp char buf[256]; READ_INTO_(in, buf, 255, c, length, c != '/'); diff --git a/src/token.h b/src/token.h index 55e222ba..d0b65ded 100644 --- a/src/token.h +++ b/src/token.h @@ -80,7 +80,8 @@ struct expr_t::token_t : public noncopyable MINUS, // - PLUS, // + STAR, // * - KW_DIV, // / + SLASH, // / + KW_DIV, // div EXCLAM, // !, not KW_AND, // &, &&, and |