Skip to content
Snippets Groups Projects
Commit db30ed5b authored by Franck Dary's avatar Franck Dary
Browse files

Added fmt library in the project

parent 60e8b2f5
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
FILE(GLOB SOURCES src/*.cpp)
add_library(reading_machine STATIC ${SOURCES})
target_link_libraries(reading_machine util)
target_link_libraries(reading_machine common)
......@@ -21,6 +21,12 @@ class Action
Check
};
enum Object
{
Buffer,
Stack
};
private :
Type type;
......@@ -35,9 +41,12 @@ class Action
public :
static Object str2object(const std::string & s);
static Action addLinesIfNeeded(int nbLines);
static Action moveWordIndex(int movement);
static Action moveCharacterIndex(int movement);
static Action addHypothesis(const std::string & colName, std::size_t lineIndex, const std::string & hypothesis);
static Action addHypothesisRelative(const std::string & colName, Object object, int relativeIndex, const std::string & hypothesis);
};
#endif
......@@ -88,7 +88,9 @@ class Config
std::size_t getWordIndex() const;
std::size_t getCharacterIndex() const;
const String & getHistory(int relativeIndex) const;
std::size_t getStack(int relativeIndex) const;
bool hasHistory(int relativeIndex) const;
bool hasStack(int relativeIndex) const;
};
......
......@@ -2,11 +2,18 @@
#define TRANSITION__H
#include <vector>
#include "Action.hpp"
class Transition
{
private :
std::string name;
std::vector<Action> sequence;
public :
Transition(const std::string & name);
};
#endif
#ifndef TRANSITIONSET__H
#define TRANSITIONSET__H
#include <vector>
#include <string>
#include <unordered_map>
#include "Transition.hpp"
class TransitionSet
{
private :
std::vector<Transition> transitions;
std::unordered_map<std::string, std::size_t> name2index;
std::optional<std::size_t> defaultAction;
public :
TransitionSet(const std::string & filename);
};
#endif
This diff is collapsed.
#include <fmt/core.h>
#include "Config.hpp"
#include "util.hpp"
......@@ -316,8 +315,18 @@ const Config::String & Config::getHistory(int relativeIndex) const
return history[history.size()-1-relativeIndex];
}
std::size_t Config::getStack(int relativeIndex) const
{
return stack[stack.size()-1-relativeIndex];
}
bool Config::hasHistory(int relativeIndex) const
{
return relativeIndex > 0 && relativeIndex < (int)history.size();
}
bool Config::hasStack(int relativeIndex) const
{
return relativeIndex > 0 && relativeIndex < (int)stack.size();
}
#include "Transition.hpp"
#include <regex>
Transition::Transition(const std::string & name)
{
this->name = name;
std::regex writeRegex("WRITE ([bs])\\.(.+) (.+) (.+)");
std::smatch sm;
try
{
std::regex_match(name, sm, writeRegex);
if (!sm.empty())
{
sequence.emplace_back(Action::addHypothesisRelative(sm[3], Action::str2object(sm[1]), std::stoi(sm[2]), sm[4]));
return;
}
throw std::exception();
} catch (std::exception &) {util::myThrow(fmt::format("Invalid name '{}'", name));}
}
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment