diff options
author | John Wiegley <johnw@newartisans.com> | 2010-09-05 01:38:47 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-09-05 01:38:47 -0400 |
commit | e162455ebb545ea33580e58f52ebe424ef9e68fa (patch) | |
tree | df9c98fb39f31b9003db07d7806815bf71031a2d /src/parser.cc | |
parent | 9fcf48482626f20151d75a2ebb81371b45d4540a (diff) | |
download | fork-ledger-e162455ebb545ea33580e58f52ebe424ef9e68fa.tar.gz fork-ledger-e162455ebb545ea33580e58f52ebe424ef9e68fa.tar.bz2 fork-ledger-e162455ebb545ea33580e58f52ebe424ef9e68fa.zip |
Minor simplifications to valexpr parser
The most significant change is the way CONS sequences are parsed, and
that now instead of =/:=, the operators are ==/=.
Diffstat (limited to 'src/parser.cc')
-rw-r--r-- | src/parser.cc | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/src/parser.cc b/src/parser.cc index 9a1ebf6f..a5b1e6e3 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -65,9 +65,6 @@ expr_t::parser_t::parse_value_term(std::istream& in, push_token(tok); // let the parser see it again node->set_right(parse_value_expr(in, tflags.plus_flags(PARSE_SINGLE))); - - if (node->has_right() && node->right()->kind == op_t::O_CONS) - node->set_right(node->right()->left()); } else { push_token(tok); } @@ -78,12 +75,6 @@ expr_t::parser_t::parse_value_term(std::istream& in, node = parse_value_expr(in, tflags.plus_flags(PARSE_PARTIAL) .minus_flags(PARSE_SINGLE)); tok = next_token(in, tflags, ')'); - - if (node && node->kind == op_t::O_CONS) { - ptr_op_t prev(node); - node = new op_t(op_t::O_SEQ); - node->set_left(prev); - } break; default: @@ -437,33 +428,37 @@ 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.plus_flags(PARSE_OP_CONTEXT)); + ptr_op_t next; + while (true) { + token_t& tok = next_token(in, tflags.plus_flags(PARSE_OP_CONTEXT)); - if (tok.kind == token_t::COMMA || tok.kind == token_t::SEMI) { - bool comma_op = tok.kind == token_t::COMMA; + if (tok.kind == token_t::COMMA || tok.kind == token_t::SEMI) { + bool comma_op = tok.kind == token_t::COMMA; - ptr_op_t prev(node); - node = new op_t(comma_op ? op_t::O_CONS : op_t::O_SEQ); - node->set_left(prev); - node->set_right(parse_value_expr(in, tflags)); - if (! node->right()) - throw_(parse_error, - _("%1 operator not followed by argument") << tok.symbol); + if (! next) { + ptr_op_t prev(node); + node = new op_t(comma_op ? op_t::O_CONS : op_t::O_SEQ); + node->set_left(prev); - tok = next_token(in, tflags.plus_flags(PARSE_OP_CONTEXT)); - } + next = node; + } + + token_t& ntok = next_token(in, tflags); + push_token(ntok); + if (ntok.kind == token_t::RPAREN) + break; - if (tok.kind != token_t::TOK_EOF) { - if (tflags.has_flags(PARSE_PARTIAL)) + ptr_op_t chain(new op_t(comma_op ? op_t::O_CONS : op_t::O_SEQ)); + chain->set_left(parse_querycolon_expr(in, tflags)); + + next->set_right(chain); + next = chain; + } else { push_token(tok); - else - tok.unexpected(); + break; + } } } - else if (! tflags.has_flags(PARSE_PARTIAL) && - ! tflags.has_flags(PARSE_SINGLE)) { - throw_(parse_error, _("Failed to parse value expression")); - } return node; } |