Commit f96499cd by maarten

nieuwe dict, validate dict

git-svn-id: svn+ssh://gitlab/srv/svn-repos/pdb-redo/trunk@325 a1961a4f-ab94-4bcc-80e8-33b5a54de466
parent 274120c9
...@@ -492,6 +492,10 @@ class Row ...@@ -492,6 +492,10 @@ class Row
// checks for an initialized Row: // checks for an initialized Row:
operator bool() const { return mData != nullptr; } operator bool() const { return mData != nullptr; }
// for debugging
uint32 lineNr() const;
void lineNr(uint32 l);
bool empty() const; bool empty() const;
const_iterator begin() const; const_iterator begin() const;
const_iterator end() const; const_iterator end() const;
...@@ -544,6 +548,7 @@ class Row ...@@ -544,6 +548,7 @@ class Row
static void swap(const string& name, ItemRow* a, ItemRow* b); static void swap(const string& name, ItemRow* a, ItemRow* b);
ItemRow* mData; ItemRow* mData;
uint32 mLineNr = 0;
}; };
// swap for Rows is defined below // swap for Rows is defined below
......
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
// the std regex of gcc is crashing.... //// the std regex of gcc is crashing....
#include <boost/regex.hpp> //#include <boost/regex.hpp>
#include <regex>
#include <set> #include <set>
namespace cif namespace cif
...@@ -38,7 +40,7 @@ struct ValidateType ...@@ -38,7 +40,7 @@ struct ValidateType
{ {
std::string mName; std::string mName;
DDL_PrimitiveType mPrimitiveType; DDL_PrimitiveType mPrimitiveType;
boost::regex mRx; std::regex mRx;
bool operator<(const ValidateType& rhs) const bool operator<(const ValidateType& rhs) const
{ {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -124,6 +124,7 @@ struct ItemRow ...@@ -124,6 +124,7 @@ struct ItemRow
ItemRow* mNext; ItemRow* mNext;
Category* mCategory; Category* mCategory;
ItemValue* mValues; ItemValue* mValues;
uint32 mLineNr = 0;
}; };
ostream& operator<<(ostream& os, const ItemRow& r) ostream& operator<<(ostream& os, const ItemRow& r)
...@@ -2139,6 +2140,17 @@ auto Row::end() const -> const_iterator ...@@ -2139,6 +2140,17 @@ auto Row::end() const -> const_iterator
return const_iterator(mData, nullptr); return const_iterator(mData, nullptr);
} }
uint32 Row::lineNr() const
{
return mData ? mData->mLineNr : 0;
}
void Row::lineNr(uint32 l)
{
if (mData)
mData->mLineNr = l;
}
Row::const_iterator::const_iterator(ItemRow* data, ItemValue* ptr) Row::const_iterator::const_iterator(ItemRow* data, ItemValue* ptr)
: mData(data), mPtr(ptr) : mData(data), mPtr(ptr)
{ {
......
...@@ -652,6 +652,7 @@ void Parser::produceRow() ...@@ -652,6 +652,7 @@ void Parser::produceRow()
mCat->emplace({}); mCat->emplace({});
mRow = mCat->back(); mRow = mCat->back();
mRow.lineNr(mLineNr);
} }
void Parser::produceItem(const string& category, const string& item, const string& value) void Parser::produceItem(const string& category, const string& item, const string& value)
...@@ -911,8 +912,7 @@ void DictParser::loadDictionary() ...@@ -911,8 +912,7 @@ void DictParser::loadDictionary()
} }
catch (const exception& ex) catch (const exception& ex)
{ {
if (VERBOSE) throw_with_nested(runtime_error("Error parsing dictionary"));
cerr << "Error parsing dictionary: '" << ex.what() << "'" << endl;
} }
// store all validators // store all validators
...@@ -971,16 +971,23 @@ bool DictParser::collectItemTypes() ...@@ -971,16 +971,23 @@ bool DictParser::collectItemTypes()
ba::replace_all(construct, "\\t", "\t"); ba::replace_all(construct, "\\t", "\t");
ba::replace_all(construct, "\\\n", ""); ba::replace_all(construct, "\\\n", "");
ValidateType v = { try
code, mapToPrimitiveType(primitiveCode), boost::regex(construct, boost::regex::egrep) {
}; ValidateType v = {
code, mapToPrimitiveType(primitiveCode), regex(construct, regex::egrep | regex::optimize)
};
mValidator.addTypeValidator(move(v));
}
catch (const exception& ex)
{
throw_with_nested(CifParserError(t.lineNr(), "error in regular expression"));
}
// Do not replace an already defined type validator, this won't work with pdbx_v40 // Do not replace an already defined type validator, this won't work with pdbx_v40
// as it has a name that is too strict for its own names :-) // as it has a name that is too strict for its own names :-)
// if (mFileImpl.mTypeValidators.count(v)) // if (mFileImpl.mTypeValidators.count(v))
// mFileImpl.mTypeValidators.erase(v); // mFileImpl.mTypeValidators.erase(v);
mValidator.addTypeValidator(move(v));
if (VERBOSE >= 5) if (VERBOSE >= 5)
cerr << "Added type " << code << " (" << primitiveCode << ") => " << construct << endl; cerr << "Added type " << code << " (" << primitiveCode << ") => " << construct << endl;
......
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
// since gcc's regex is crashing.... //// since gcc's regex is crashing....
#include <boost/regex.hpp> //#include <boost/regex.hpp>
#include <regex>
#include "cif++/Cif++.h" #include "cif++/Cif++.h"
#include "cif++/CifParser.h" #include "cif++/CifParser.h"
...@@ -151,7 +152,7 @@ void ValidateItem::operator()(string value) const ...@@ -151,7 +152,7 @@ void ValidateItem::operator()(string value) const
{ {
if (not value.empty() and value != "?" and value != ".") if (not value.empty() and value != "?" and value != ".")
{ {
if (mType != nullptr and not boost::regex_match(value, mType->mRx)) if (mType != nullptr and not regex_match(value, mType->mRx))
throw ValidationError(mCategory->mName, mTag, "Value '" + value + "' does not match type expression for type " + mType->mName); throw ValidationError(mCategory->mName, mTag, "Value '" + value + "' does not match type expression for type " + mType->mName);
if (not mEnums.empty()) if (not mEnums.empty())
...@@ -208,7 +209,7 @@ const ValidateType* Validator::getValidatorForType(string typeCode) const ...@@ -208,7 +209,7 @@ const ValidateType* Validator::getValidatorForType(string typeCode) const
{ {
const ValidateType* result = nullptr; const ValidateType* result = nullptr;
auto i = mTypeValidators.find(ValidateType{ typeCode, ptChar, boost::regex() }); auto i = mTypeValidators.find(ValidateType{ typeCode, ptChar, regex() });
if (i != mTypeValidators.end()) if (i != mTypeValidators.end())
result = &*i; result = &*i;
else if (VERBOSE > 4) else if (VERBOSE > 4)
......
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