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.
This commit is contained in:
parent
53c6e826f1
commit
db9f891003
3 changed files with 11 additions and 9 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue