Commit 9862904a authored by Ronan's avatar Ronan

rename files and remove parser-impl.cc

parent c67dfed3
......@@ -21,11 +21,10 @@
############################################################################
set(HEADER_FILES
abnf.hh
belr.hh
grammarbuilder.hh
parser.hh
parser-impl.cc
abnf.h
belr.h
grammarbuilder.h
parser.h
)
set(BELR_HEADER_FILES )
......
#ifndef abnf_hh
#define abnf_hh
/*
* abnf.h
* Copyright (C) 2017 Belledonne Communications SARL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef _ABNF_H_
#define _ABNF_H_
#include "belr.hh"
namespace belr{
/**
* Grammar containing core definitions of ABNF.
* This is required for almost all IETF text based protocols.
......
#ifndef belr_hh
#define belr_hh
/*
* belr.h
* Copyright (C) 2017 Belledonne Communications SARL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef _BELR_H_
#define _BELR_H_
#include <string>
#include <list>
#include <map>
#include <memory>
#ifdef _MSC_VER
#ifdef BELR_STATIC
#define BELR_PUBLIC
......@@ -22,7 +39,7 @@
#endif
namespace belr{
BELR_PUBLIC std::string tolower(const std::string &str);
class ParserContextBase;
......@@ -169,9 +186,9 @@ public:
* Initialize an empty grammar, giving a name for debugging.
**/
BELR_PUBLIC Grammar(const std::string &name);
BELR_PUBLIC ~Grammar();
/**
* Include another grammar into this grammar.
**/
......@@ -209,7 +226,7 @@ public:
BELR_PUBLIC std::shared_ptr<Recognizer> findRule(const std::string &name);
/**
* Find a rule from the grammar, given its name.
* Unlike findRule(), getRule() never returns NULL.
* Unlike findRule(), getRule() never returns NULL.
* If the rule is not (yet) defined, it returns an undefined pointer, that will be set later if the rule gets defined.
* This mechanism is required to allow defining rules in any order, and defining rules that call themselve recursively.
* @param name the name of the rule to get
......@@ -226,7 +243,7 @@ public:
* The optimization step consists in checking whether belr::Selector objects in the grammar are exclusive or not.
* A selector is said exclusive when a single sub-rule can match. Knowing this in advance optimizes the processing because no branch
* context is to be created to explore the different choices of the selector recognizer.
**/
**/
void optimize();
/**
* Return the number of rules in this grammar.
......
#ifndef grammarbuilder_hh
#define grammarbuilder_hh
/*
* grammarbuilder.h
* Copyright (C) 2017 Belledonne Communications SARL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef _GRAMMARBUILDER_H_
#define _GRAMMARBUILDER_H_
#include "parser.hh"
#include <vector>
using namespace std;
namespace belr{
class ABNFAlternation;
class ABNFBuilder{
public:
virtual ~ABNFBuilder();
......
This diff is collapsed.
......@@ -22,11 +22,11 @@
set(BELR_HEADER_FILES )
set(BELR_SOURCE_FILES_C )
set(BELR_SOURCE_FILES_CXX
abnf.cc
belr.cc
grammarbuilder.cc
parser.cc
set(BELR_SOURCE_FILES_CXX
abnf.cpp
belr.cpp
grammarbuilder.cpp
parser.cpp
)
bc_apply_compile_flags(BELR_SOURCE_FILES_C STRICT_OPTIONS_CPP STRICT_OPTIONS_C)
......
/*
* abnf.cpp
* Copyright (C) 2017 Belledonne Communications SARL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "belr/abnf.hh"
using namespace std;
......@@ -27,7 +45,7 @@ CoreRules::CoreRules() : Grammar("core rules"){
void CoreRules::alpha(){
shared_ptr<Selector> selector=Foundation::selector(true);
selector->addRecognizer(Utils::char_range('a','z'));
selector->addRecognizer(Utils::char_range('A','Z'));
......@@ -155,7 +173,7 @@ ABNFGrammar::ABNFGrammar(): Grammar("ABNF"){
}
void ABNFGrammar::crlf_or_lf(){
addRule("crlf-or-lf",
addRule("crlf-or-lf",
Foundation::selector()
->addRecognizer(getRule("crlf"))
->addRecognizer(getRule("lf")));
......@@ -361,8 +379,8 @@ void ABNFGrammar::element(){
);
}
/*
"(" *c-wsp alternation *c-wsp ")"
/*
"(" *c-wsp alternation *c-wsp ")"
*/
void ABNFGrammar::group(){
addRule("group", Foundation::sequence()
......
/*
* belr.cpp
* Copyright (C) 2017 Belledonne Communications SARL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "belr/belr.hh"
#include "belr/parser.hh"
......@@ -56,7 +72,7 @@ const string &Recognizer::getName()const{
size_t Recognizer::feed(const shared_ptr<ParserContextBase> &ctx, const string &input, size_t pos){
size_t match;
ParserLocalContext hctx;
if (ctx) ctx->beginParse(hctx, shared_from_this());
match=_feed(ctx, input, pos);
......@@ -67,7 +83,7 @@ size_t Recognizer::feed(const shared_ptr<ParserContextBase> &ctx, const string &
}
}
if (ctx) ctx->endParse(hctx, input, pos, match);
return match;
}
......@@ -144,7 +160,7 @@ bool Selector::_getTransitionMap(TransitionMap* mask){
size_t Selector::_feedExclusive(const shared_ptr<ParserContextBase> &ctx, const string &input, size_t pos){
size_t matched=0;
for (auto it=mElements.begin(); it!=mElements.end(); ++it){
matched=(*it)->feed(ctx, input, pos);
if (matched!=string::npos && matched>0) {
......@@ -156,11 +172,11 @@ size_t Selector::_feedExclusive(const shared_ptr<ParserContextBase> &ctx, const
size_t Selector::_feed(const shared_ptr<ParserContextBase> &ctx, const string &input, size_t pos){
if (mIsExclusive) return _feedExclusive(ctx, input, pos);
size_t matched=0;
size_t bestmatch=0;
shared_ptr<HandlerContextBase> bestBranch;
for (auto it=mElements.begin(); it!=mElements.end(); ++it){
shared_ptr<HandlerContextBase> br;
if (ctx) br=ctx->branch();
......@@ -238,7 +254,7 @@ bool Sequence::_getTransitionMap(TransitionMap* mask){
size_t Sequence::_feed(const shared_ptr<ParserContextBase> &ctx, const string &input, size_t pos){
size_t matched=0;
size_t total=0;
for (auto it=mElements.begin(); it!=mElements.end(); ++it){
matched=(*it)->feed(ctx, input, pos);
if (matched==string::npos){
......@@ -257,7 +273,7 @@ void Sequence::_optimize(int recursionLevel){
Loop::Loop() : mMin(0), mMax(-1) {
}
shared_ptr<Loop> Loop::setRecognizer(const shared_ptr<Recognizer> &element, int min, int max){
......@@ -271,7 +287,7 @@ size_t Loop::_feed(const shared_ptr<ParserContextBase> &ctx, const string &input
size_t matched=0;
size_t total=0;
int repeat;
for(repeat=0;mMax!=-1 ? repeat<mMax : true;repeat++){
matched=mRecognizer->feed(ctx, input, pos);
if (matched==string::npos) break;
......@@ -324,7 +340,7 @@ shared_ptr<Loop> Foundation::loop(){
}
Literal::Literal(const string& lit) : mLiteral(tolower(lit)), mLiteralSize(mLiteral.size()) {
}
size_t Literal::_feed(const shared_ptr< ParserContextBase >& ctx, const string& input, size_t pos){
......@@ -497,4 +513,3 @@ string belr::tolower(const string &str){
transform(ret.begin(),ret.end(), ret.begin(), ::tolower);
return ret;
}
/*
* grammarbuilder.cpp
* Copyright (C) 2017 Belledonne Communications SARL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "belr/abnf.hh"
#include "belr/grammarbuilder.hh"
#include "belr/parser-impl.cc"
#include "belr/parser.hh"
#include "bctoolbox/logging.h"
......@@ -9,6 +26,7 @@
#include <fstream>
#include <sstream>
using namespace std;
namespace belr{
......@@ -16,7 +34,7 @@ ABNFBuilder::~ABNFBuilder(){
}
ABNFNumval::ABNFNumval() : mIsRange(false) {
}
shared_ptr< ABNFNumval > ABNFNumval::create(){
......@@ -77,7 +95,7 @@ shared_ptr< Recognizer > ABNFOption::buildRecognizer(const shared_ptr< Grammar >
}
ABNFOption::ABNFOption() {
}
shared_ptr< ABNFOption > ABNFOption::create(){
......@@ -89,7 +107,7 @@ void ABNFOption::setAlternation(const shared_ptr< ABNFAlternation >& a){
}
ABNFGroup::ABNFGroup() {
}
shared_ptr< ABNFGroup > ABNFGroup::create(){
......@@ -112,7 +130,7 @@ shared_ptr< Recognizer > ABNFElement::buildRecognizer(const shared_ptr< Grammar
if (!mCharVal.empty()){
if (mCharVal.size()==1)
return Foundation::charRecognizer(mCharVal[0],false);
else
else
return Utils::literal(mCharVal);
}
bctbx_error("[belr] ABNFElement::buildRecognizer is empty, should not happen!");
......@@ -121,7 +139,7 @@ shared_ptr< Recognizer > ABNFElement::buildRecognizer(const shared_ptr< Grammar
}
ABNFElement::ABNFElement() {
}
shared_ptr< ABNFElement > ABNFElement::create(){
......@@ -148,7 +166,7 @@ void ABNFElement::setProseVal(const string& prose){
}
ABNFRepetition::ABNFRepetition() : mMin(0), mMax(-1), mCount(-1) {
}
shared_ptr< ABNFRepetition > ABNFRepetition::create(){
......@@ -233,7 +251,7 @@ shared_ptr< Recognizer > ABNFAlternation::buildRecognizerNoOptim(const shared_pt
}
ABNFRule::ABNFRule() {
}
shared_ptr<ABNFRule> ABNFRule::create(){
......@@ -323,7 +341,7 @@ ABNFGrammarBuilder::ABNFGrammarBuilder()
shared_ptr<Grammar> ABNFGrammarBuilder::createFromAbnf(const string &abnf, const shared_ptr<Grammar> &gram){
size_t parsed;
shared_ptr<ABNFBuilder> builder = mParser.parseInput("rulelist",abnf,&parsed);
if (parsed<(size_t)abnf.size()){
bctbx_error("[belr] Only %llu bytes parsed over a total of %llu.", (unsigned long long)parsed, (unsigned long long) abnf.size());
......
/*
* parser.cpp
* Copyright (C) 2017 Belledonne Communications SARL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* 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, see <http://www.gnu.org/licenses/>.
*/
#include <belr/parser.hh>
#include <iostream>
#include "belr/parser-impl.cc"
using namespace std;
namespace belr{
......
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