summaryrefslogtreecommitdiff
path: root/src/parser.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-09-14 19:42:32 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-09-14 19:44:35 -0400
commitdb9f89100382b019892de66b0353c7f6fbef6f9d (patch)
tree52acc959ca3b1874ee780b939ae9ef9afe582ad6 /src/parser.cc
parent53c6e826f1e41f29c86f1c86f179f38838123d1d (diff)
downloadfork-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.
Diffstat (limited to 'src/parser.cc')
-rw-r--r--src/parser.cc9
1 files changed, 5 insertions, 4 deletions
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");
}