A Hugo incarnation of the blog.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

parse_driver.hpp 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include <string>
  3. #include <fstream>
  4. #include <sstream>
  5. #include "definition.hpp"
  6. #include "location.hh"
  7. #include "parser.hpp"
  8. struct parse_driver;
  9. void scanner_init(parse_driver* d, yyscan_t* scanner);
  10. void scanner_destroy(yyscan_t* scanner);
  11. class file_mgr {
  12. private:
  13. std::ostringstream string_stream;
  14. std::string file_contents;
  15. size_t file_offset;
  16. std::vector<size_t> line_offsets;
  17. public:
  18. file_mgr();
  19. void write(const char* buffer, size_t len);
  20. void mark_line();
  21. void finalize();
  22. size_t get_index(int line, int column) const;
  23. size_t get_line_end(int line) const;
  24. void print_location(
  25. std::ostream& stream,
  26. const yy::location& loc,
  27. bool highlight = true) const;
  28. };
  29. class parse_driver {
  30. private:
  31. std::string file_name;
  32. yy::location location;
  33. definition_group* global_defs;
  34. file_mgr* file_m;
  35. public:
  36. parse_driver(
  37. file_mgr& mgr,
  38. definition_group& defs,
  39. const std::string& file)
  40. : file_name(file), file_m(&mgr), global_defs(&defs) {}
  41. bool operator()();
  42. yy::location& get_current_location();
  43. file_mgr& get_file_manager() const;
  44. definition_group& get_global_defs() const;
  45. };
  46. #define YY_DECL yy::parser::symbol_type yylex(yyscan_t yyscanner, parse_driver& drv)
  47. YY_DECL;