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
// checks for an initialized Row:
operator bool() const { return mData != nullptr; }
// for debugging
uint32 lineNr() const;
void lineNr(uint32 l);
bool empty() const;
const_iterator begin() const;
const_iterator end() const;
......@@ -544,6 +548,7 @@ class Row
static void swap(const string& name, ItemRow* a, ItemRow* b);
ItemRow* mData;
uint32 mLineNr = 0;
};
// swap for Rows is defined below
......
......@@ -4,8 +4,10 @@
#include <boost/filesystem/path.hpp>
// the std regex of gcc is crashing....
#include <boost/regex.hpp>
//// the std regex of gcc is crashing....
//#include <boost/regex.hpp>
#include <regex>
#include <set>
namespace cif
......@@ -38,7 +40,7 @@ struct ValidateType
{
std::string mName;
DDL_PrimitiveType mPrimitiveType;
boost::regex mRx;
std::regex mRx;
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
ItemRow* mNext;
Category* mCategory;
ItemValue* mValues;
uint32 mLineNr = 0;
};
ostream& operator<<(ostream& os, const ItemRow& r)
......@@ -2139,6 +2140,17 @@ auto Row::end() const -> const_iterator
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)
: mData(data), mPtr(ptr)
{
......
......@@ -652,6 +652,7 @@ void Parser::produceRow()
mCat->emplace({});
mRow = mCat->back();
mRow.lineNr(mLineNr);
}
void Parser::produceItem(const string& category, const string& item, const string& value)
......@@ -911,8 +912,7 @@ void DictParser::loadDictionary()
}
catch (const exception& ex)
{
if (VERBOSE)
cerr << "Error parsing dictionary: '" << ex.what() << "'" << endl;
throw_with_nested(runtime_error("Error parsing dictionary"));
}
// store all validators
......@@ -971,16 +971,23 @@ bool DictParser::collectItemTypes()
ba::replace_all(construct, "\\t", "\t");
ba::replace_all(construct, "\\\n", "");
ValidateType v = {
code, mapToPrimitiveType(primitiveCode), boost::regex(construct, boost::regex::egrep)
};
try
{
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
// as it has a name that is too strict for its own names :-)
// if (mFileImpl.mTypeValidators.count(v))
// mFileImpl.mTypeValidators.erase(v);
mValidator.addTypeValidator(move(v));
if (VERBOSE >= 5)
cerr << "Added type " << code << " (" << primitiveCode << ") => " << construct << endl;
......
......@@ -2,8 +2,9 @@
#include <boost/algorithm/string.hpp>
// since gcc's regex is crashing....
#include <boost/regex.hpp>
//// since gcc's regex is crashing....
//#include <boost/regex.hpp>
#include <regex>
#include "cif++/Cif++.h"
#include "cif++/CifParser.h"
......@@ -151,7 +152,7 @@ void ValidateItem::operator()(string value) const
{
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);
if (not mEnums.empty())
......@@ -208,7 +209,7 @@ const ValidateType* Validator::getValidatorForType(string typeCode) const
{
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())
result = &*i;
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