PageRenderTime 25ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/mordor/ragel.h

http://github.com/mozy/mordor
C Header | 64 lines | 44 code | 15 blank | 5 comment | 0 complexity | 33bbf6491cd0f7f4203557a17d7c917d MD5 | raw file
Possible License(s): BSD-3-Clause
  1. #ifndef __MORDOR_RAGEL_H__
  2. #define __MORDOR_RAGEL_H__
  3. // Copyright (c) 2009 - Mozy, Inc.
  4. #include <stdexcept>
  5. #include <string>
  6. #include <vector>
  7. #include <boost/shared_ptr.hpp>
  8. namespace Mordor {
  9. struct Buffer;
  10. class Stream;
  11. class RagelParser
  12. {
  13. public:
  14. virtual ~RagelParser() {}
  15. // Complete parsing
  16. size_t run(const void *buffer, size_t length);
  17. size_t run(const char *string);
  18. size_t run(const std::string &string);
  19. size_t run(const Buffer &buffer);
  20. unsigned long long run(Stream &stream);
  21. unsigned long long run(boost::shared_ptr<Stream> stream) { return run(*stream); }
  22. // Partial parsing
  23. virtual void init();
  24. size_t run(const void *buffer, size_t length, bool isEof);
  25. virtual bool complete() const { return final(); }
  26. virtual bool final() const = 0;
  27. virtual bool error() const = 0;
  28. protected:
  29. virtual void exec() = 0;
  30. virtual const char *earliestPointer() const;
  31. virtual void adjustPointers(ptrdiff_t offset);
  32. protected:
  33. // Ragel state
  34. int cs;
  35. const char *p, *pe, *eof, *mark;
  36. std::string m_fullString;
  37. };
  38. class RagelParserWithStack : public RagelParser
  39. {
  40. protected:
  41. void prepush();
  42. void postpop();
  43. protected:
  44. // Ragel state
  45. std::vector<int> stack;
  46. size_t top;
  47. };
  48. }
  49. #endif