teditor  1.8.0@@fee5e94
Terminal based editor written in C++
scanner.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include "core/pos2d.h"
5 #include "core/buffer.h"
6 
7 namespace teditor {
8 namespace parser {
9 
11 class Scanner {
12  public:
13  virtual ~Scanner() {}
14  virtual char next(Point& pt) = 0;
15  virtual bool isEof() const = 0;
16  virtual void rewind() = 0;
17  virtual std::string at(const Point& begin, const Point& end) = 0;
18 }; // class Scanner
19 
20 
21 class StringScanner : public Scanner {
22  public:
23  StringScanner(const std::string& s): str(s), currPos(0), startPos(0) {}
24  char next(Point& pt) override;
25  bool isEof() const override { return currPos >= str.size(); }
26  void rewind() override;
27  std::string at(const Point& begin, const Point& end) override;
28 
29  private:
30  std::string str;
31  size_t currPos;
32  size_t startPos;
33 }; // class StringScanner
34 
35 
36 class BufferScanner : public Scanner {
37  public:
39  char next(Point& pt) override;
40  bool isEof() const override { return end == buf.getPoint(); }
41  void rewind() override { buf.left(); }
42  std::string at(const Point& begin, const Point& end) override;
43 
44  private:
45  Buffer& buf;
46  Point currPos, end;
47 }; // class BufferScanner
48 
49 } // namespace parser
50 } // namespace teditor
teditor::parser::Scanner::~Scanner
virtual ~Scanner()
Definition: scanner.h:13
teditor::parser::BufferScanner::BufferScanner
BufferScanner(Buffer &b)
Definition: scanner.cpp:30
teditor::parser::StringScanner::at
std::string at(const Point &begin, const Point &end) override
Definition: scanner.cpp:24
teditor::parser::StringScanner::isEof
bool isEof() const override
Definition: scanner.h:25
teditor::parser::BufferScanner::isEof
bool isEof() const override
Definition: scanner.h:40
teditor::parser::Scanner::isEof
virtual bool isEof() const =0
teditor::Buffer::left
void left()
Definition: buffer.cpp:670
teditor::parser::StringScanner::StringScanner
StringScanner(const std::string &s)
Definition: scanner.h:23
teditor::parser::BufferScanner::next
char next(Point &pt) override
Definition: scanner.cpp:36
teditor::Buffer::length
int length() const
Definition: buffer.h:92
teditor::Buffer::getPoint
const Point & getPoint() const
Definition: buffer.h:165
teditor::Pos2d::y
T y
Definition: pos2d.h:16
teditor::Line::get
const std::string & get() const
Definition: line.h:51
teditor::parser::Scanner::next
virtual char next(Point &pt)=0
teditor::Buffer::at
Line & at(int idx)
Definition: buffer.h:98
teditor::Buffer::lengthOf
int lengthOf(int i) const
Definition: buffer.h:187
utils.h
teditor::parser::StringScanner
Definition: scanner.h:21
teditor::Pos2d< int >::DataT
int DataT
Definition: pos2d.h:14
teditor::parser::StringScanner::next
char next(Point &pt) override
Definition: scanner.cpp:8
ASSERT
#define ASSERT(check, fmt,...)
Macro to assert with runtime_error exception if the check fails.
Definition: utils.h:35
teditor::parser::BufferScanner::at
std::string at(const Point &begin, const Point &end) override
Definition: scanner.cpp:45
file_utils.h
buffer.h
teditor::parser::BufferScanner
Definition: scanner.h:36
teditor::Pos2d< int >
teditor::Buffer::right
void right()
Definition: buffer.cpp:686
teditor::parser::Scanner
Definition: scanner.h:11
teditor::parser::Scanner::rewind
virtual void rewind()=0
pos2d.h
teditor::parser::BufferScanner::rewind
void rewind() override
Definition: scanner.h:41
teditor::Buffer::regionAsStr
std::string regionAsStr() const
Definition: buffer.cpp:307
teditor::parser::Scanner::at
virtual std::string at(const Point &begin, const Point &end)=0
scanner.h
teditor::Pos2d::x
T x
Definition: pos2d.h:16
teditor::parser::StringScanner::rewind
void rewind() override
Definition: scanner.cpp:17
teditor::Buffer
Definition: buffer.h:25
teditor
Definition: any.hpp:10