From b84078e4bcb7bad171f42d40b7ee5337ded3ed35 Mon Sep 17 00:00:00 2001 From: HÃ¥vard Pettersen Date: Mon, 8 Apr 2019 10:23:53 +0000 Subject: Improve handling of malformed cell type specifiers Do not consume any input when encountering a malformed cell type specifier. This avoids parse conflicts between 'less' operators and tensor cell type specifiers in type expressions in the type resolution test which parses partial input into value types. example expression: 'tensor < double' --- eval/src/vespa/eval/eval/value_type_spec.cpp | 30 ++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'eval/src') diff --git a/eval/src/vespa/eval/eval/value_type_spec.cpp b/eval/src/vespa/eval/eval/value_type_spec.cpp index 9bd0e54882f..6076988ad50 100644 --- a/eval/src/vespa/eval/eval/value_type_spec.cpp +++ b/eval/src/vespa/eval/eval/value_type_spec.cpp @@ -12,6 +12,14 @@ namespace { class ParseContext { +public: + struct Mark { + const char *pos; + char curr; + bool failed; + Mark(const char *pos_in, char curr_in, bool failed_in) + : pos(pos_in), curr(curr_in), failed(failed_in) {} + }; private: const char *_pos; const char *_end; @@ -34,6 +42,14 @@ public: _pos_after = nullptr; } } + Mark mark() const { + return Mark(_pos, _curr, _failed); + } + void revert(Mark mark) { + _pos = mark.pos; + _curr = mark.curr; + _failed = mark.failed; + } void fail() { _failed = true; _curr = 0; @@ -131,13 +147,15 @@ std::vector parse_dimension_list(ParseContext &ctx) { } vespalib::string parse_cell_type(ParseContext &ctx) { - vespalib::string cell_type = "double"; + auto mark = ctx.mark(); ctx.skip_spaces(); - if (ctx.get() == '<') { - ctx.eat('<'); - cell_type = parse_ident(ctx); - ctx.skip_spaces(); - ctx.eat('>'); + ctx.eat('<'); + auto cell_type = parse_ident(ctx); + ctx.skip_spaces(); + ctx.eat('>'); + if (ctx.failed()) { + ctx.revert(mark); + cell_type = "double"; } return cell_type; } -- cgit v1.2.3