From aceee75ed943b284fd905c7c522566fb314431e4 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 27 Feb 2014 06:41:58 +0000 Subject: [PATCH] Tolerate invalid %...{} when completing --- src/command_manager.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/command_manager.cc b/src/command_manager.cc index 377089e3..0f0b700c 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -137,6 +137,7 @@ String get_until_delimiter(const String& base, ByteCount& pos, return base.substr(start, pos - start); } +template Token::Type token_type(const String& type_name) { if (type_name == "") @@ -147,8 +148,10 @@ Token::Type token_type(const String& type_name) return Token::Type::RegisterExpand; else if (type_name == "opt") return Token::Type::OptionExpand; - else + else if (throw_on_invalid) throw unknown_expand{type_name}; + else + return Token::Type::Raw; } void skip_blanks_and_comments(const String& base, ByteCount& pos) @@ -204,7 +207,7 @@ TokenList parse(const String& line) if (throw_on_unterminated and pos == length) throw parse_error{"expected a string delimiter after '%" + type_name + "'"}; - Token::Type type = token_type(type_name); + Token::Type type = token_type(type_name); static const std::unordered_map matching_delimiters = { { '(', ')' }, { '[', ']' }, { '{', '}' }, { '<', '>' } };