Commit a5d43998 by Maarten L. Hekkelman

replace tag with item or item_name

parent 2792caec
...@@ -957,32 +957,32 @@ class category ...@@ -957,32 +957,32 @@ class category
{ return prefix + std::to_string(nr + 1); }); { return prefix + std::to_string(nr + 1); });
} }
/// @brief Generate a new, unique value for a item named @a tag /// @brief Generate a new, unique value for a item named @a item_name
/// @param tag The name of the item /// @param item_name The name of the item
/// @return a new unique value /// @return a new unique value
std::string get_unique_value(std::string_view tag); std::string get_unique_value(std::string_view item_name);
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/// \brief Update a single item named @a tag in the rows that match \a cond to value \a value /// \brief Update a single item named @a item_name in the rows that match \a cond to value \a value
/// making sure the linked categories are updated according to the link. /// making sure the linked categories are updated according to the link.
/// That means, child categories are updated if the links are absolute /// That means, child categories are updated if the links are absolute
/// and unique. If they are not, the child category rows are split. /// and unique. If they are not, the child category rows are split.
void update_value(condition &&cond, std::string_view tag, std::string_view value) void update_value(condition &&cond, std::string_view item_name, std::string_view value)
{ {
auto rs = find(std::move(cond)); auto rs = find(std::move(cond));
std::vector<row_handle> rows; std::vector<row_handle> rows;
std::copy(rs.begin(), rs.end(), std::back_inserter(rows)); std::copy(rs.begin(), rs.end(), std::back_inserter(rows));
update_value(rows, tag, value); update_value(rows, item_name, value);
} }
/// \brief Update a single item named @a tag in @a rows to value \a value /// \brief Update a single item named @a item_name in @a rows to value \a value
/// making sure the linked categories are updated according to the link. /// making sure the linked categories are updated according to the link.
/// That means, child categories are updated if the links are absolute /// That means, child categories are updated if the links are absolute
/// and unique. If they are not, the child category rows are split. /// and unique. If they are not, the child category rows are split.
void update_value(const std::vector<row_handle> &rows, std::string_view tag, std::string_view value); void update_value(const std::vector<row_handle> &rows, std::string_view item_name, std::string_view value);
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Naming used to be very inconsistent. For backward compatibility, // Naming used to be very inconsistent. For backward compatibility,
...@@ -1140,7 +1140,15 @@ class category ...@@ -1140,7 +1140,15 @@ class category
/// This function returns effectively the list of fully qualified item /// This function returns effectively the list of fully qualified item
/// names, that is category_name + '.' + item_name for each item /// names, that is category_name + '.' + item_name for each item
std::vector<std::string> get_tag_order() const; [[deprecated("use get_item_order instead")]]
std::vector<std::string> get_tag_order() const
{
return get_item_order();
}
/// This function returns effectively the list of fully qualified item
/// names, that is category_name + '.' + item_name for each item
std::vector<std::string> get_item_order() const;
/// Write the contents of the category to the std::ostream @a os /// Write the contents of the category to the std::ostream @a os
void write(std::ostream &os) const; void write(std::ostream &os) const;
......
...@@ -169,7 +169,16 @@ class datablock : public std::list<category> ...@@ -169,7 +169,16 @@ class datablock : public std::list<category>
/** /**
* @brief Get the preferred order of the categories when writing them * @brief Get the preferred order of the categories when writing them
*/ */
std::vector<std::string> get_tag_order() const; [[deprecated("use get_item_order instead")]]
std::vector<std::string> get_tag_order() const
{
return get_item_order();
}
/**
* @brief Get the preferred order of the categories when writing them
*/
std::vector<std::string> get_item_order() const;
/** /**
* @brief Write out the contents to @a os * @brief Write out the contents to @a os
...@@ -177,9 +186,9 @@ class datablock : public std::list<category> ...@@ -177,9 +186,9 @@ class datablock : public std::list<category>
void write(std::ostream &os) const; void write(std::ostream &os) const;
/** /**
* @brief Write out the contents to @a os using the order defined in @a tag_order * @brief Write out the contents to @a os using the order defined in @a item_name_order
*/ */
void write(std::ostream &os, const std::vector<std::string> &tag_order); void write(std::ostream &os, const std::vector<std::string> &item_name_order);
/** /**
* @brief Friend operator<< to write datablock @a db to std::ostream @a os * @brief Friend operator<< to write datablock @a db to std::ostream @a os
......
...@@ -143,9 +143,9 @@ class sac_parser ...@@ -143,9 +143,9 @@ class sac_parser
enum class CIFToken enum class CIFToken
{ {
Unknown, UNKNOWN,
Eof, END_OF_FILE,
DATA, DATA,
LOOP, LOOP,
...@@ -153,24 +153,24 @@ class sac_parser ...@@ -153,24 +153,24 @@ class sac_parser
SAVE_, SAVE_,
SAVE_NAME, SAVE_NAME,
STOP, STOP,
Tag, ITEM_NAME,
Value VALUE
}; };
static constexpr const char *get_token_name(CIFToken token) static constexpr const char *get_token_name(CIFToken token)
{ {
switch (token) switch (token)
{ {
case CIFToken::Unknown: return "Unknown"; case CIFToken::UNKNOWN: return "Unknown";
case CIFToken::Eof: return "Eof"; case CIFToken::END_OF_FILE: return "Eof";
case CIFToken::DATA: return "DATA"; case CIFToken::DATA: return "DATA";
case CIFToken::LOOP: return "LOOP"; case CIFToken::LOOP: return "LOOP";
case CIFToken::GLOBAL: return "GLOBAL"; case CIFToken::GLOBAL: return "GLOBAL";
case CIFToken::SAVE_: return "SAVE"; case CIFToken::SAVE_: return "SAVE";
case CIFToken::SAVE_NAME: return "SAVE+name"; case CIFToken::SAVE_NAME: return "SAVE+name";
case CIFToken::STOP: return "STOP"; case CIFToken::STOP: return "STOP";
case CIFToken::Tag: return "Tag"; case CIFToken::ITEM_NAME: return "Tag";
case CIFToken::Value: return "Value"; case CIFToken::VALUE: return "Value";
default: return "Invalid token parameter"; default: return "Invalid token parameter";
} }
} }
...@@ -267,7 +267,7 @@ class sac_parser ...@@ -267,7 +267,7 @@ class sac_parser
QuotedString, QuotedString,
QuotedStringQuote, QuotedStringQuote,
UnquotedString, UnquotedString,
Tag, ItemName,
TextItem, TextItem,
TextItemNL, TextItemNL,
Reserved, Reserved,
......
...@@ -317,7 +317,7 @@ inline char tolower(int ch) ...@@ -317,7 +317,7 @@ inline char tolower(int ch)
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** \brief return a tuple consisting of the category and item name for @a tag /** \brief return a tuple consisting of the category and item name for @a item_name
* *
* The category name is stripped of its leading underscore character. * The category name is stripped of its leading underscore character.
* *
...@@ -325,7 +325,19 @@ inline char tolower(int ch) ...@@ -325,7 +325,19 @@ inline char tolower(int ch)
* cif 1.0 formatted data. * cif 1.0 formatted data.
*/ */
std::tuple<std::string, std::string> split_tag_name(std::string_view tag); [[deprecated("use split_item_name instead")]]
std::tuple<std::string, std::string> split_tag_name(std::string_view item_name);
/** \brief return a tuple consisting of the category and item name for @a item_name
*
* The category name is stripped of its leading underscore character.
*
* If no dot character was found, the category name is empty. That's for
* cif 1.0 formatted data.
*/
std::tuple<std::string, std::string> split_item_name(std::string_view item_name);
// -------------------------------------------------------------------- // --------------------------------------------------------------------
......
...@@ -266,7 +266,7 @@ struct item_alias ...@@ -266,7 +266,7 @@ struct item_alias
*/ */
struct item_validator struct item_validator
{ {
std::string m_tag; ///< The item name std::string m_item_name; ///< The item name
bool m_mandatory; ///< Flag indicating this item is mandatory bool m_mandatory; ///< Flag indicating this item is mandatory
const type_validator *m_type; ///< The type for this item const type_validator *m_type; ///< The type for this item
cif::iset m_enums; ///< If filled, the set of allowed values cif::iset m_enums; ///< If filled, the set of allowed values
...@@ -277,13 +277,13 @@ struct item_validator ...@@ -277,13 +277,13 @@ struct item_validator
/// @brief Compare based on the name /// @brief Compare based on the name
bool operator<(const item_validator &rhs) const bool operator<(const item_validator &rhs) const
{ {
return icompare(m_tag, rhs.m_tag) < 0; return icompare(m_item_name, rhs.m_item_name) < 0;
} }
/// @brief Compare based on the name /// @brief Compare based on the name
bool operator==(const item_validator &rhs) const bool operator==(const item_validator &rhs) const
{ {
return iequals(m_tag, rhs.m_tag); return iequals(m_item_name, rhs.m_item_name);
} }
/// @brief Validate the value in @a value for this item /// @brief Validate the value in @a value for this item
...@@ -317,11 +317,11 @@ struct category_validator ...@@ -317,11 +317,11 @@ struct category_validator
/// @brief Add item_validator @a v to the list of item validators /// @brief Add item_validator @a v to the list of item validators
void add_item_validator(item_validator &&v); void add_item_validator(item_validator &&v);
/// @brief Return the item_validator for item @a tag, may return nullptr /// @brief Return the item_validator for item @a item_name, may return nullptr
const item_validator *get_validator_for_item(std::string_view tag) const; const item_validator *get_validator_for_item(std::string_view item_name) const;
/// @brief Return the item_validator for an item that has as alias name @a tag, may return nullptr /// @brief Return the item_validator for an item that has as alias name @a item_name, may return nullptr
const item_validator *get_validator_for_aliased_item(std::string_view tag) const; const item_validator *get_validator_for_aliased_item(std::string_view item_name) const;
}; };
/** /**
......
...@@ -63,14 +63,14 @@ namespace detail ...@@ -63,14 +63,14 @@ namespace detail
condition_impl *key_equals_condition_impl::prepare(const category &c) condition_impl *key_equals_condition_impl::prepare(const category &c)
{ {
m_item_ix = c.get_item_ix(m_item_tag); m_item_ix = c.get_item_ix(m_item_name);
m_icase = is_item_type_uchar(c, m_item_tag); m_icase = is_item_type_uchar(c, m_item_name);
if (c.get_cat_validator() != nullptr and if (c.get_cat_validator() != nullptr and
c.key_item_indices().contains(m_item_ix) and c.key_item_indices().contains(m_item_ix) and
c.key_item_indices().size() == 1) c.key_item_indices().size() == 1)
{ {
m_single_hit = c[{ { m_item_tag, m_value } }]; m_single_hit = c[{ { m_item_name, m_value } }];
} }
return this; return this;
......
...@@ -159,7 +159,7 @@ std::tuple<datablock::iterator, bool> datablock::emplace(std::string_view name) ...@@ -159,7 +159,7 @@ std::tuple<datablock::iterator, bool> datablock::emplace(std::string_view name)
return std::make_tuple(i, is_new); return std::make_tuple(i, is_new);
} }
std::vector<std::string> datablock::get_tag_order() const std::vector<std::string> datablock::get_item_order() const
{ {
std::vector<std::string> result; std::vector<std::string> result;
...@@ -168,7 +168,7 @@ std::vector<std::string> datablock::get_tag_order() const ...@@ -168,7 +168,7 @@ std::vector<std::string> datablock::get_tag_order() const
{ return cat.name() == "entry"; }); { return cat.name() == "entry"; });
if (ci != end()) if (ci != end())
{ {
auto cto = ci->get_tag_order(); auto cto = ci->get_item_order();
result.insert(result.end(), cto.begin(), cto.end()); result.insert(result.end(), cto.begin(), cto.end());
} }
...@@ -176,7 +176,7 @@ std::vector<std::string> datablock::get_tag_order() const ...@@ -176,7 +176,7 @@ std::vector<std::string> datablock::get_tag_order() const
{ return cat.name() == "audit_conform"; }); { return cat.name() == "audit_conform"; });
if (ci != end()) if (ci != end())
{ {
auto cto = ci->get_tag_order(); auto cto = ci->get_item_order();
result.insert(result.end(), cto.begin(), cto.end()); result.insert(result.end(), cto.begin(), cto.end());
} }
...@@ -184,7 +184,7 @@ std::vector<std::string> datablock::get_tag_order() const ...@@ -184,7 +184,7 @@ std::vector<std::string> datablock::get_tag_order() const
{ {
if (cat.name() == "entry" or cat.name() == "audit_conform") if (cat.name() == "entry" or cat.name() == "audit_conform")
continue; continue;
auto cto = cat.get_tag_order(); auto cto = cat.get_item_order();
result.insert(result.end(), cto.begin(), cto.end()); result.insert(result.end(), cto.begin(), cto.end());
} }
...@@ -338,16 +338,16 @@ void datablock::write(std::ostream &os) const ...@@ -338,16 +338,16 @@ void datablock::write(std::ostream &os) const
} }
} }
void datablock::write(std::ostream &os, const std::vector<std::string> &tag_order) void datablock::write(std::ostream &os, const std::vector<std::string> &item_name_order)
{ {
os << "data_" << m_name << '\n' os << "data_" << m_name << '\n'
<< "# \n"; << "# \n";
std::vector<std::string> cat_order; std::vector<std::string> cat_order;
for (auto &o : tag_order) for (auto &o : item_name_order)
{ {
std::string cat_name, item_name; std::string cat_name, item_name;
std::tie(cat_name, item_name) = split_tag_name(o); std::tie(cat_name, item_name) = split_item_name(o);
if (find_if(cat_order.rbegin(), cat_order.rend(), [cat_name](const std::string &s) -> bool if (find_if(cat_order.rbegin(), cat_order.rend(), [cat_name](const std::string &s) -> bool
{ return iequals(cat_name, s); }) == cat_order.rend()) { return iequals(cat_name, s); }) == cat_order.rend())
cat_order.push_back(cat_name); cat_order.push_back(cat_name);
...@@ -360,10 +360,10 @@ void datablock::write(std::ostream &os, const std::vector<std::string> &tag_orde ...@@ -360,10 +360,10 @@ void datablock::write(std::ostream &os, const std::vector<std::string> &tag_orde
continue; continue;
std::vector<std::string> items; std::vector<std::string> items;
for (auto &o : tag_order) for (auto &o : item_name_order)
{ {
std::string cat_name, item_name; std::string cat_name, item_name;
std::tie(cat_name, item_name) = split_tag_name(o); std::tie(cat_name, item_name) = split_item_name(o);
if (cat_name == c) if (cat_name == c)
items.push_back(item_name); items.push_back(item_name);
......
...@@ -50,7 +50,7 @@ class dictionary_parser : public parser ...@@ -50,7 +50,7 @@ class dictionary_parser : public parser
try try
{ {
while (m_lookahead != CIFToken::Eof) while (m_lookahead != CIFToken::END_OF_FILE)
{ {
switch (m_lookahead) switch (m_lookahead)
{ {
...@@ -128,7 +128,7 @@ class dictionary_parser : public parser ...@@ -128,7 +128,7 @@ class dictionary_parser : public parser
datablock::iterator cat = dict.end(); datablock::iterator cat = dict.end();
match(CIFToken::SAVE_NAME); match(CIFToken::SAVE_NAME);
while (m_lookahead == CIFToken::LOOP or m_lookahead == CIFToken::Tag) while (m_lookahead == CIFToken::LOOP or m_lookahead == CIFToken::ITEM_NAME)
{ {
if (m_lookahead == CIFToken::LOOP) if (m_lookahead == CIFToken::LOOP)
{ {
...@@ -136,30 +136,30 @@ class dictionary_parser : public parser ...@@ -136,30 +136,30 @@ class dictionary_parser : public parser
match(CIFToken::LOOP); match(CIFToken::LOOP);
std::vector<std::string> tags; std::vector<std::string> item_names;
while (m_lookahead == CIFToken::Tag) while (m_lookahead == CIFToken::ITEM_NAME)
{ {
std::string catName, item_name; std::string catName, item_name;
std::tie(catName, item_name) = split_tag_name(m_token_value); std::tie(catName, item_name) = split_item_name(m_token_value);
if (cat == dict.end()) if (cat == dict.end())
std::tie(cat, std::ignore) = dict.emplace(catName); std::tie(cat, std::ignore) = dict.emplace(catName);
else if (not iequals(cat->name(), catName)) else if (not iequals(cat->name(), catName))
error("inconsistent categories in loop_"); error("inconsistent categories in loop_");
tags.push_back(item_name); item_names.push_back(item_name);
match(CIFToken::Tag); match(CIFToken::ITEM_NAME);
} }
while (m_lookahead == CIFToken::Value) while (m_lookahead == CIFToken::VALUE)
{ {
cat->emplace({}); cat->emplace({});
auto row = cat->back(); auto row = cat->back();
for (auto tag : tags) for (auto item_name : item_names)
{ {
row[tag] = m_token_value; row[item_name] = m_token_value;
match(CIFToken::Value); match(CIFToken::VALUE);
} }
} }
...@@ -168,18 +168,18 @@ class dictionary_parser : public parser ...@@ -168,18 +168,18 @@ class dictionary_parser : public parser
else else
{ {
std::string catName, item_name; std::string catName, item_name;
std::tie(catName, item_name) = split_tag_name(m_token_value); std::tie(catName, item_name) = split_item_name(m_token_value);
if (cat == dict.end() or not iequals(cat->name(), catName)) if (cat == dict.end() or not iequals(cat->name(), catName))
std::tie(cat, std::ignore) = dict.emplace(catName); std::tie(cat, std::ignore) = dict.emplace(catName);
match(CIFToken::Tag); match(CIFToken::ITEM_NAME);
if (cat->empty()) if (cat->empty())
cat->emplace({}); cat->emplace({});
cat->back()[item_name] = m_token_value; cat->back()[item_name] = m_token_value;
match(CIFToken::Value); match(CIFToken::VALUE);
} }
} }
...@@ -191,7 +191,7 @@ class dictionary_parser : public parser ...@@ -191,7 +191,7 @@ class dictionary_parser : public parser
std::vector<std::string> keys; std::vector<std::string> keys;
for (auto k : dict["category_key"]) for (auto k : dict["category_key"])
keys.push_back(std::get<1>(split_tag_name(k["name"].as<std::string>()))); keys.push_back(std::get<1>(split_item_name(k["name"].as<std::string>())));
iset groups; iset groups;
for (auto g : dict["category_group"]) for (auto g : dict["category_group"])
...@@ -234,17 +234,17 @@ class dictionary_parser : public parser ...@@ -234,17 +234,17 @@ class dictionary_parser : public parser
// collect the dict from our dataBlock and construct validators // collect the dict from our dataBlock and construct validators
for (auto i : dict["item"]) for (auto i : dict["item"])
{ {
std::string tagName, category, mandatory; std::string item, category, mandatory;
cif::tie(tagName, category, mandatory) = i.get("name", "category_id", "mandatory_code"); cif::tie(item, category, mandatory) = i.get("name", "category_id", "mandatory_code");
std::string cat_name, item_name; std::string cat_name, item_name;
std::tie(cat_name, item_name) = split_tag_name(tagName); std::tie(cat_name, item_name) = split_item_name(item);
if (cat_name.empty() or item_name.empty()) if (cat_name.empty() or item_name.empty())
error("Invalid tag name in _item.name " + tagName); error("Invalid item name in _item.name " + item);
if (not iequals(category, cat_name) and not(category.empty() or category == "?")) if (not iequals(category, cat_name) and not(category.empty() or category == "?"))
error("specified category id does match the implicit category name for tag '" + tagName + '\''); error("specified category id does match the implicit category name for item '" + item + '\'');
else else
category = cat_name; category = cat_name;
...@@ -260,22 +260,22 @@ class dictionary_parser : public parser ...@@ -260,22 +260,22 @@ class dictionary_parser : public parser
{ {
if (VERBOSE > 2) if (VERBOSE > 2)
{ {
std::cerr << "inconsistent mandatory value for " << tagName << " in dictionary\n"; std::cerr << "inconsistent mandatory value for " << item << " in dictionary\n";
if (iequals(tagName, saveFrameName)) if (iequals(item, saveFrameName))
std::cerr << "choosing " << mandatory << '\n'; std::cerr << "choosing " << mandatory << '\n';
else else
std::cerr << "choosing " << (vi->m_mandatory ? "Y" : "N") << '\n'; std::cerr << "choosing " << (vi->m_mandatory ? "Y" : "N") << '\n';
} }
if (iequals(tagName, saveFrameName)) if (iequals(item, saveFrameName))
vi->m_mandatory = (iequals(mandatory, "yes")); vi->m_mandatory = (iequals(mandatory, "yes"));
} }
if (vi->m_type != nullptr and tv != nullptr and vi->m_type != tv) if (vi->m_type != nullptr and tv != nullptr and vi->m_type != tv)
{ {
if (VERBOSE > 1) if (VERBOSE > 1)
std::cerr << "inconsistent type for " << tagName << " in dictionary\n"; std::cerr << "inconsistent type for " << item << " in dictionary\n";
} }
// vi->mMandatory = (iequals(mandatory, "yes")); // vi->mMandatory = (iequals(mandatory, "yes"));
...@@ -358,7 +358,7 @@ class dictionary_parser : public parser ...@@ -358,7 +358,7 @@ class dictionary_parser : public parser
} }
size_t ix = linkIndex.at(key); size_t ix = linkIndex.at(key);
addLink(ix, piv->m_tag, civ->m_tag); addLink(ix, piv->m_item_name, civ->m_item_name);
} }
// Only process inline linked items if the linked group list is absent // Only process inline linked items if the linked group list is absent
...@@ -386,7 +386,7 @@ class dictionary_parser : public parser ...@@ -386,7 +386,7 @@ class dictionary_parser : public parser
} }
size_t ix = linkIndex.at(key); size_t ix = linkIndex.at(key);
addLink(ix, piv->m_tag, civ->m_tag); addLink(ix, piv->m_item_name, civ->m_item_name);
} }
} }
...@@ -417,7 +417,7 @@ class dictionary_parser : public parser ...@@ -417,7 +417,7 @@ class dictionary_parser : public parser
for (auto &iv : cv.m_item_validators) for (auto &iv : cv.m_item_validators)
{ {
if (iv.m_type == nullptr and cif::VERBOSE >= 0) if (iv.m_type == nullptr and cif::VERBOSE >= 0)
std::cerr << "Missing item_type for " << iv.m_tag << '\n'; std::cerr << "Missing item_type for " << iv.m_item_name << '\n';
} }
} }
} }
......
...@@ -163,9 +163,9 @@ int atom::atom_impl::get_charge() const ...@@ -163,9 +163,9 @@ int atom::atom_impl::get_charge() const
// const std::string atom::atom_impl::get_property(const std::string_view name) const // const std::string atom::atom_impl::get_property(const std::string_view name) const
// { // {
// for (auto &&[tag, ref] : mCachedRefs) // for (auto &&[item_name, ref] : mCachedRefs)
// { // {
// if (tag == name) // if (item_name == name)
// return ref.as<std::string>(); // return ref.as<std::string>();
// } // }
...@@ -175,9 +175,9 @@ int atom::atom_impl::get_charge() const ...@@ -175,9 +175,9 @@ int atom::atom_impl::get_charge() const
// void atom::atom_impl::set_property(const std::string_view name, const std::string &value) // void atom::atom_impl::set_property(const std::string_view name, const std::string &value)
// { // {
// for (auto &&[tag, ref] : mCachedRefs) // for (auto &&[item_name, ref] : mCachedRefs)
// { // {
// if (tag != name) // if (item_name != name)
// continue; // continue;
// ref = value; // ref = value;
......
...@@ -269,7 +269,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -269,7 +269,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
{ {
const auto kEOF = std::char_traits<char>::eof(); const auto kEOF = std::char_traits<char>::eof();
CIFToken result = CIFToken::Unknown; CIFToken result = CIFToken::UNKNOWN;
int quoteChar = 0; int quoteChar = 0;
State state = State::Start; State state = State::Start;
m_bol = false; m_bol = false;
...@@ -279,7 +279,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -279,7 +279,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
reserved_words_automaton dag; reserved_words_automaton dag;
while (result == CIFToken::Unknown) while (result == CIFToken::UNKNOWN)
{ {
auto ch = get_next_char(); auto ch = get_next_char();
...@@ -287,7 +287,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -287,7 +287,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
{ {
case State::Start: case State::Start:
if (ch == kEOF) if (ch == kEOF)
result = CIFToken::Eof; result = CIFToken::END_OF_FILE;
else if (ch == '\n') else if (ch == '\n')
{ {
m_bol = true; m_bol = true;
...@@ -298,7 +298,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -298,7 +298,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
else if (ch == '#') else if (ch == '#')
state = State::Comment; state = State::Comment;
else if (ch == '_') else if (ch == '_')
state = State::Tag; state = State::ItemName;
else if (ch == ';' and m_bol) else if (ch == ';' and m_bol)
state = State::TextItem; state = State::TextItem;
else if (ch == '?') else if (ch == '?')
...@@ -316,7 +316,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -316,7 +316,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
case State::White: case State::White:
if (ch == kEOF) if (ch == kEOF)
result = CIFToken::Eof; result = CIFToken::END_OF_FILE;
else if (not is_space(ch)) else if (not is_space(ch))
{ {
state = State::Start; state = State::Start;
...@@ -335,7 +335,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -335,7 +335,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
m_token_buffer.clear(); m_token_buffer.clear();
} }
else if (ch == kEOF) else if (ch == kEOF)
result = CIFToken::Eof; result = CIFToken::END_OF_FILE;
else if (not is_any_print(ch)) else if (not is_any_print(ch))
error("invalid character in comment"); error("invalid character in comment");
break; break;
...@@ -344,7 +344,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -344,7 +344,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
if (not is_non_blank(ch)) if (not is_non_blank(ch))
{ {
retract(); retract();
result = CIFToken::Value; result = CIFToken::VALUE;
} }
else else
state = State::Value; state = State::Value;
...@@ -366,7 +366,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -366,7 +366,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
{ {
assert(m_token_buffer.size() >= 2); assert(m_token_buffer.size() >= 2);
m_token_value = std::string_view(m_token_buffer.data() + 1, m_token_buffer.size() - 3); m_token_value = std::string_view(m_token_buffer.data() + 1, m_token_buffer.size() - 3);
result = CIFToken::Value; result = CIFToken::VALUE;
} }
else if (ch == kEOF) else if (ch == kEOF)
error("unterminated textfield"); error("unterminated textfield");
...@@ -387,7 +387,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -387,7 +387,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
if (is_white(ch)) if (is_white(ch))
{ {
retract(); retract();
result = CIFToken::Value; result = CIFToken::VALUE;
if (m_token_buffer.size() < 2) if (m_token_buffer.size() < 2)
error("Invalid quoted string token"); error("Invalid quoted string token");
...@@ -403,11 +403,11 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -403,11 +403,11 @@ sac_parser::CIFToken sac_parser::get_next_token()
error("invalid character in quoted string"); error("invalid character in quoted string");
break; break;
case State::Tag: case State::ItemName:
if (not is_non_blank(ch)) if (not is_non_blank(ch))
{ {
retract(); retract();
result = CIFToken::Tag; result = CIFToken::ITEM_NAME;
m_token_value = std::string_view(m_token_buffer.data(), m_token_buffer.size()); m_token_value = std::string_view(m_token_buffer.data(), m_token_buffer.size());
} }
break; break;
...@@ -422,7 +422,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -422,7 +422,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
if (not is_non_blank(ch)) if (not is_non_blank(ch))
{ {
retract(); retract();
result = CIFToken::Value; result = CIFToken::VALUE;
m_token_value = std::string_view(m_token_buffer.data(), m_token_buffer.size()); m_token_value = std::string_view(m_token_buffer.data(), m_token_buffer.size());
} }
else else
...@@ -467,7 +467,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -467,7 +467,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
if (not is_non_blank(ch)) if (not is_non_blank(ch))
{ {
retract(); retract();
result = CIFToken::Value; result = CIFToken::VALUE;
m_token_value = std::string_view(m_token_buffer.data(), m_token_buffer.size()); m_token_value = std::string_view(m_token_buffer.data(), m_token_buffer.size());
break; break;
} }
...@@ -483,7 +483,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -483,7 +483,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
if (VERBOSE >= 5) if (VERBOSE >= 5)
{ {
std::cerr << get_token_name(result); std::cerr << get_token_name(result);
if (result != CIFToken::Eof) if (result != CIFToken::END_OF_FILE)
std::cerr << " " << std::quoted(m_token_value); std::cerr << " " << std::quoted(m_token_value);
std::cerr << '\n'; std::cerr << '\n';
} }
...@@ -710,7 +710,7 @@ bool sac_parser::parse_single_datablock(const std::string &datablock, const data ...@@ -710,7 +710,7 @@ bool sac_parser::parse_single_datablock(const std::string &datablock, const data
void sac_parser::parse_file() void sac_parser::parse_file()
{ {
while (m_lookahead != CIFToken::Eof) while (m_lookahead != CIFToken::END_OF_FILE)
{ {
switch (m_lookahead) switch (m_lookahead)
{ {
...@@ -735,10 +735,10 @@ void sac_parser::parse_file() ...@@ -735,10 +735,10 @@ void sac_parser::parse_file()
void sac_parser::parse_global() void sac_parser::parse_global()
{ {
match(CIFToken::GLOBAL); match(CIFToken::GLOBAL);
while (m_lookahead == CIFToken::Tag) while (m_lookahead == CIFToken::ITEM_NAME)
{ {
match(CIFToken::Tag); match(CIFToken::ITEM_NAME);
match(CIFToken::Value); match(CIFToken::VALUE);
} }
} }
...@@ -747,7 +747,7 @@ void sac_parser::parse_datablock() ...@@ -747,7 +747,7 @@ void sac_parser::parse_datablock()
static const std::string kUnitializedCategory("<invalid>"); static const std::string kUnitializedCategory("<invalid>");
std::string cat = kUnitializedCategory; // intial value acts as a guard for empty category names std::string cat = kUnitializedCategory; // intial value acts as a guard for empty category names
while (m_lookahead == CIFToken::LOOP or m_lookahead == CIFToken::Tag or m_lookahead == CIFToken::SAVE_NAME) while (m_lookahead == CIFToken::LOOP or m_lookahead == CIFToken::ITEM_NAME or m_lookahead == CIFToken::SAVE_NAME)
{ {
switch (m_lookahead) switch (m_lookahead)
{ {
...@@ -757,12 +757,12 @@ void sac_parser::parse_datablock() ...@@ -757,12 +757,12 @@ void sac_parser::parse_datablock()
match(CIFToken::LOOP); match(CIFToken::LOOP);
std::vector<std::string> tags; std::vector<std::string> item_names;
while (m_lookahead == CIFToken::Tag) while (m_lookahead == CIFToken::ITEM_NAME)
{ {
std::string catName, itemName; std::string catName, itemName;
std::tie(catName, itemName) = split_tag_name(m_token_value); std::tie(catName, itemName) = split_item_name(m_token_value);
if (cat == kUnitializedCategory) if (cat == kUnitializedCategory)
{ {
...@@ -772,19 +772,19 @@ void sac_parser::parse_datablock() ...@@ -772,19 +772,19 @@ void sac_parser::parse_datablock()
else if (not iequals(cat, catName)) else if (not iequals(cat, catName))
error("inconsistent categories in loop_"); error("inconsistent categories in loop_");
tags.push_back(itemName); item_names.push_back(itemName);
match(CIFToken::Tag); match(CIFToken::ITEM_NAME);
} }
while (m_lookahead == CIFToken::Value) while (m_lookahead == CIFToken::VALUE)
{ {
produce_row(); produce_row();
for (auto tag : tags) for (auto item_name : item_names)
{ {
produce_item(cat, tag, m_token_value); produce_item(cat, item_name, m_token_value);
match(CIFToken::Value); match(CIFToken::VALUE);
} }
} }
...@@ -792,10 +792,10 @@ void sac_parser::parse_datablock() ...@@ -792,10 +792,10 @@ void sac_parser::parse_datablock()
break; break;
} }
case CIFToken::Tag: case CIFToken::ITEM_NAME:
{ {
std::string catName, itemName; std::string catName, itemName;
std::tie(catName, itemName) = split_tag_name(m_token_value); std::tie(catName, itemName) = split_item_name(m_token_value);
if (not iequals(cat, catName)) if (not iequals(cat, catName))
{ {
...@@ -804,11 +804,11 @@ void sac_parser::parse_datablock() ...@@ -804,11 +804,11 @@ void sac_parser::parse_datablock()
produce_row(); produce_row();
} }
match(CIFToken::Tag); match(CIFToken::ITEM_NAME);
produce_item(cat, itemName, m_token_value); produce_item(cat, itemName, m_token_value);
match(CIFToken::Value); match(CIFToken::VALUE);
break; break;
} }
......
...@@ -239,18 +239,18 @@ void checkAtomRecords(datablock &db) ...@@ -239,18 +239,18 @@ void checkAtomRecords(datablock &db)
// Rewrite the coordinates and other items that look better in a fixed format // Rewrite the coordinates and other items that look better in a fixed format
// Be careful not to nuke invalidly formatted data here // Be careful not to nuke invalidly formatted data here
for (auto [tag, prec] : std::vector<std::tuple<std::string_view, std::string::size_type>>{ for (auto [item_name, prec] : std::vector<std::tuple<std::string_view, std::string::size_type>>{
{ "cartn_x", 3 }, { "cartn_x", 3 },
{ "cartn_y", 3 }, { "cartn_y", 3 },
{ "cartn_z", 3 }, { "cartn_z", 3 },
{ "occupancy", 2 }, { "occupancy", 2 },
{ "b_iso_or_equiv", 2 } }) { "b_iso_or_equiv", 2 } })
{ {
if (row[tag].empty()) if (row[item_name].empty())
continue; continue;
float v; float v;
auto s = row.get<std::string>(tag); auto s = row.get<std::string>(item_name);
if (auto [ptr, ec] = cif::from_chars(s.data(), s.data() + s.length(), v); ec != std::errc()) if (auto [ptr, ec] = cif::from_chars(s.data(), s.data() + s.length(), v); ec != std::errc())
continue; continue;
...@@ -259,7 +259,7 @@ void checkAtomRecords(datablock &db) ...@@ -259,7 +259,7 @@ void checkAtomRecords(datablock &db)
char b[12]; char b[12];
if (auto [ptr, ec] = cif::to_chars(b, b + sizeof(b), v, cif::chars_format::fixed, prec); ec == std::errc()) if (auto [ptr, ec] = cif::to_chars(b, b + sizeof(b), v, cif::chars_format::fixed, prec); ec == std::errc())
row.assign(tag, { b, static_cast<std::string::size_type>(ptr - b) }, false, false); row.assign(item_name, { b, static_cast<std::string::size_type>(ptr - b) }, false, false);
} }
} }
} }
...@@ -268,21 +268,21 @@ void checkAtomRecords(datablock &db) ...@@ -268,21 +268,21 @@ void checkAtomRecords(datablock &db)
if (cv) if (cv)
{ {
// See if there are items that are no longer known // See if there are items that are no longer known
for (auto tag : atom_site.get_items()) for (auto item_name : atom_site.get_items())
{ {
if (cv->get_validator_for_item(tag) != nullptr) if (cv->get_validator_for_item(item_name) != nullptr)
continue; continue;
auto r = atom_site.find_first(key(tag) != null); auto r = atom_site.find_first(key(item_name) != null);
if (not r) if (not r)
{ {
if (cif::VERBOSE > 0) if (cif::VERBOSE > 0)
std::clog << "Dropping unknown item " << tag << '\n'; std::clog << "Dropping unknown item " << item_name << '\n';
atom_site.remove_item(tag); atom_site.remove_item(item_name);
} }
else if (cif::VERBOSE > 0) else if (cif::VERBOSE > 0)
std::clog << "Keeping unknown item " << std::quoted(tag) << " in atom_site since it is not empty\n"; std::clog << "Keeping unknown item " << std::quoted(item_name) << " in atom_site since it is not empty\n";
} }
} }
} }
...@@ -733,19 +733,19 @@ void reconstruct_pdbx(file &file, std::string_view dictionary) ...@@ -733,19 +733,19 @@ void reconstruct_pdbx(file &file, std::string_view dictionary)
// Start by renaming items that may have old names based on alias info // Start by renaming items that may have old names based on alias info
for (auto tag : cat.get_items()) for (auto item_name : cat.get_items())
{ {
auto iv = cv->get_validator_for_item(tag); auto iv = cv->get_validator_for_item(item_name);
if (iv) // know, must be OK then` if (iv) // know, must be OK then`
continue; continue;
iv = cv->get_validator_for_aliased_item(tag); iv = cv->get_validator_for_aliased_item(item_name);
if (not iv) if (not iv)
continue; continue;
if (cif::VERBOSE > 0) if (cif::VERBOSE > 0)
std::clog << "Renaming " << tag << " to " << iv->m_tag << " in category " << cat.name() << '\n'; std::clog << "Renaming " << item_name << " to " << iv->m_item_name << " in category " << cat.name() << '\n';
cat.rename_item(tag, iv->m_tag); cat.rename_item(item_name, iv->m_item_name);
} }
for (auto link : validator.get_links_for_child(cat.name())) for (auto link : validator.get_links_for_child(cat.name()))
...@@ -780,13 +780,13 @@ void reconstruct_pdbx(file &file, std::string_view dictionary) ...@@ -780,13 +780,13 @@ void reconstruct_pdbx(file &file, std::string_view dictionary)
} }
// validate all values, and if they do not validate replace the content with an unknown flag // validate all values, and if they do not validate replace the content with an unknown flag
for (auto tag : cat.get_items()) for (auto item_name : cat.get_items())
{ {
auto iv = cv->get_validator_for_item(tag); auto iv = cv->get_validator_for_item(item_name);
if (not iv) if (not iv)
continue; continue;
auto ix = cat.get_item_ix(tag); auto ix = cat.get_item_ix(item_name);
for (auto row : cat) for (auto row : cat)
{ {
...@@ -796,7 +796,7 @@ void reconstruct_pdbx(file &file, std::string_view dictionary) ...@@ -796,7 +796,7 @@ void reconstruct_pdbx(file &file, std::string_view dictionary)
if (not iv->validate_value(value, ec)) if (not iv->validate_value(value, ec))
{ {
if (cif::VERBOSE > 0) if (cif::VERBOSE > 0)
std::clog << "Replacing value (" << std::quoted(value) << ") for item " << tag << " since it does not validate\n"; std::clog << "Replacing value (" << std::quoted(value) << ") for item " << item_name << " since it does not validate\n";
row[ix] = "?"; row[ix] = "?";
} }
......
...@@ -215,19 +215,19 @@ std::string trim_copy(std::string_view s) ...@@ -215,19 +215,19 @@ std::string trim_copy(std::string_view s)
// -------------------------------------------------------------------- // --------------------------------------------------------------------
std::tuple<std::string, std::string> split_tag_name(std::string_view tag) std::tuple<std::string, std::string> split_item_name(std::string_view item_name)
{ {
if (tag.empty()) if (item_name.empty())
throw std::runtime_error("empty tag"); throw std::runtime_error("empty item_name");
if (tag[0] != '_') if (item_name[0] != '_')
throw std::runtime_error("tag '" + std::string { tag } + "' does not start with underscore"); throw std::runtime_error("item_name '" + std::string { item_name } + "' does not start with underscore");
auto s = tag.find('.'); auto s = item_name.find('.');
if (s == std::string::npos) if (s == std::string::npos)
// throw std::runtime_error("tag does not contain dot (" + std::string{ tag } + ')'); // throw std::runtime_error("item_name does not contain dot (" + std::string{ item_name } + ')');
return std::tuple<std::string, std::string>{ "", tag.substr(1) }; return std::tuple<std::string, std::string>{ "", item_name.substr(1) };
else else
return std::tuple<std::string, std::string>{tag.substr(1, s - 1), tag.substr(s + 1)}; return std::tuple<std::string, std::string>{item_name.substr(1, s - 1), item_name.substr(s + 1)};
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
......
...@@ -196,31 +196,11 @@ int type_validator::compare(std::string_view a, std::string_view b) const ...@@ -196,31 +196,11 @@ int type_validator::compare(std::string_view a, std::string_view b) const
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// void ValidateItem::addLinked(ValidateItem* parent, const std::string& parentItem, const std::string& childItem)
//{
//// if (mParent != nullptr and VERBOSE)
//// cerr << "replacing parent in " << mCategory->m_name << " from " << mParent->mCategory->m_name << " to " << parent->mCategory->m_name << endl;
//// mParent = parent;
//
// if (m_type == nullptr and parent != nullptr)
// m_type = parent->m_type;
//
// if (parent != nullptr)
// {
// mLinked.push_back({parent, parentItem, childItem});
//
// parent->mChildren.insert(this);
////
//// if (mCategory->mKeys == std::vector<std::string>{mTag})
//// parent->mForeignKeys.insert(this);
// }
//}
void item_validator::operator()(std::string_view value) const void item_validator::operator()(std::string_view value) const
{ {
std::error_code ec; std::error_code ec;
if (not validate_value(value, ec)) if (not validate_value(value, ec))
throw std::system_error(ec, std::string{ value } + " does not match rx for " + m_tag); throw std::system_error(ec, std::string{ value } + " does not match rx for " + m_item_name);
} }
bool item_validator::validate_value(std::string_view value, std::error_code &ec) const noexcept bool item_validator::validate_value(std::string_view value, std::error_code &ec) const noexcept
...@@ -243,27 +223,27 @@ bool item_validator::validate_value(std::string_view value, std::error_code &ec) ...@@ -243,27 +223,27 @@ bool item_validator::validate_value(std::string_view value, std::error_code &ec)
void category_validator::add_item_validator(item_validator &&v) void category_validator::add_item_validator(item_validator &&v)
{ {
if (v.m_mandatory) if (v.m_mandatory)
m_mandatory_items.insert(v.m_tag); m_mandatory_items.insert(v.m_item_name);
v.m_category = this; v.m_category = this;
auto r = m_item_validators.insert(std::move(v)); auto r = m_item_validators.insert(std::move(v));
if (not r.second and VERBOSE >= 4) if (not r.second and VERBOSE >= 4)
std::cout << "Could not add validator for item " << v.m_tag << " to category " << m_name << '\n'; std::cout << "Could not add validator for item " << v.m_item_name << " to category " << m_name << '\n';
} }
const item_validator *category_validator::get_validator_for_item(std::string_view tag) const const item_validator *category_validator::get_validator_for_item(std::string_view item_name) const
{ {
const item_validator *result = nullptr; const item_validator *result = nullptr;
auto i = m_item_validators.find(item_validator{ std::string(tag) }); auto i = m_item_validators.find(item_validator{ std::string(item_name) });
if (i != m_item_validators.end()) if (i != m_item_validators.end())
result = &*i; result = &*i;
else if (VERBOSE > 4) else if (VERBOSE > 4)
std::cout << "No validator for tag " << tag << '\n'; std::cout << "No validator for item " << item_name << '\n';
return result; return result;
} }
const item_validator *category_validator::get_validator_for_aliased_item(std::string_view tag) const const item_validator *category_validator::get_validator_for_aliased_item(std::string_view item_name) const
{ {
const item_validator *result = nullptr; const item_validator *result = nullptr;
...@@ -271,8 +251,8 @@ const item_validator *category_validator::get_validator_for_aliased_item(std::st ...@@ -271,8 +251,8 @@ const item_validator *category_validator::get_validator_for_aliased_item(std::st
{ {
for (auto &ai : iv.m_aliases) for (auto &ai : iv.m_aliases)
{ {
const auto &[cat, name] = split_tag_name(ai.m_name); const auto &[cat, name] = split_item_name(ai.m_name);
if (iequals(name, tag) and iequals(cat, m_name)) if (iequals(name, item_name) and iequals(cat, m_name))
{ {
result = &iv; result = &iv;
break; break;
...@@ -324,19 +304,19 @@ const category_validator *validator::get_validator_for_category(std::string_view ...@@ -324,19 +304,19 @@ const category_validator *validator::get_validator_for_category(std::string_view
return result; return result;
} }
item_validator *validator::get_validator_for_item(std::string_view tag) const item_validator *validator::get_validator_for_item(std::string_view item_name) const
{ {
item_validator *result = nullptr; item_validator *result = nullptr;
std::string cat, item; std::string cat, item;
std::tie(cat, item) = split_tag_name(tag); std::tie(cat, item) = split_item_name(item_name);
auto *cv = get_validator_for_category(cat); auto *cv = get_validator_for_category(cat);
if (cv != nullptr) if (cv != nullptr)
result = const_cast<item_validator *>(cv->get_validator_for_item(item)); result = const_cast<item_validator *>(cv->get_validator_for_item(item));
if (result == nullptr and VERBOSE > 4) if (result == nullptr and VERBOSE > 4)
std::cout << "No validator for item " << tag << '\n'; std::cout << "No validator for item " << item_name << '\n';
return result; return result;
} }
...@@ -361,11 +341,11 @@ void validator::add_link_validator(link_validator &&v) ...@@ -361,11 +341,11 @@ void validator::add_link_validator(link_validator &&v)
auto piv = pcv->get_validator_for_item(v.m_parent_keys[i]); auto piv = pcv->get_validator_for_item(v.m_parent_keys[i]);
if (piv == nullptr) if (piv == nullptr)
throw std::runtime_error("unknown parent tag _" + v.m_parent_category + '.' + v.m_parent_keys[i]); throw std::runtime_error("unknown parent item _" + v.m_parent_category + '.' + v.m_parent_keys[i]);
auto civ = ccv->get_validator_for_item(v.m_child_keys[i]); auto civ = ccv->get_validator_for_item(v.m_child_keys[i]);
if (civ == nullptr) if (civ == nullptr)
throw std::runtime_error("unknown child tag _" + v.m_child_category + '.' + v.m_child_keys[i]); throw std::runtime_error("unknown child item _" + v.m_child_category + '.' + v.m_child_keys[i]);
if (civ->m_type == nullptr and piv->m_type != nullptr) if (civ->m_type == nullptr and piv->m_type != nullptr)
const_cast<item_validator *>(civ)->m_type = piv->m_type; const_cast<item_validator *>(civ)->m_type = piv->m_type;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment