| 110 | |
| 111 | template <typename T, typename... CallState> |
| 112 | bool parse(std::string const& input, T& index, |
| 113 | std::vector<std::string> const& allArgs, |
| 114 | CallState&&... state) const |
| 115 | { |
| 116 | ParseMode parseState = ParseMode::Valid; |
| 117 | |
| 118 | if (this->Type == Values::Zero) { |
| 119 | if (input.size() == this->Name.size()) { |
| 120 | parseState = |
| 121 | this->StoreCall(std::string{}, std::forward<CallState>(state)...) |
| 122 | ? ParseMode::Valid |
| 123 | : ParseMode::Invalid; |
| 124 | } else { |
| 125 | parseState = ParseMode::SyntaxError; |
| 126 | } |
| 127 | |
| 128 | } else if (this->Type == Values::One || this->Type == Values::ZeroOrOne) { |
| 129 | if (input.size() == this->Name.size()) { |
| 130 | auto nextValueIndex = index + 1; |
| 131 | if (nextValueIndex >= allArgs.size() || |
| 132 | IsFlag(allArgs[nextValueIndex])) { |
| 133 | if (this->Type == Values::ZeroOrOne) { |
| 134 | parseState = |
| 135 | this->StoreCall(std::string{}, std::forward<CallState>(state)...) |
| 136 | ? ParseMode::Valid |
| 137 | : ParseMode::Invalid; |
| 138 | } else { |
| 139 | parseState = ParseMode::ValueError; |
| 140 | } |
| 141 | } else { |
| 142 | parseState = this->StoreCall(allArgs[nextValueIndex], |
| 143 | std::forward<CallState>(state)...) |
| 144 | ? ParseMode::Valid |
| 145 | : ParseMode::Invalid; |
| 146 | index = nextValueIndex; |
| 147 | } |
| 148 | } else { |
| 149 | auto value = this->extract_single_value(input, parseState); |
| 150 | if (parseState == ParseMode::Valid) { |
| 151 | parseState = |
| 152 | this->StoreCall(value, std::forward<CallState>(state)...) |
| 153 | ? ParseMode::Valid |
| 154 | : ParseMode::Invalid; |
| 155 | } |
| 156 | } |
| 157 | } else if (this->Type == Values::Two) { |
| 158 | if (input.size() == this->Name.size()) { |
| 159 | if (index + 2 >= allArgs.size() || IsFlag(allArgs[index + 1]) || |
| 160 | IsFlag(allArgs[index + 2])) { |
| 161 | parseState = ParseMode::ValueError; |
| 162 | } else { |
| 163 | index += 2; |
| 164 | parseState = |
| 165 | this->StoreCall(cmStrCat(allArgs[index - 1], ";", allArgs[index]), |
| 166 | std::forward<CallState>(state)...) |
| 167 | ? ParseMode::Valid |
| 168 | : ParseMode::Invalid; |
| 169 | } |