Get description of what the grammar expects at current position
| 217 | |
| 218 | // Get description of what the grammar expects at current position |
| 219 | static std::string get_expected_description(const llama_grammar_rules & rules, const llama_grammar_stacks & stacks) { |
| 220 | if (stacks.empty()) { |
| 221 | return "<no valid continuations>"; |
| 222 | } |
| 223 | |
| 224 | std::string result; |
| 225 | std::set<std::string> seen; |
| 226 | |
| 227 | for (const auto & stack : stacks) { |
| 228 | if (stack.empty()) { |
| 229 | if (seen.insert("<end>").second) { |
| 230 | if (!result.empty()) { |
| 231 | result += " OR "; |
| 232 | } |
| 233 | result += "<end>"; |
| 234 | } |
| 235 | continue; |
| 236 | } |
| 237 | |
| 238 | const llama_grammar_element * elem = stack.back(); |
| 239 | std::string desc = format_expected_element(rules, elem); |
| 240 | if (seen.insert(desc).second) { |
| 241 | if (!result.empty()) { |
| 242 | result += " OR "; |
| 243 | } |
| 244 | result += desc; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | return result; |
| 249 | } |
| 250 | |
| 251 | // Result of a detailed grammar match attempt |
| 252 | struct grammar_match_result { |
no test coverage detected