diff options
author | John Wiegley <johnw@newartisans.com> | 2008-09-14 19:42:32 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-09-14 19:44:35 -0400 |
commit | db9f89100382b019892de66b0353c7f6fbef6f9d (patch) | |
tree | 52acc959ca3b1874ee780b939ae9ef9afe582ad6 | |
parent | 53c6e826f1e41f29c86f1c86f179f38838123d1d (diff) | |
download | fork-ledger-db9f89100382b019892de66b0353c7f6fbef6f9d.tar.gz fork-ledger-db9f89100382b019892de66b0353c7f6fbef6f9d.tar.bz2 fork-ledger-db9f89100382b019892de66b0353c7f6fbef6f9d.zip |
Added value expression parsing flag EXPR_PARSE_SINGLE, which means to read
only a single expression and then quit immediately. Useful for parsing
expressions that begin with a left parenthesis and are known to end at the
right parenthesis.
-rw-r--r-- | src/format.cc | 2 | ||||
-rw-r--r-- | src/parser.cc | 9 | ||||
-rw-r--r-- | src/parser.h | 9 |
3 files changed, 11 insertions, 9 deletions
diff --git a/src/format.cc b/src/format.cc index 3b3c562a..121cdf63 100644 --- a/src/format.cc +++ b/src/format.cc @@ -212,7 +212,7 @@ format_t::element_t * format_t::parse_elements(const string& fmt) case '[': { std::istringstream str(p); current->type = element_t::EXPR; - current->expr.parse(str, EXPR_PARSE_PARTIAL); + current->expr.parse(str, EXPR_PARSE_SINGLE); istream_pos_type pos = str.tellg(); current->expr.set_text(string(p, p + long(pos))); p += long(pos) - 1; diff --git a/src/parser.cc b/src/parser.cc index 922e3453..eabcb845 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -64,7 +64,7 @@ expr_t::parser_t::parse_value_term(std::istream& in, ptr_op_t call_node(new op_t(op_t::O_CALL)); call_node->set_left(node); - call_node->set_right(parse_value_expr(in, tflags | EXPR_PARSE_PARTIAL)); + call_node->set_right(parse_value_expr(in, tflags | EXPR_PARSE_SINGLE)); tok = next_token(in, tflags); if (tok.kind != token_t::RPAREN) @@ -85,7 +85,7 @@ expr_t::parser_t::parse_value_term(std::istream& in, } case token_t::LPAREN: - node = parse_value_expr(in, tflags | EXPR_PARSE_PARTIAL); + node = parse_value_expr(in, tflags | EXPR_PARSE_SINGLE); if (! node) throw_(parse_error, tok.symbol << " operator not followed by expression"); @@ -355,7 +355,7 @@ expr_t::parser_t::parse_value_expr(std::istream& in, { ptr_op_t node(parse_querycolon_expr(in, tflags)); - if (node) { + if (node && ! (tflags & EXPR_PARSE_SINGLE)) { token_t& tok = next_token(in, tflags); if (tok.kind == token_t::COMMA) { @@ -376,7 +376,8 @@ expr_t::parser_t::parse_value_expr(std::istream& in, tok.unexpected(); } } - else if (! (tflags & EXPR_PARSE_PARTIAL)) { + else if (! (tflags & (EXPR_PARSE_PARTIAL | + EXPR_PARSE_SINGLE))) { throw_(parse_error, "Failed to parse value expression"); } diff --git a/src/parser.h b/src/parser.h index 294d28ff..a9828c05 100644 --- a/src/parser.h +++ b/src/parser.h @@ -41,10 +41,11 @@ class expr_t::parser_t : public noncopyable { #define EXPR_PARSE_NORMAL 0x00 #define EXPR_PARSE_PARTIAL 0x01 -#define EXPR_PARSE_NO_MIGRATE 0x02 -#define EXPR_PARSE_NO_REDUCE 0x04 -#define EXPR_PARSE_NO_ASSIGN 0x08 -#define EXPR_PARSE_NO_DATES 0x10 +#define EXPR_PARSE_SINGLE 0x02 +#define EXPR_PARSE_NO_MIGRATE 0x04 +#define EXPR_PARSE_NO_REDUCE 0x08 +#define EXPR_PARSE_NO_ASSIGN 0x10 +#define EXPR_PARSE_NO_DATES 0x20 public: typedef uint_least8_t flags_t; |