@@ -14,22 +14,12 @@ bool SymRule::match(std::string_view s) const {
1414 return RE2::FullMatch (s, *m_RE);
1515}
1616
17- bool SymDefs::parse (const std::filesystem::path& path) {
18- const auto fileName = path.filename ().string ();
17+ bool SymDefs::parseObject (std::string_view fileName, std::string_view content) {
1918 std::unordered_set<std::string> ruleNames;
2019 std::vector<SymRule> rules;
2120
22- // Read json.
23- std::ifstream f (path);
24- if (!f.is_open ()) {
25- resgen::printError (PrintFileInfo {
26- .fileName = fileName,
27- .boldText = true ,
28- }, " could not open file" );
29- return false ;
30- }
31-
32- const auto jsonData = nlohmann::json::parse (f, nullptr , false );
21+ // Parse json.
22+ const auto jsonData = nlohmann::json::parse (content, nullptr , false );
3323 if (!jsonData.is_object ()) {
3424 resgen::printError ( PrintFileInfo {
3525 .fileName = fileName,
@@ -79,6 +69,19 @@ bool SymDefs::parse(const std::filesystem::path& path) {
7969 name = value[" name" ].get <std::string>();
8070 }
8171
72+ if (value.contains (" weak" )) {
73+ if (!value[" weak" ].is_boolean ()) {
74+ resgen::printError ( PrintFileInfo {
75+ .fileName = fileName,
76+ .boldText = true ,
77+ }, " expected bool for \" weak\" of rule \" {}\" " , rule);
78+ return false ;
79+ }
80+
81+ if (value[" weak" ].get <bool >())
82+ flags |= SymRule::FLAG_WEAK;
83+ }
84+
8285 if (value.contains (" exclude" )) {
8386 if (!value[" exclude" ].is_boolean ()) {
8487 resgen::printError ( PrintFileInfo {
@@ -125,6 +128,22 @@ bool SymDefs::parse(const std::filesystem::path& path) {
125128 return true ;
126129}
127130
131+ bool SymDefs::parseFile (const std::filesystem::path& path) {
132+ const auto fileName = path.filename ().string ();
133+
134+ std::ifstream f (path);
135+ if (!f.is_open ()) {
136+ resgen::printError (PrintFileInfo {
137+ .fileName = fileName,
138+ .boldText = true ,
139+ }, " could not open file" );
140+ return false ;
141+ }
142+
143+ const std::string content ((std::istreambuf_iterator<char >(f)), std::istreambuf_iterator<char >());
144+ return parseObject (fileName, content);
145+ }
146+
128147static std::size_t checkSym (std::string_view s) {
129148 for (auto i = 0u ; i < s.size (); ++i) {
130149 if (s[i] <= ' \x20 ' || s[i] >= ' \x7F ' )
@@ -170,7 +189,7 @@ static bool parseList(const std::filesystem::path& path, SymList& out) {
170189
171190 // Check for duplicates.
172191 auto tmpIt = syms.find (tmp);
173- auto otherIt = out.find (tmp);
192+ auto otherIt = out.find (SymEntry{ tmp, false } );
174193
175194 if ((tmpIt != syms.end ()) || (otherIt != out.end ())) {
176195 resgen::printWarning (PrintFileInfo {
@@ -193,7 +212,7 @@ static bool parseList(const std::filesystem::path& path, SymList& out) {
193212 auto it = syms.begin ();
194213 while (it != syms.end ()) {
195214 auto node = syms.extract (it);
196- out.insert (node.key ());
215+ out.insert ({ node.key (), false } );
197216 it = syms.begin ();
198217 }
199218
0 commit comments