Fixes to the way that EXPR_PARSE_SINGLE behaves.
This commit is contained in:
parent
50ee03e3f0
commit
01aa3800fb
2 changed files with 28 additions and 22 deletions
|
|
@ -212,14 +212,22 @@ format_t::element_t * format_t::parse_elements(const string& fmt)
|
||||||
case '[': {
|
case '[': {
|
||||||
std::istringstream str(p);
|
std::istringstream str(p);
|
||||||
current->type = element_t::EXPR;
|
current->type = element_t::EXPR;
|
||||||
current->expr.parse(str, EXPR_PARSE_SINGLE);
|
string temp(p);
|
||||||
istream_pos_type pos = str.tellg();
|
current->expr.parse(str, EXPR_PARSE_SINGLE, &temp);
|
||||||
current->expr.set_text(string(p, p + long(pos)));
|
if (str.eof()) {
|
||||||
p += long(pos) - 1;
|
current->expr.set_text(p);
|
||||||
// Don't gobble up any whitespace
|
p += std::strlen(p);
|
||||||
const char * base = p;
|
} else {
|
||||||
while (p >= base && std::isspace(*p))
|
assert(str.good());
|
||||||
p--;
|
istream_pos_type pos = str.tellg();
|
||||||
|
current->expr.set_text(string(p, p + long(pos)));
|
||||||
|
p += long(pos) - 1;
|
||||||
|
|
||||||
|
// Don't gobble up any whitespace
|
||||||
|
const char * base = p;
|
||||||
|
while (p >= base && std::isspace(*p))
|
||||||
|
p--;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,13 +64,10 @@ expr_t::parser_t::parse_value_term(std::istream& in,
|
||||||
|
|
||||||
ptr_op_t call_node(new op_t(op_t::O_CALL));
|
ptr_op_t call_node(new op_t(op_t::O_CALL));
|
||||||
call_node->set_left(node);
|
call_node->set_left(node);
|
||||||
call_node->set_right(parse_value_expr(in, tflags | EXPR_PARSE_SINGLE));
|
|
||||||
|
|
||||||
tok = next_token(in, tflags);
|
|
||||||
if (tok.kind != token_t::RPAREN)
|
|
||||||
tok.expected(')');
|
|
||||||
|
|
||||||
node = call_node;
|
node = call_node;
|
||||||
|
|
||||||
|
push_token(tok); // let the parser see it again
|
||||||
|
node->set_right(parse_value_expr(in, tflags | EXPR_PARSE_SINGLE));
|
||||||
} else {
|
} else {
|
||||||
if (std::isdigit(ident[0])) {
|
if (std::isdigit(ident[0])) {
|
||||||
node = new op_t(op_t::INDEX);
|
node = new op_t(op_t::INDEX);
|
||||||
|
|
@ -85,9 +82,10 @@ expr_t::parser_t::parse_value_term(std::istream& in,
|
||||||
}
|
}
|
||||||
|
|
||||||
case token_t::LPAREN:
|
case token_t::LPAREN:
|
||||||
node = parse_value_expr(in, tflags | EXPR_PARSE_SINGLE);
|
node = parse_value_expr(in, (tflags | EXPR_PARSE_PARTIAL) &
|
||||||
|
~EXPR_PARSE_SINGLE);
|
||||||
if (! node)
|
if (! node)
|
||||||
throw_(parse_error, tok.symbol << " operator not followed by expression");
|
throw_(parse_error, "Left parenthesis not followed by an expression");
|
||||||
|
|
||||||
tok = next_token(in, tflags);
|
tok = next_token(in, tflags);
|
||||||
if (tok.kind != token_t::RPAREN)
|
if (tok.kind != token_t::RPAREN)
|
||||||
|
|
@ -160,7 +158,7 @@ expr_t::parser_t::parse_mul_expr(std::istream& in,
|
||||||
{
|
{
|
||||||
ptr_op_t node(parse_unary_expr(in, tflags));
|
ptr_op_t node(parse_unary_expr(in, tflags));
|
||||||
|
|
||||||
if (node) {
|
if (node && ! (tflags & EXPR_PARSE_SINGLE)) {
|
||||||
token_t& tok = next_token(in, tflags);
|
token_t& tok = next_token(in, tflags);
|
||||||
|
|
||||||
if (tok.kind == token_t::STAR || tok.kind == token_t::KW_DIV) {
|
if (tok.kind == token_t::STAR || tok.kind == token_t::KW_DIV) {
|
||||||
|
|
@ -187,7 +185,7 @@ expr_t::parser_t::parse_add_expr(std::istream& in,
|
||||||
{
|
{
|
||||||
ptr_op_t node(parse_mul_expr(in, tflags));
|
ptr_op_t node(parse_mul_expr(in, tflags));
|
||||||
|
|
||||||
if (node) {
|
if (node && ! (tflags & EXPR_PARSE_SINGLE)) {
|
||||||
token_t& tok = next_token(in, tflags);
|
token_t& tok = next_token(in, tflags);
|
||||||
|
|
||||||
if (tok.kind == token_t::PLUS ||
|
if (tok.kind == token_t::PLUS ||
|
||||||
|
|
@ -215,7 +213,7 @@ expr_t::parser_t::parse_logic_expr(std::istream& in,
|
||||||
{
|
{
|
||||||
ptr_op_t node(parse_add_expr(in, tflags));
|
ptr_op_t node(parse_add_expr(in, tflags));
|
||||||
|
|
||||||
if (node) {
|
if (node && ! (tflags & EXPR_PARSE_SINGLE)) {
|
||||||
op_t::kind_t kind = op_t::LAST;
|
op_t::kind_t kind = op_t::LAST;
|
||||||
flags_t _flags = tflags;
|
flags_t _flags = tflags;
|
||||||
token_t& tok = next_token(in, tflags);
|
token_t& tok = next_token(in, tflags);
|
||||||
|
|
@ -271,7 +269,7 @@ expr_t::parser_t::parse_and_expr(std::istream& in,
|
||||||
{
|
{
|
||||||
ptr_op_t node(parse_logic_expr(in, tflags));
|
ptr_op_t node(parse_logic_expr(in, tflags));
|
||||||
|
|
||||||
if (node) {
|
if (node && ! (tflags & EXPR_PARSE_SINGLE)) {
|
||||||
token_t& tok = next_token(in, tflags);
|
token_t& tok = next_token(in, tflags);
|
||||||
|
|
||||||
if (tok.kind == token_t::KW_AND) {
|
if (tok.kind == token_t::KW_AND) {
|
||||||
|
|
@ -295,7 +293,7 @@ expr_t::parser_t::parse_or_expr(std::istream& in,
|
||||||
{
|
{
|
||||||
ptr_op_t node(parse_and_expr(in, tflags));
|
ptr_op_t node(parse_and_expr(in, tflags));
|
||||||
|
|
||||||
if (node) {
|
if (node && ! (tflags & EXPR_PARSE_SINGLE)) {
|
||||||
token_t& tok = next_token(in, tflags);
|
token_t& tok = next_token(in, tflags);
|
||||||
|
|
||||||
if (tok.kind == token_t::KW_OR) {
|
if (tok.kind == token_t::KW_OR) {
|
||||||
|
|
@ -319,7 +317,7 @@ expr_t::parser_t::parse_querycolon_expr(std::istream& in,
|
||||||
{
|
{
|
||||||
ptr_op_t node(parse_or_expr(in, tflags));
|
ptr_op_t node(parse_or_expr(in, tflags));
|
||||||
|
|
||||||
if (node) {
|
if (node && ! (tflags & EXPR_PARSE_SINGLE)) {
|
||||||
token_t& tok = next_token(in, tflags);
|
token_t& tok = next_token(in, tflags);
|
||||||
|
|
||||||
if (tok.kind == token_t::QUERY) {
|
if (tok.kind == token_t::QUERY) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue