omega_h
Reliable mesh adaptation
Omega_h_reader.hpp
1 #ifndef OMEGA_H_READER_HPP
2 #define OMEGA_H_READER_HPP
3 
4 #include <functional>
5 #include <iosfwd>
6 
7 #include <Omega_h_any.hpp>
8 #include <Omega_h_reader_tables.hpp>
9 #include <Omega_h_std_vector.hpp>
10 
11 namespace Omega_h {
12 
13 class Reader {
14  public:
15  Reader() = delete;
16  Reader(Reader const&) = default;
17  virtual ~Reader() = default;
18  Reader(ReaderTablesPtr tables_in);
19  any read_stream(std::istream& stream, std::string const& stream_name_in = "");
20  any read_string(
21  std::string const& string, std::string const& string_name = "");
22  any read_file(std::string const& file_name);
23 
24  protected:
25  virtual any at_shift(int token, std::string& text);
26  virtual any at_reduce(int token, std::vector<any>& rhs);
27 
28  protected:
29  ReaderTablesPtr tables;
30  Parser const& parser;
31  FiniteAutomaton const& lexer;
32  GrammarPtr grammar;
33  std::size_t line;
34  std::size_t column;
35  int lexer_state;
36  std::string lexer_text;
37  std::string line_text;
38  int lexer_token;
39  std::size_t last_lexer_accept;
40  std::size_t last_lexer_accept_line;
41  std::size_t last_lexer_accept_column;
42  std::string last_lexer_accept_line_text;
43  int parser_state;
44  std::vector<int> parser_stack;
45  std::vector<any> value_stack;
46  std::vector<any> reduction_rhs;
47  std::string stream_name;
48  bool did_accept;
49 
50  protected: // variables for indentation-sensitive language parsing
51  bool sensing_indent;
52  std::string indent_text;
54  std::size_t line;
55  std::size_t start_length;
56  std::size_t end_length;
57  };
58  // this is the stack that shows, for the current leading indentation
59  // characters, which subset of them came from each nested increase
60  // in indentation
61  std::vector<IndentStackEntry> indent_stack;
62  // this stack notes, for each symbol in the pushdown automaton
63  // stack, how many characters indent the line that that symbol
64  // starts on
65  std::vector<std::size_t> symbol_indentation_stack;
66 
67  private: // helper methods
68  void at_token(std::istream& stream);
69  [[noreturn]] void indent_mismatch();
70  void at_token_indent(std::istream& stream);
71  void at_lexer_end(std::istream& stream);
72  void backtrack_to_last_accept(std::istream& stream);
73  void reset_lexer_state();
74  void update_position(char c);
75  void error_print_line(std::istream& is, std::ostream& os);
76 };
77 
78 class DebugReader : public Reader {
79  public:
80  DebugReader(ReaderTablesPtr tables_in, std::ostream& os_in);
81  DebugReader(DebugReader const& other) = default;
82  virtual ~DebugReader() override = default;
83 
84  protected:
85  virtual any at_shift(int token, std::string& text) override;
86  virtual any at_reduce(int token, std::vector<any>& rhs) override;
87 
88  private:
89  std::ostream& os;
90 };
91 
92 } // namespace Omega_h
93 
94 #endif
Definition: Omega_h_reader.hpp:78
Definition: Omega_h_reader.hpp:13
Definition: Omega_h_any.hpp:68
Definition: amr_mpi_test.cpp:6
Definition: Omega_h_finite_automaton.hpp:19
Definition: Omega_h_parser.hpp:26
Definition: Omega_h_reader.hpp:53