| 137 | } |
| 138 | |
| 139 | void ConfigWriter::EmitIdentifier(std::ostream& fp, const String& identifier, bool inAssignment) |
| 140 | { |
| 141 | static std::set<String> keywords; |
| 142 | static std::mutex mutex; |
| 143 | |
| 144 | { |
| 145 | std::unique_lock<std::mutex> lock(mutex); |
| 146 | if (keywords.empty()) { |
| 147 | const std::vector<String>& vkeywords = GetKeywords(); |
| 148 | std::copy(vkeywords.begin(), vkeywords.end(), std::inserter(keywords, keywords.begin())); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | if (keywords.find(identifier) != keywords.end()) { |
| 153 | fp << "@" << identifier; |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | boost::regex expr("^[a-zA-Z_][a-zA-Z0-9\\_]*$"); |
| 158 | boost::smatch what; |
| 159 | if (boost::regex_search(identifier.GetData(), what, expr)) |
| 160 | fp << identifier; |
| 161 | else if (inAssignment) |
| 162 | EmitString(fp, identifier); |
| 163 | else |
| 164 | BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid identifier")); |
| 165 | } |
| 166 | |
| 167 | void ConfigWriter::EmitConfigItem(std::ostream& fp, const String& type, const String& name, bool isTemplate, |
| 168 | bool ignoreOnError, const Array::Ptr& imports, const Dictionary::Ptr& attrs) |