Commit f8fccb7a authored by Ronan's avatar Ronan

fix(parser): rename belr_fatal to fatal (useless prefix and snake case ?) +...

fix(parser): rename belr_fatal to fatal (useless prefix and snake case ?) + export as public symbol on windows
parent df5a82e8
......@@ -315,7 +315,7 @@ T universal_pointer_cast(U * p){
return static_cast<T>(p);
}
void belr_fatal(const char *message);
BELR_PUBLIC void fatal(const char *message);
template <typename _derivedParserElementT, typename _parserElementT, typename _valueT>
void ParserCollector<_derivedParserElementT,_parserElementT, _valueT>::invoke(_parserElementT obj, _valueT value){
......@@ -324,7 +324,7 @@ void ParserCollector<_derivedParserElementT,_parserElementT, _valueT>::invoke(_p
template <typename _derivedParserElementT, typename _parserElementT, typename _valueT>
void ParserCollector<_derivedParserElementT,_parserElementT, _valueT>::invokeWithChild(_parserElementT obj, _parserElementT child){
belr_fatal("We should never be called in ParserCollector<_derivedParserElementT,_parserElementT, _valueT>::invokeWithChild(_parserElementT obj, _parserElementT child)");
fatal("We should never be called in ParserCollector<_derivedParserElementT,_parserElementT, _valueT>::invokeWithChild(_parserElementT obj, _parserElementT child)");
}
template <typename _derivedParserElementT, typename _parserElementT, typename _valueT>
......@@ -334,7 +334,7 @@ void ParserChildCollector<_derivedParserElementT,_parserElementT, _valueT>::invo
template <typename _derivedParserElementT, typename _parserElementT, typename _valueT>
void ParserChildCollector<_derivedParserElementT,_parserElementT, _valueT>::invoke(_parserElementT obj, _valueT value){
belr_fatal("We should never be called in ParserChildCollector<_derivedParserElementT,_parserElementT, _valueT>::invoke(_parserElementT obj, _valueT value)");
fatal("We should never be called in ParserChildCollector<_derivedParserElementT,_parserElementT, _valueT>::invoke(_parserElementT obj, _valueT value)");
}
template <typename _parserElementT>
......@@ -430,7 +430,7 @@ void ParserHandlerBase<_parserElementT>::installCollector(const std::string &rul
if (!rec){
std::ostringstream ostr;
ostr<<"There is no rule '"<<rulename<<"' in the grammar.";
belr_fatal(ostr.str().c_str());
fatal(ostr.str().c_str());
return;
}
mCollectors[rec->getId()]=collector;
......@@ -490,7 +490,7 @@ void ParserContext<_parserElementT>::_beginParse(ParserLocalContext & lctx, cons
mHandlerStack.push_back(std::static_pointer_cast<HandlerContext<_parserElementT>>(ctx));
}
if (mHandlerStack.empty()){
belr_fatal("Cannot parse when mHandlerStack is empty. You must define a top-level rule handler.");
fatal("Cannot parse when mHandlerStack is empty. You must define a top-level rule handler.");
}
lctx.set(ctx,rec,mHandlerStack.back()->getLastIterator());
}
......@@ -532,7 +532,7 @@ _parserElementT ParserContext<_parserElementT>::createRootObject(const std::stri
template <typename _parserElementT>
std::shared_ptr<HandlerContext<_parserElementT>> ParserContext<_parserElementT>::_branch(){
if (mHandlerStack.empty()){
belr_fatal("Cannot branch while stack is empty");
fatal("Cannot branch while stack is empty");
}
std::shared_ptr<HandlerContext<_parserElementT>> ret=mHandlerStack.back()->branch();
mHandlerStack.push_back(ret);
......@@ -542,7 +542,7 @@ std::shared_ptr<HandlerContext<_parserElementT>> ParserContext<_parserElementT>:
template <typename _parserElementT>
void ParserContext<_parserElementT>::_merge(const std::shared_ptr<HandlerContext<_parserElementT>> &other){
if (mHandlerStack.back()!=other){
belr_fatal("The branch being merged is not the last one of the stack !");
fatal("The branch being merged is not the last one of the stack !");
}
mHandlerStack.pop_back();
mHandlerStack.back()->merge(other);
......@@ -553,7 +553,7 @@ template <typename _parserElementT>
void ParserContext<_parserElementT>::_removeBranch(const std::shared_ptr<HandlerContext<_parserElementT>> &other){
auto it=find(mHandlerStack.rbegin(), mHandlerStack.rend(),other);
if (it==mHandlerStack.rend()){
belr_fatal("A branch could not be found in the stack while removing it !");
fatal("A branch could not be found in the stack while removing it !");
}else{
advance(it,1);
mHandlerStack.erase(it.base());
......@@ -593,7 +593,7 @@ void ParserContext<_parserElementT>::removeBranch(const std::shared_ptr<HandlerC
template <typename _parserElementT>
Parser<_parserElementT>::Parser(const std::shared_ptr<Grammar> &grammar) : mGrammar(grammar) {
if (!mGrammar->isComplete()){
belr_fatal("Grammar not complete, aborting.");
fatal("Grammar not complete, aborting.");
return;
}
}
......@@ -611,7 +611,7 @@ void Parser<_parserElementT>::installHandler(const std::shared_ptr<ParserHandler
if (!rec){
std::ostringstream str;
str<<"There is no rule '"<<handler->getRulename()<<"' in the grammar.";
belr_fatal(str.str().c_str());
fatal(str.str().c_str());
}
mHandlers[rec->getId()]=handler;
}
......
......@@ -10,7 +10,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
......@@ -25,7 +25,7 @@ using namespace std;
namespace belr{;
void belr_fatal(const char *message){
void fatal(const char *message){
bctbx_fatal("%s", message);
}
......@@ -78,9 +78,9 @@ void Recognizer::serialize(BinaryOutputStream& fstr, bool topLevel){
else if (typeid(*this) == typeid(RecognizerPointer)) tid = PointerId;
else if (typeid(*this) == typeid(RecognizerAlias)) tid = AliasId;
else bctbx_fatal("Unsupported Recognizer derived type.");
unsigned char type_byte = (unsigned char)tid;
if (tid == PointerId){
/*
* It is useless to serialize a RecognizerPointer, which is only a trick to break loops in recognizer chains.
......@@ -89,7 +89,7 @@ void Recognizer::serialize(BinaryOutputStream& fstr, bool topLevel){
dynamic_cast<RecognizerPointer*>(this)->getPointed()->serialize(fstr, topLevel);
return;
}
if (topLevel || mName.empty()) {
//write the type
fstr<<type_byte;
......@@ -259,7 +259,7 @@ CharRecognizer::CharRecognizer(BinaryGrammarBuilder &istr) : Recognizer(istr){
unsigned char toRecognize;
istr>>toRecognize;
mToRecognize = toRecognize;
unsigned char tmp;
istr>>tmp;
mCaseSensitive = !!tmp;
......@@ -319,7 +319,7 @@ size_t Selector::_feed(const shared_ptr<ParserContextBase> &ctx, const string &i
void Selector::_serialize(BinaryOutputStream &fstr){
fstr<<(unsigned char) mIsExclusive;
fstr<<(int)mElements.size();
for(auto it = mElements.begin(); it != mElements.end(); ++it){
(*it)->serialize(fstr);
}
......@@ -329,7 +329,7 @@ Selector::Selector(BinaryGrammarBuilder& istr) : Recognizer(istr){
unsigned char tmp;
istr>>tmp;
mIsExclusive = !!tmp;
int count;
istr>>count;
for (int i = 0 ; i < count ; ++i){
......@@ -424,7 +424,7 @@ void Sequence::_serialize(BinaryOutputStream &fstr){
Sequence::Sequence(BinaryGrammarBuilder& istr) : Recognizer(istr){
int count;
istr>>count;
for (int i = 0 ; i < count ; ++i){
shared_ptr<Recognizer> rec;
rec = Recognizer::build(istr);
......@@ -751,7 +751,7 @@ int Grammar::save(const std::string &filename){
for (auto it = mRules.begin(); it != mRules.end(); ++it){
(*it).second->serialize(of, true);
}
of.close();
return 0;
}
......@@ -759,7 +759,7 @@ int Grammar::save(const std::string &filename){
int Grammar::load(const std::string &filename){
BinaryGrammarBuilder ifs(*this);
int err = 0;
ifs.open(filename, ifstream::in|ifstream::binary);
if (ifs.fail()){
BCTBX_SLOGE<<"Could not open "<<filename;
......@@ -773,7 +773,7 @@ int Grammar::load(const std::string &filename){
BCTBX_SLOGE<<filename<< " is not a belr grammar binary file.";
return -1;
}
/*extract the name of the grammar*/
ifs>>mName;
//load rules
......@@ -782,7 +782,7 @@ int Grammar::load(const std::string &filename){
ifs.get();
if (ifs.eof()) break;
ifs.unget();
shared_ptr<Recognizer> rule = Recognizer::build(ifs);
if (!rule){
bctbx_error("Fail to parse recognizer.");
......@@ -813,4 +813,3 @@ string tolower(const string &str){
}
}//end of namespace
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