Mercurial > repo
view interps/sadol/Source.hpp @ 11562:6b0304dcec5c draft
<oerjan> ` cd bin; cp welcome \xd0\xb4\xd0\xbe\xd0\xb1\xd1\x80\xd0\xbe-\xd0\xbf\xd0\xbe\xd0\xb6\xd0\xb0\xd0\xbb\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x82\xd1\x8c; sled \xd0\xb4\xd0\xbe\xd0\xb1\xd1\x80\xd0\xbe-\xd0\xbf\xd0\xbe\xd0\xb6\xd0\xb0\xd0\xbb\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x82\xd1\x8c//s,welcome,welcome.ru,
author | HackEso <hackeso@esolangs.org> |
---|---|
date | Wed, 16 May 2018 04:46:17 +0100 |
parents | 859f9b4339e6 |
children |
line wrap: on
line source
/* * BDSM2 * Author: Adam Sawicki * http://www.regedit.risp.pl * mailto:regedit@risp.pl */ #ifndef SOURCE_H_ #define SOURCE_H_ class Source { public: struct Iterator { size_t Index; int Row; int Col; // return string in form of "index: #, row: #, col: #" string ToString() const; }; private: const string *m_Src; Iterator m_Index; // Valid only if m_ErrIndexSaved Iterator m_ErrIndex; bool m_ErrIndexSaved; // Read current character // Cannot be end. char Peek() { return (*m_Src)[m_Index.Index]; } // Forward cursor one step // Cannot be end. void Forward(); // Read current character and step forward // Cannot be end. char Get(); public: // Create view of given document as source for parsing Source(const string *Src); const Iterator & GetIterator() { return (m_ErrIndexSaved ? m_ErrIndex : m_Index); } // Return true of current position at the end bool End() { return m_Index.Index >= m_Src->size(); } // Read current character and step forward (safe) // If at end, error. char GetS(); // Skip all whitespaces and comments void Skip(); // Freeze position for error reporting (real position will still moving) void SaveErrPos() { m_ErrIndex = m_Index; m_ErrIndexSaved = true; } // Drop frozen position for error (real position will be reported in errors) void DropErrPos() { m_ErrIndexSaved = false; } // Write error and terminate process, include current (or frozen) index, row and col void SrcError(const string &msg, ERR_PLACE place = ERR_GENERAL); }; #endif