Euphoria
textfileparser.h
Go to the documentation of this file.
1 #pragma once
2 
3 
4 #include <memory>
5 
6 namespace eu::core
7 {
8  namespace detail
9  {
10  struct Textfile
11  {
12  Textfile() = default;
13  virtual ~Textfile() = default;
14 
15  Textfile(const Textfile&) = delete;
16  Textfile(Textfile&&) = delete;
17  void operator=(const Textfile&) = delete;
18  void operator=(Textfile&&) = delete;
19 
20  char peek(/* advance = 1 */);
21 
22  [[nodiscard]] virtual bool has_more() const = 0;
23  // return 0 if position is beyond file
24  [[nodiscard]] virtual char peek(int advance) = 0;
25  [[nodiscard]] virtual char read() = 0;
26  };
27 
28  std::shared_ptr<Textfile> create_from_string(const std::string& str);
29 
31  {
32  int line = -1;
33  int column = -1;
34  };
35  }
36 
37  bool is_ident_start(char c);
38 
42  {
43  std::shared_ptr<detail::Textfile> file;
45 
46 
47  explicit TextfileParser(std::shared_ptr<detail::Textfile> afile);
48 
49 
50  static TextfileParser from_string(const std::string& str);
51 
52 
54  char peek_char(int advance = 0);
55 
57  std::string peek_string(int advance = 0);
58 
60  bool expect_char(char c);
61 
62  void advance_char();
63  char read_char();
64  std::string read_ident();
65  std::string read_string();
66  std::string read_to_end_of_line();
67  void skip_spaces(bool include_newline);
68 
69 
70  [[nodiscard]] bool has_more() const;
71  [[nodiscard]] int get_line() const;
72  [[nodiscard]] int get_column() const;
73  };
74 
75 }
76 
std::shared_ptr< Textfile > create_from_string(const std::string &str)
bool is_ident_start(char c)
Parses a text file in memory.
bool expect_char(char c)
if peekchar(0) is c then it is read and function returns true, otherwise false
TextfileParser(std::shared_ptr< detail::Textfile > afile)
void skip_spaces(bool include_newline)
std::string peek_string(int advance=0)
like PeekChar but returns human readable strings for some chars
std::string read_to_end_of_line()
detail::LocationInFile location
std::shared_ptr< detail::Textfile > file
static TextfileParser from_string(const std::string &str)
char peek_char(int advance=0)
advance = 0 - next char, 1-the one after that, negative values are not allowed
virtual char peek(int advance)=0
Textfile(const Textfile &)=delete
void operator=(Textfile &&)=delete
virtual bool has_more() const =0
void operator=(const Textfile &)=delete
Textfile(Textfile &&)=delete
virtual ~Textfile()=default