teditor
1.8.0@@fee5e94
Terminal based editor written in C++
|
Go to the documentation of this file.
6 #include <unordered_set>
28 NFA(
const std::string& reg);
37 size_t find(
const std::string& str,
size_t start = 0,
size_t end = 0);
48 size_t findAny(
const std::string& str,
size_t& matchStartPos,
49 size_t start = 0,
size_t end = 0);
51 ~NFA() {
for (
auto itr : states)
delete itr; }
64 bool isMatch(
bool lastStateRemaining =
false)
const;
117 State() : c(0), s(), next(nullptr), other(nullptr) {}
118 State(
int _c): c(_c), s(), next(nullptr), other(nullptr) {}
122 typedef std::unordered_set<State*> Actives;
125 std::vector<State*> states;
131 DoubleBuffer<Actives> acs;
133 void stepThroughSplitStates();
134 void checkForSplitState(State* st,
const Point& pos, Actives& ac);
140 std::vector<State*> tails;
141 Fragment(): entry(nullptr), tails() {}
143 void addState(State* s);
144 void appendState(State* s) { tails.push_back(s); }
148 std::stack<Fragment> fragments;
151 struct CompilerState {
153 bool prevSqBracketOpen;
155 bool isUnderSqBracket;
157 void validate(
const std::string& reg);
160 void parseChar(
char c, CompilerState& cState);
161 void parseGeneral(
char c, CompilerState& cState);
162 void parseInsideSqBracket(
char c, CompilerState& cState);
163 State* createState(
int c);
164 void addNewStateFor(
int c);
165 void stitchFragments();
Type & current()
Definition: double_buffer.hpp:12
void reset()
Reset all the variables used during regex search. This needs to be called once before beginning of ev...
Definition: nfa.cpp:90
struct Impl ///
Definition: any.hpp:54
~NFA()
Definition: nfa.h:51
Ken-Thompson NFA as described here: https://swtch.com/~rsc/regexp/regexp1.html but adjusted to work w...
Definition: nfa.h:23
bool step(char c, const Point &pos)
Step through the NFA state using the current char.
Definition: nfa.cpp:97
bool isMatch(bool lastStateRemaining=false) const
checks if we have reached match state, indicating a regex match
Definition: nfa.cpp:123
static const size_t NoMatch
Definition: nfa.h:93
size_t findAny(const std::string &str, size_t &matchStartPos, size_t start=0, size_t end=0)
Tries for regex match starting from anywhere in the string.
Definition: nfa.cpp:76
#define ASSERT(check, fmt,...)
Macro to assert with runtime_error exception if the check fails.
Definition: utils.h:35
const Point & getMatchPos() const
After the search has finished, use this to know the latest position of the match of the regex in the ...
Definition: nfa.h:77
Type & next()
Definition: double_buffer.hpp:14
bool areActiveStatesEmpty() const
Tells if after the current step() whether there are any active states still remaining....
Definition: nfa.h:71
NFA(const std::string ®)
ctor with adding a regex for the NFA
Definition: nfa.cpp:48
void update()
Definition: double_buffer.hpp:16
size_t find(const std::string &str, size_t start=0, size_t end=0)
String match function.
Definition: nfa.cpp:64
Pos2di Point
Definition: pos2d.h:112
T x
Definition: pos2d.h:16