diff options
author | Håvard Pettersen <havardpe@oath.com> | 2019-04-08 10:23:53 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@oath.com> | 2019-04-08 10:23:53 +0000 |
commit | b84078e4bcb7bad171f42d40b7ee5337ded3ed35 (patch) | |
tree | 9b2ffc6a32fbf29a2b3e257f90cf80c34bd84adf /eval/src | |
parent | 26ea003c227e65b929e80b9ac412ca7d7c2a5404 (diff) |
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'
Diffstat (limited to 'eval/src')
-rw-r--r-- | eval/src/vespa/eval/eval/value_type_spec.cpp | 30 |
1 files changed, 24 insertions, 6 deletions
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<ValueType::Dimension> 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; } |