3 #ifndef pfp_cpCommandScannerBASE_H_INCLUDED
4 #define pfp_cpCommandScannerBASE_H_INCLUDED
18 class CommandScannerBase
21 typedef std::vector<int> VectorInt;
23 static size_t const s_unavailable = std::numeric_limits<size_t>::max();
34 enum class ActionType__
53 enum class StartCondition__ {
76 std::deque<unsigned char> d_deque;
83 Input(std::istream *iStream,
size_t lineNr = 1);
85 void reRead(
size_t ch);
87 void reRead(std::string
const &str,
size_t fmIdx);
92 size_t nPending()
const
94 return d_deque.size();
96 void setPending(
size_t size)
98 d_deque.erase(d_deque.begin(), d_deque.end() - size);
113 std::string pushedName;
118 std::vector<StreamStruct> d_streamStack;
120 std::string d_filename;
121 static size_t s_istreamNr;
125 int d_startCondition = 0;
130 std::shared_ptr<std::ostream> d_out;
136 std::shared_ptr<std::istringstream> d_line;
139 std::string d_matched;
140 std::string d_lopMatched;
141 std::string::iterator d_lopIter;
142 std::string::iterator d_lopTail;
143 std::string::iterator d_lopEnd;
149 size_t (CommandScannerBase::*d_get)() = &CommandScannerBase::getInput;
152 std::istream *d_in__;
157 int const (*d_dfaBase__)[38];
159 static int const s_dfa__[][38];
160 static int const (*s_dfaBase__[])[38];
161 enum:
bool { s_interactive__ =
false };
166 s_maxSizeofStreamStack__ = 10
168 static size_t const s_ranges__[];
169 static size_t const s_rf__[][2];
172 CommandScannerBase(CommandScannerBase
const &other) =
delete;
173 CommandScannerBase &operator=(CommandScannerBase
const &rhs) =
delete;
176 std::string
const &filename()
const;
177 std::string
const &matched()
const;
179 size_t length()
const;
180 size_t lineNr()
const;
182 void setDebug(
bool onOff);
184 void switchOstream(std::ostream &out);
185 void switchOstream(std::string
const &outfilename);
188 void switchStreams(std::istream &in,
189 std::ostream &out = std::cout);
191 void switchIstream(std::string
const &infilename);
192 void switchStreams(std::string
const &infilename,
193 std::string
const &outfilename);
199 CommandScannerBase(std::istream &in, std::ostream &out);
200 CommandScannerBase(std::string
const &infilename, std::string
const &outfilename);
202 StartCondition__ startCondition()
const;
205 void begin(StartCondition__ startCondition);
207 void leave(
int retValue)
const;
214 void accept(
size_t nChars = 0);
215 void redo(
size_t nChars = 0);
219 void push(
size_t ch);
220 void push(std::string
const &txt);
223 std::vector<StreamStruct>
const &streamStack()
const;
225 void pushStream(std::istream &curStream);
226 void pushStream(std::string
const &curName);
229 void setFilename(std::string
const &name);
230 void setMatched(std::string
const &text);
232 static std::string istreamName__();
237 ActionType__ actionType__(
size_t range);
239 size_t matched__(
size_t ch);
240 size_t getRange__(
int ch);
242 size_t state__()
const;
243 void continue__(
int ch);
244 void echoCh__(
size_t ch);
245 void echoFirst__(
size_t ch);
246 void updateFinals__();
248 void print__()
const;
249 void pushFront__(
size_t ch);
252 void switchStream__(std::istream &in,
size_t lineNr);
253 void lopf__(
size_t tail);
254 void lop1__(
int lopSC);
262 void p_pushStream(std::string
const &name, std::istream *streamPtr);
263 void setMatchedSize(
size_t length);
264 bool knownFinalState();
266 template <
typename ReturnType,
typename ArgType>
267 static ReturnType constexpr as(ArgType value);
268 static bool constexpr available(
size_t value);
269 static StartCondition__ constexpr SC(
int sc);
270 static int constexpr SC(StartCondition__ sc);
273 template <
typename ReturnType,
typename ArgType>
274 inline ReturnType constexpr CommandScannerBase::as(ArgType value)
276 return static_cast<ReturnType
>(value);
279 inline bool CommandScannerBase::knownFinalState()
281 return (d_atBOL && available(d_final.bol.rule)) ||
282 available(d_final.std.rule);
285 inline bool constexpr CommandScannerBase::available(
size_t value)
287 return value != std::numeric_limits<size_t>::max();
290 inline CommandScannerBase::StartCondition__ constexpr CommandScannerBase::SC(
int sc)
292 return as<StartCondition__>(sc);
295 inline int constexpr CommandScannerBase::SC(StartCondition__ sc)
300 inline std::ostream &CommandScannerBase::out()
305 inline void CommandScannerBase::push(
size_t ch)
310 inline void CommandScannerBase::push(std::string
const &str)
312 d_input.reRead(str, 0);
315 inline void CommandScannerBase::setFilename(std::string
const &name)
320 inline void CommandScannerBase::setMatched(std::string
const &text)
325 inline std::string
const &CommandScannerBase::matched()
const
330 inline CommandScannerBase::StartCondition__ CommandScannerBase::startCondition()
const
332 return SC(d_startCondition);
335 inline std::string
const &CommandScannerBase::filename()
const
340 inline void CommandScannerBase::echo()
const
345 inline size_t CommandScannerBase::length()
const
347 return d_matched.size();
350 inline void CommandScannerBase::leave(
int retValue)
const
352 throw as<Leave__>(retValue);
355 inline size_t CommandScannerBase::lineNr()
const
357 return d_input.lineNr();
360 inline void CommandScannerBase::more()
365 inline void CommandScannerBase::begin(StartCondition__ startCondition)
368 d_dfaBase__ = s_dfaBase__[d_startCondition = SC(startCondition)];
371 inline size_t CommandScannerBase::state__()
const
376 inline size_t CommandScannerBase::get__()
378 return (this->*d_get)();
381 inline size_t CommandScannerBase::getInput()
383 return d_input.get();
386 inline bool CommandScannerBase::return__()
391 inline void CommandScannerBase::noReturn__()
399 #endif // CommandScannerBASE_H_INCLUDED
Definition: json.hpp:8681
Definition: CommandParser.h:50