From 96c97181443d3e6cd14a3802448de6a9c7974960 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 29 Jun 2018 08:36:06 +1000 Subject: [PATCH] Parse unknown switches as positional for region highlighters --- rc/base/haskell.kak | 2 +- rc/base/lua.kak | 4 ++-- src/highlighters.cc | 3 ++- src/parameters_parser.cc | 19 +++++++++++++++---- src/parameters_parser.hh | 5 +++-- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/rc/base/haskell.kak b/rc/base/haskell.kak index 80b7e20d..1fec8da6 100644 --- a/rc/base/haskell.kak +++ b/rc/base/haskell.kak @@ -17,7 +17,7 @@ add-highlighter shared/haskell/string region (??@\\\^|~=]|$) $ '' fill comment +add-highlighter shared/haskell/line_comment region --(?:[^!#$%&*+./<>?@\\\^|~=]|$) $ '' fill comment add-highlighter shared/haskell/code/ regex (? switch_seen(desc.switches.size(), false); for (size_t i = 0; i < params.size(); ++i) { - if (not only_pos and params[i] == "--") + if (not only_pos and not ignore_unknown_switches and params[i] == "--") only_pos = true; else if (not only_pos and not params[i].empty() and params[i][0_byte] == '-') { auto it = m_desc.switches.find(params[i].substr(1_byte)); if (it == m_desc.switches.end()) + { + if (ignore_unknown_switches) + { + m_positional_indices.push_back(i); + if (switches_only_at_start) + only_pos = true; + continue; + } throw unknown_option(params[i]); + } auto switch_index = it - m_desc.switches.begin(); if (switch_seen[switch_index]) @@ -52,7 +63,7 @@ ParametersParser::ParametersParser(ParameterList params, } else // positional { - if (desc.flags & ParameterDesc::Flags::SwitchesOnlyAtStart) + if (switches_only_at_start) only_pos = true; m_positional_indices.push_back(i); } diff --git a/src/parameters_parser.hh b/src/parameters_parser.hh index e30fbabf..01da6ade 100644 --- a/src/parameters_parser.hh +++ b/src/parameters_parser.hh @@ -52,8 +52,9 @@ struct ParameterDesc enum class Flags { None = 0, - SwitchesOnlyAtStart = 1, - SwitchesAsPositional = 2, + SwitchesOnlyAtStart = 0b0001, + SwitchesAsPositional = 0b0010, + IgnoreUnknownSwitches = 0b0100 }; friend constexpr bool with_bit_ops(Meta::Type) { return true; }