MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / deserialize_parser_variant

Function deserialize_parser_variant

common/peg-parser.cpp:1922–2079  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1920}
1921
1922static common_peg_parser_variant deserialize_parser_variant(const nlohmann::json & j) {
1923 if (!j.contains("type") || !j["type"].is_string()) {
1924 throw std::runtime_error("Parser variant JSON missing or invalid 'type' field");
1925 }
1926
1927 std::string type = j["type"];
1928
1929 if (type == "epsilon") {
1930 return common_peg_epsilon_parser{};
1931 }
1932 if (type == "start") {
1933 return common_peg_start_parser{};
1934 }
1935 if (type == "end") {
1936 return common_peg_end_parser{};
1937 }
1938 if (type == "literal") {
1939 if (!j.contains("literal") || !j["literal"].is_string()) {
1940 throw std::runtime_error("literal parser missing or invalid 'literal' field");
1941 }
1942 return common_peg_literal_parser{j["literal"]};
1943 }
1944 if (type == "sequence") {
1945 if (!j.contains("children") || !j["children"].is_array()) {
1946 throw std::runtime_error("sequence parser missing or invalid 'children' field");
1947 }
1948 return common_peg_sequence_parser{j["children"].get<std::vector<common_peg_parser_id>>()};
1949 }
1950 if (type == "choice") {
1951 if (!j.contains("children") || !j["children"].is_array()) {
1952 throw std::runtime_error("choice parser missing or invalid 'children' field");
1953 }
1954 return common_peg_choice_parser{j["children"].get<std::vector<common_peg_parser_id>>()};
1955 }
1956 if (type == "repetition") {
1957 if (!j.contains("child") || !j.contains("min_count") || !j.contains("max_count")) {
1958 throw std::runtime_error("repetition parser missing required fields");
1959 }
1960 return common_peg_repetition_parser{
1961 j["child"].get<common_peg_parser_id>(),
1962 j["min_count"].get<int>(),
1963 j["max_count"].get<int>()
1964 };
1965 }
1966 if (type == "and") {
1967 if (!j.contains("child")) {
1968 throw std::runtime_error("and parser missing 'child' field");
1969 }
1970 return common_peg_and_parser{j["child"].get<common_peg_parser_id>()};
1971 }
1972 if (type == "not") {
1973 if (!j.contains("child")) {
1974 throw std::runtime_error("not parser missing 'child' field");
1975 }
1976 return common_peg_not_parser{j["child"].get<common_peg_parser_id>()};
1977 }
1978 if (type == "any") {
1979 return common_peg_any_parser{};

Callers 1

from_jsonMethod · 0.85

Calls 3

containsMethod · 0.80
push_backMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected