Skip to content
Snippets Groups Projects
Commit 994e3f7a authored by Jan Trávníček's avatar Jan Trávníček
Browse files

implementation of RankedBarSymbol

parent d13953ae
No related branches found
No related tags found
No related merge requests found
Showing with 160 additions and 7 deletions
...@@ -153,6 +153,14 @@ std::list<sax::Token> api<alphabet::BarSymbol>::compose(const alphabet::BarSymbo ...@@ -153,6 +153,14 @@ std::list<sax::Token> api<alphabet::BarSymbol>::compose(const alphabet::BarSymbo
return ToXMLComposers::symbolComposer.compose(data); return ToXMLComposers::symbolComposer.compose(data);
} }
   
alphabet::RankedBarSymbol api<alphabet::RankedBarSymbol>::parse(std::list<sax::Token>& input) {
return FromXMLParsers::symbolParser.parseRankedBarSymbol(input);
}
std::list<sax::Token> api<alphabet::RankedBarSymbol>::compose(const alphabet::RankedBarSymbol& data) {
return ToXMLComposers::symbolComposer.compose(data);
}
   
automaton::Automaton api<automaton::Automaton>::parse(std::list<sax::Token>& input) { automaton::Automaton api<automaton::Automaton>::parse(std::list<sax::Token>& input) {
return FromXMLParsers::automatonParser.parseAutomaton(input); return FromXMLParsers::automatonParser.parseAutomaton(input);
...@@ -635,6 +643,10 @@ void ToXMLComposers::Visit(void* data, const alphabet::BarSymbol& symbol) const ...@@ -635,6 +643,10 @@ void ToXMLComposers::Visit(void* data, const alphabet::BarSymbol& symbol) const
*((std::list<sax::Token>*) data) = std::move(api<alphabet::BarSymbol>::compose(symbol)); *((std::list<sax::Token>*) data) = std::move(api<alphabet::BarSymbol>::compose(symbol));
} }
   
void ToXMLComposers::Visit(void* data, const alphabet::RankedBarSymbol& symbol) const {
*((std::list<sax::Token>*) data) = std::move(api<alphabet::RankedBarSymbol>::compose(symbol));
}
void ToXMLComposers::Visit(void* data, const alphabet::LabeledSymbol& symbol) const { void ToXMLComposers::Visit(void* data, const alphabet::LabeledSymbol& symbol) const {
*((std::list<sax::Token>*) data) = std::move(api<alphabet::LabeledSymbol>::compose(symbol)); *((std::list<sax::Token>*) data) = std::move(api<alphabet::LabeledSymbol>::compose(symbol));
} }
......
...@@ -150,6 +150,12 @@ struct api<alphabet::BarSymbol> { ...@@ -150,6 +150,12 @@ struct api<alphabet::BarSymbol> {
static std::list<sax::Token> compose(const alphabet::BarSymbol& data); static std::list<sax::Token> compose(const alphabet::BarSymbol& data);
}; };
   
template<>
struct api<alphabet::RankedBarSymbol> {
static alphabet::RankedBarSymbol parse(std::list<sax::Token>& input);
static std::list<sax::Token> compose(const alphabet::RankedBarSymbol& data);
};
template<> template<>
struct api<automaton::Automaton> { struct api<automaton::Automaton> {
static automaton::Automaton parse(std::list<sax::Token>& input); static automaton::Automaton parse(std::list<sax::Token>& input);
...@@ -522,6 +528,7 @@ class ToXMLComposers : public VisitableObjectBase::const_visitor_type { ...@@ -522,6 +528,7 @@ class ToXMLComposers : public VisitableObjectBase::const_visitor_type {
void Visit(void*, const alphabet::EndSymbol& symbol) const; void Visit(void*, const alphabet::EndSymbol& symbol) const;
void Visit(void*, const alphabet::RankedSymbol& symbol) const; void Visit(void*, const alphabet::RankedSymbol& symbol) const;
void Visit(void*, const alphabet::BarSymbol& symbol) const; void Visit(void*, const alphabet::BarSymbol& symbol) const;
void Visit(void*, const alphabet::RankedBarSymbol& symbol) const;
   
void Visit(void*, const automaton::EpsilonNFA& automaton) const; void Visit(void*, const automaton::EpsilonNFA& automaton) const;
void Visit(void*, const automaton::MultiInitialStateNFA& automaton) const; void Visit(void*, const automaton::MultiInitialStateNFA& automaton) const;
......
#include "RankedBarSymbol.h"
namespace alphabet {
RankedBarSymbol::RankedBarSymbol(int rank) : rank(primitive::Integer(rank)) {
}
RankedBarSymbol::RankedBarSymbol(const primitive::Integer& rank) : rank(rank) {
}
SymbolBase* RankedBarSymbol::clone() const {
return new RankedBarSymbol(*this);
}
SymbolBase* RankedBarSymbol::plunder() && {
return new RankedBarSymbol(std::move(*this));
}
const primitive::Integer& RankedBarSymbol::getRank() const {
return rank;
}
bool RankedBarSymbol::operator <(const ObjectBase& other) const {
return other > *this;
}
bool RankedBarSymbol::operator ==(const ObjectBase& other) const {
return other == *this;
}
bool RankedBarSymbol::operator >(const ObjectBase& other) const {
return other < *this;
}
bool RankedBarSymbol::operator ==(const RankedBarSymbol&) const {
return true;
}
bool RankedBarSymbol::operator <(const RankedBarSymbol&) const {
return false;
}
void RankedBarSymbol::operator>>(std::ostream& out) const {
out << "(RankedBar symbol)";
}
RankedBarSymbol::operator std::string () const {
return "|";
}
} /* namespace alphabet */
#ifndef RANKED_BAR_SYMBOL_H_
#define RANKED_BAR_SYMBOL_H_
#include "Symbol.h"
#include "../primitive/Integer.h"
namespace alphabet {
/**
* Represents rankedBar symbol for tree linearization.
*/
class RankedBarSymbol : public std::acceptor<RankedBarSymbol, VisitableSymbolBase, std::acceptor<RankedBarSymbol, alib::VisitableObjectBase, SymbolBase> > {
primitive::Integer rank;
public:
/**
* Creates a rankedBar symbol.
* @param symbol name of the symbol
*/
explicit RankedBarSymbol(int rank);
explicit RankedBarSymbol(const primitive::Integer& rank);
virtual SymbolBase* clone() const;
virtual SymbolBase* plunder() &&;
/**
* @return rank of the symbol
*/
const primitive::Integer& getRank() const;
virtual bool operator <(const alib::ObjectBase& other) const;
virtual bool operator ==(const alib::ObjectBase& other) const;
virtual bool operator >(const alib::ObjectBase& other) const;
virtual bool operator ==(const RankedBarSymbol& other) const;
virtual bool operator <(const RankedBarSymbol& other) const;
virtual void operator>>(std::ostream& out) const;
virtual operator std::string () const;
virtual int selfTypeId() const {
return typeId<RankedBarSymbol>();
}
};
} /* namespace alphabet */
#endif /* RANKED_BAR_SYMBOL_H_ */
...@@ -16,7 +16,7 @@ namespace alphabet { ...@@ -16,7 +16,7 @@ namespace alphabet {
class SymbolBase; class SymbolBase;
   
typedef std::acceptor_base<SymbolBase, typedef std::acceptor_base<SymbolBase,
LabeledSymbol, BlankSymbol, BottomOfTheStackSymbol, EndSymbol, RankedSymbol, BarSymbol LabeledSymbol, BlankSymbol, BottomOfTheStackSymbol, EndSymbol, RankedSymbol, BarSymbol, RankedBarSymbol
> VisitableSymbolBase; > VisitableSymbolBase;
   
/** /**
......
...@@ -16,7 +16,8 @@ enum class FEATURES { ...@@ -16,7 +16,8 @@ enum class FEATURES {
BOTTOM, BOTTOM,
END, END,
RANKED, RANKED,
BAR BAR,
RANKED_BAR
}; };
   
} /* namespace alphabet */ } /* namespace alphabet */
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
namespace alphabet { namespace alphabet {
   
Symbol SymbolFromXMLParser::parseSymbol(std::list<sax::Token>& input) const { Symbol SymbolFromXMLParser::parseSymbol(std::list<sax::Token>& input) const {
return parseSymbol(input, std::set<FEATURES>({FEATURES::LABELED, FEATURES::BLANK, FEATURES::BOTTOM, FEATURES::END, FEATURES::RANKED, FEATURES::BAR})); return parseSymbol(input, std::set<FEATURES>({FEATURES::LABELED, FEATURES::BLANK, FEATURES::BOTTOM, FEATURES::END, FEATURES::RANKED, FEATURES::BAR, FEATURES::RANKED_BAR}));
} }
   
Symbol SymbolFromXMLParser::parseSymbol(std::list<sax::Token>& input, const std::set<FEATURES>& features) const { Symbol SymbolFromXMLParser::parseSymbol(std::list<sax::Token>& input, const std::set<FEATURES>& features) const {
...@@ -37,13 +37,16 @@ Symbol SymbolFromXMLParser::parseSymbol(std::list<sax::Token>& input, const std: ...@@ -37,13 +37,16 @@ Symbol SymbolFromXMLParser::parseSymbol(std::list<sax::Token>& input, const std:
} else if(isToken(input, sax::Token::TokenType::START_ELEMENT, "BarSymbol")) { } else if(isToken(input, sax::Token::TokenType::START_ELEMENT, "BarSymbol")) {
if(!features.count(FEATURES::BAR)) throw exception::AlibException(); if(!features.count(FEATURES::BAR)) throw exception::AlibException();
return Symbol(parseBarSymbol(input)); return Symbol(parseBarSymbol(input));
} else if(isToken(input, sax::Token::TokenType::START_ELEMENT, "RankedBarSymbol")) {
if(!features.count(FEATURES::RANKED_BAR)) throw exception::AlibException();
return Symbol(parseRankedBarSymbol(input));
} else { } else {
throw sax::ParserException(sax::Token("LabeledSymbol, BlankSymbol, BottomOfTheStackSymbol, EndSymbol", sax::Token::TokenType::START_ELEMENT), input.front()); throw sax::ParserException(sax::Token("LabeledSymbol, BlankSymbol, BottomOfTheStackSymbol, EndSymbol, RankedSymbol, BarSymbol, RankedBarSymbol", sax::Token::TokenType::START_ELEMENT), input.front());
} }
} }
   
bool SymbolFromXMLParser::first(std::list<sax::Token>& input) const { bool SymbolFromXMLParser::first(std::list<sax::Token>& input) const {
if(isToken(input, sax::Token::TokenType::START_ELEMENT, "LabeledSymbol") || isToken(input, sax::Token::TokenType::START_ELEMENT, "BlankSymbol") || isToken(input, sax::Token::TokenType::START_ELEMENT, "BottomOfTheStackSymbol") || isToken(input, sax::Token::TokenType::START_ELEMENT, "EndSymbol") || isToken(input, sax::Token::TokenType::START_ELEMENT, "RankedSymbol") || isToken(input, sax::Token::TokenType::START_ELEMENT, "BarSymbol")) { if(isToken(input, sax::Token::TokenType::START_ELEMENT, "LabeledSymbol") || isToken(input, sax::Token::TokenType::START_ELEMENT, "BlankSymbol") || isToken(input, sax::Token::TokenType::START_ELEMENT, "BottomOfTheStackSymbol") || isToken(input, sax::Token::TokenType::START_ELEMENT, "EndSymbol") || isToken(input, sax::Token::TokenType::START_ELEMENT, "RankedSymbol") || isToken(input, sax::Token::TokenType::START_ELEMENT, "BarSymbol") || isToken(input, sax::Token::TokenType::START_ELEMENT, "RankedBarSymbol")) {
return true; return true;
} else { } else {
return false; return false;
...@@ -89,4 +92,11 @@ BarSymbol SymbolFromXMLParser::parseBarSymbol(std::list<sax::Token>& input) cons ...@@ -89,4 +92,11 @@ BarSymbol SymbolFromXMLParser::parseBarSymbol(std::list<sax::Token>& input) cons
return BarSymbol(); return BarSymbol();
} }
   
RankedBarSymbol SymbolFromXMLParser::parseRankedBarSymbol(std::list<sax::Token>& input) const {
popToken(input, sax::Token::TokenType::START_ELEMENT, "RankedBarSymbol");
primitive::Integer rank = alib::api<primitive::Integer>::parse(input);
popToken(input, sax::Token::TokenType::END_ELEMENT, "RankedBarSymbol");
return RankedBarSymbol(rank);
}
} /* namespace alphabet */ } /* namespace alphabet */
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "LabeledSymbol.h" #include "LabeledSymbol.h"
#include "RankedSymbol.h" #include "RankedSymbol.h"
#include "BarSymbol.h" #include "BarSymbol.h"
#include "RankedBarSymbol.h"
   
namespace alib { namespace alib {
   
...@@ -45,6 +46,7 @@ class SymbolFromXMLParser : public sax::FromXMLParserHelper { ...@@ -45,6 +46,7 @@ class SymbolFromXMLParser : public sax::FromXMLParserHelper {
EndSymbol parseEndSymbol(std::list<sax::Token>& input) const; EndSymbol parseEndSymbol(std::list<sax::Token>& input) const;
RankedSymbol parseRankedSymbol(std::list<sax::Token>& input) const; RankedSymbol parseRankedSymbol(std::list<sax::Token>& input) const;
BarSymbol parseBarSymbol(std::list<sax::Token>& input) const; BarSymbol parseBarSymbol(std::list<sax::Token>& input) const;
RankedBarSymbol parseRankedBarSymbol(std::list<sax::Token>& input) const;
   
template<typename T> friend class alib::api; template<typename T> friend class alib::api;
public: public:
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <algorithm> #include <algorithm>
#include "LabeledSymbol.h" #include "LabeledSymbol.h"
#include "RankedSymbol.h" #include "RankedSymbol.h"
#include "RankedBarSymbol.h"
   
namespace alphabet { namespace alphabet {
   
...@@ -54,6 +55,14 @@ void SymbolToStringComposer::Visit(void* userData, const BarSymbol&) { ...@@ -54,6 +55,14 @@ void SymbolToStringComposer::Visit(void* userData, const BarSymbol&) {
out << "#|"; out << "#|";
} }
   
void SymbolToStringComposer::Visit(void* userData, const RankedBarSymbol& symbol) {
std::stringstream &out = *((std::stringstream*) userData);
out << "#|";
primitive::PrimitiveToStringComposer composer2;
out << composer2.compose(primitive::Primitive(symbol.getRank()));
}
std::string SymbolToStringComposer::compose(const Symbol& symbol) { std::string SymbolToStringComposer::compose(const Symbol& symbol) {
std::stringstream out; std::stringstream out;
symbol.getData().Accept((void*) &out, *this); symbol.getData().Accept((void*) &out, *this);
......
...@@ -25,6 +25,7 @@ class SymbolToStringComposer : public VisitableSymbolBase::visitor_type { ...@@ -25,6 +25,7 @@ class SymbolToStringComposer : public VisitableSymbolBase::visitor_type {
void Visit(void*, const EndSymbol& symbol); void Visit(void*, const EndSymbol& symbol);
void Visit(void*, const RankedSymbol& symbol); void Visit(void*, const RankedSymbol& symbol);
void Visit(void*, const BarSymbol& symbol); void Visit(void*, const BarSymbol& symbol);
void Visit(void*, const RankedBarSymbol& symbol);
   
public: public:
/** /**
......
...@@ -68,4 +68,12 @@ std::list<sax::Token> SymbolToXMLComposer::compose(const BarSymbol&) const { ...@@ -68,4 +68,12 @@ std::list<sax::Token> SymbolToXMLComposer::compose(const BarSymbol&) const {
return out; return out;
} }
   
std::list<sax::Token> SymbolToXMLComposer::compose(const RankedBarSymbol& symbol) const {
std::list<sax::Token> out;
out.push_back(sax::Token("RankedBarSymbol", sax::Token::TokenType::START_ELEMENT));
out.splice(out.end(), alib::api<primitive::Integer>::compose(symbol.getRank()));
out.push_back(sax::Token("RankedBarSymbol", sax::Token::TokenType::END_ELEMENT));
return out;
}
} /* namespace alphabet */ } /* namespace alphabet */
...@@ -46,6 +46,7 @@ class SymbolToXMLComposer { ...@@ -46,6 +46,7 @@ class SymbolToXMLComposer {
std::list<sax::Token> compose(const EndSymbol& symbol) const; std::list<sax::Token> compose(const EndSymbol& symbol) const;
std::list<sax::Token> compose(const RankedSymbol& symbol) const; std::list<sax::Token> compose(const RankedSymbol& symbol) const;
std::list<sax::Token> compose(const BarSymbol& symbol) const; std::list<sax::Token> compose(const BarSymbol& symbol) const;
std::list<sax::Token> compose(const RankedBarSymbol& symbol) const;
   
template<typename T> friend class alib::api; template<typename T> friend class alib::api;
}; };
......
...@@ -95,6 +95,7 @@ class BottomOfTheStackSymbol; ...@@ -95,6 +95,7 @@ class BottomOfTheStackSymbol;
class EndSymbol; class EndSymbol;
class RankedSymbol; class RankedSymbol;
class BarSymbol; class BarSymbol;
class RankedBarSymbol;
   
} }
   
...@@ -127,7 +128,7 @@ typedef std::acceptor_base<ObjectBase, ...@@ -127,7 +128,7 @@ typedef std::acceptor_base<ObjectBase,
label::PrimitiveLabel, label::HexavigesimalLabel, label::ObjectLabel, label::LabelSetLabel, label::LabelPairLabel, label::PrimitiveLabel, label::HexavigesimalLabel, label::ObjectLabel, label::LabelSetLabel, label::LabelPairLabel,
regexp::UnboundedRegExp, regexp::FormalRegExp, regexp::UnboundedRegExp, regexp::FormalRegExp,
string::Epsilon, string::LinearString, string::CyclicString, string::Epsilon, string::LinearString, string::CyclicString,
alphabet::LabeledSymbol, alphabet::BlankSymbol, alphabet::BottomOfTheStackSymbol, alphabet::EndSymbol, alphabet::RankedSymbol, alphabet::BarSymbol, alphabet::LabeledSymbol, alphabet::BlankSymbol, alphabet::BottomOfTheStackSymbol, alphabet::EndSymbol, alphabet::RankedSymbol, alphabet::BarSymbol, alphabet::RankedBarSymbol,
container::ObjectsSet, container::ObjectsVector, container::ObjectsPair, container::ObjectsMap, container::ObjectsSet, container::ObjectsVector, container::ObjectsPair, container::ObjectsMap,
primitive::String, primitive::Integer, primitive::Character primitive::String, primitive::Integer, primitive::Character
> VisitableObjectBase; > VisitableObjectBase;
...@@ -142,7 +143,7 @@ class ObjectBase : ...@@ -142,7 +143,7 @@ class ObjectBase :
label::PrimitiveLabel, label::HexavigesimalLabel, label::ObjectLabel, label::LabelSetLabel, label::LabelPairLabel, label::PrimitiveLabel, label::HexavigesimalLabel, label::ObjectLabel, label::LabelSetLabel, label::LabelPairLabel,
regexp::UnboundedRegExp, regexp::FormalRegExp, regexp::UnboundedRegExp, regexp::FormalRegExp,
string::Epsilon, string::LinearString, string::CyclicString, string::Epsilon, string::LinearString, string::CyclicString,
alphabet::LabeledSymbol, alphabet::BlankSymbol, alphabet::BottomOfTheStackSymbol, alphabet::EndSymbol, alphabet::RankedSymbol, alphabet::BarSymbol, alphabet::LabeledSymbol, alphabet::BlankSymbol, alphabet::BottomOfTheStackSymbol, alphabet::EndSymbol, alphabet::RankedSymbol, alphabet::BarSymbol, alphabet::RankedBarSymbol,
container::ObjectsSet, container::ObjectsVector, container::ObjectsPair, container::ObjectsMap, container::ObjectsSet, container::ObjectsVector, container::ObjectsPair, container::ObjectsMap,
primitive::String, primitive::Integer, primitive::Character primitive::String, primitive::Integer, primitive::Character
>, public VisitableObjectBase { >, public VisitableObjectBase {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment