Changeset View
Changeset View
Standalone View
Standalone View
clang-tools-extra/clangd/ConfigYAML.cpp
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | public: | ||||
bool parse(Fragment &F, Node &N) { | bool parse(Fragment &F, Node &N) { | ||||
DictParser Dict("Config", this); | DictParser Dict("Config", this); | ||||
Dict.handle("If", [&](Node &N) { parse(F.If, N); }); | Dict.handle("If", [&](Node &N) { parse(F.If, N); }); | ||||
Dict.handle("CompileFlags", [&](Node &N) { parse(F.CompileFlags, N); }); | Dict.handle("CompileFlags", [&](Node &N) { parse(F.CompileFlags, N); }); | ||||
Dict.handle("Index", [&](Node &N) { parse(F.Index, N); }); | Dict.handle("Index", [&](Node &N) { parse(F.Index, N); }); | ||||
Dict.handle("Style", [&](Node &N) { parse(F.Style, N); }); | Dict.handle("Style", [&](Node &N) { parse(F.Style, N); }); | ||||
Dict.handle("Diagnostics", [&](Node &N) { parse(F.Diagnostics, N); }); | Dict.handle("Diagnostics", [&](Node &N) { parse(F.Diagnostics, N); }); | ||||
Dict.handle("Completion", [&](Node &N) { parse(F.Completion, N); }); | Dict.handle("Completion", [&](Node &N) { parse(F.Completion, N); }); | ||||
Dict.handle("Hover", [&](Node &N) { parse(F.Hover, N); }); | |||||
Dict.parse(N); | Dict.parse(N); | ||||
return !(N.failed() || HadError); | return !(N.failed() || HadError); | ||||
} | } | ||||
private: | private: | ||||
void parse(Fragment::IfBlock &F, Node &N) { | void parse(Fragment::IfBlock &F, Node &N) { | ||||
DictParser Dict("If", this); | DictParser Dict("If", this); | ||||
Dict.unrecognized([&](Located<std::string>, Node &) { | Dict.unrecognized([&](Located<std::string>, Node &) { | ||||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | Dict.handle("AllScopes", [&](Node &N) { | ||||
F.AllScopes = *AllScopes; | F.AllScopes = *AllScopes; | ||||
else | else | ||||
warning("AllScopes should be a boolean", N); | warning("AllScopes should be a boolean", N); | ||||
} | } | ||||
}); | }); | ||||
Dict.parse(N); | Dict.parse(N); | ||||
} | } | ||||
void parse(Fragment::HoverBlock &F, Node &N) { | |||||
DictParser Dict("Hover", this); | |||||
Dict.handle("AKAPrint", [&](Node &N) { | |||||
if (auto Value = scalarValue(N, "AKAPrint")) { | |||||
if (auto AKAPrint = llvm::yaml::parseBool(**Value)) | |||||
F.AKAPrint = *AKAPrint; | |||||
else | |||||
warning("AKAPrint should be a boolean", N); | |||||
} | |||||
}); | |||||
Dict.parse(N); | |||||
} | |||||
// Helper for parsing mapping nodes (dictionaries). | // Helper for parsing mapping nodes (dictionaries). | ||||
// We don't use YamlIO as we want to control over unknown keys. | // We don't use YamlIO as we want to control over unknown keys. | ||||
class DictParser { | class DictParser { | ||||
llvm::StringRef Description; | llvm::StringRef Description; | ||||
std::vector<std::pair<llvm::StringRef, std::function<void(Node &)>>> Keys; | std::vector<std::pair<llvm::StringRef, std::function<void(Node &)>>> Keys; | ||||
std::function<bool(Located<std::string>, Node &)> UnknownHandler; | std::function<bool(Located<std::string>, Node &)> UnknownHandler; | ||||
Parser *Outer; | Parser *Outer; | ||||
▲ Show 20 Lines • Show All 181 Lines • Show Last 20 Lines |