| 140 | } |
| 141 | |
| 142 | void Instance::Consume(cm::string_view arg) |
| 143 | { |
| 144 | ParserState& state = this->GetState(); |
| 145 | |
| 146 | auto const it = state.Bindings.Keywords.Find(arg); |
| 147 | if (it != state.Bindings.Keywords.end()) { |
| 148 | this->FinishKeyword(); |
| 149 | state.Keyword = it->first; |
| 150 | state.KeywordValuesSeen = 0; |
| 151 | state.DoneWithPositional = true; |
| 152 | if (state.Bindings.ParsedKeyword) { |
| 153 | state.Bindings.ParsedKeyword(*this, it->first); |
| 154 | } |
| 155 | it->second(*this); |
| 156 | return; |
| 157 | } |
| 158 | |
| 159 | if (!state.DoneWithPositional) { |
| 160 | auto const pit = state.Bindings.Positions.Find(state.Pos); |
| 161 | if (pit != state.Bindings.Positions.end()) { |
| 162 | pit->second(*this, state.Pos, arg); |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | if (state.Bindings.TrailingArgs) { |
| 167 | state.Keyword = ""_s; |
| 168 | state.KeywordValuesSeen = 0; |
| 169 | state.DoneWithPositional = true; |
| 170 | state.Bindings.TrailingArgs(*this); |
| 171 | if (!state.KeywordValueFunc) { |
| 172 | return; |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | if (state.KeywordValueFunc) { |
| 178 | switch (state.KeywordValueFunc(arg)) { |
| 179 | case Continue::Yes: |
| 180 | break; |
| 181 | case Continue::No: |
| 182 | state.KeywordValueFunc = nullptr; |
| 183 | break; |
| 184 | } |
| 185 | ++state.KeywordValuesSeen; |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | if (this->UnparsedArguments) { |
| 190 | this->UnparsedArguments->emplace_back(arg); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | void Instance::FinishKeyword() |
| 195 | { |
no test coverage detected