| 14 | } |
| 15 | |
| 16 | class cmJSONState |
| 17 | { |
| 18 | using Location = struct |
| 19 | { |
| 20 | int line; |
| 21 | int column; |
| 22 | }; |
| 23 | |
| 24 | public: |
| 25 | using JsonPair = std::pair<std::string const, Json::Value const*>; |
| 26 | cmJSONState() = default; |
| 27 | cmJSONState(std::string jsonFile, Json::Value* root); |
| 28 | void AddError(std::string const& errMsg); |
| 29 | void AddErrorAtValue(std::string const& errMsg, Json::Value const* value); |
| 30 | void AddErrorAtOffset(std::string const& errMsg, std::ptrdiff_t offset); |
| 31 | std::string GetErrorMessage(bool showContext = true); |
| 32 | std::string key(); |
| 33 | std::string key_after(std::string const& key); |
| 34 | Json::Value const* value_after(std::string const& key); |
| 35 | void push_stack(std::string const& key, Json::Value const* value); |
| 36 | void pop_stack(); |
| 37 | |
| 38 | class Error |
| 39 | { |
| 40 | public: |
| 41 | Error(Location loc, std::string errMsg) |
| 42 | : location(loc) |
| 43 | , message(std::move(errMsg)) {}; |
| 44 | Error(std::string errMsg) |
| 45 | : location({ -1, -1 }) |
| 46 | , message(std::move(errMsg)) {}; |
| 47 | std::string GetErrorMessage() const { return message; } |
| 48 | Location GetLocation() const { return location; } |
| 49 | |
| 50 | private: |
| 51 | Location location; |
| 52 | std::string message; |
| 53 | }; |
| 54 | |
| 55 | std::vector<JsonPair> parseStack; |
| 56 | std::vector<Error> errors; |
| 57 | std::string doc; |
| 58 | bool allowComments = false; |
| 59 | |
| 60 | private: |
| 61 | std::string GetJsonContext(Location loc); |
| 62 | Location LocateInDocument(ptrdiff_t offset); |
| 63 | std::string Filename; |
| 64 | }; |
no outgoing calls
searching dependent graphs…