PageRenderTime 284ms CodeModel.GetById 173ms app.highlight 5ms RepoModel.GetById 104ms 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
 1#ifndef __MORDOR_RAGEL_H__
 2#define __MORDOR_RAGEL_H__
 3// Copyright (c) 2009 - Mozy, Inc.
 4
 5#include <stdexcept>
 6#include <string>
 7#include <vector>
 8
 9#include <boost/shared_ptr.hpp>
10
11namespace Mordor {
12
13struct Buffer;
14class Stream;
15
16class RagelParser
17{
18public:
19    virtual ~RagelParser() {}
20
21    // Complete parsing
22    size_t run(const void *buffer, size_t length);
23    size_t run(const char *string);
24    size_t run(const std::string &string);
25    size_t run(const Buffer &buffer);
26    unsigned long long run(Stream &stream);
27    unsigned long long run(boost::shared_ptr<Stream> stream) { return run(*stream); }
28
29    // Partial parsing
30    virtual void init();
31    size_t run(const void *buffer, size_t length, bool isEof);
32
33    virtual bool complete() const { return final(); }
34    virtual bool final() const = 0;
35    virtual bool error() const = 0;
36
37protected:
38    virtual void exec() = 0;
39
40    virtual const char *earliestPointer() const;
41    virtual void adjustPointers(ptrdiff_t offset);
42
43protected:
44    // Ragel state
45    int cs;
46    const char *p, *pe, *eof, *mark;
47    std::string m_fullString;
48};
49
50class RagelParserWithStack : public RagelParser
51{
52protected:
53    void prepush();
54    void postpop();
55
56protected:
57    // Ragel state
58    std::vector<int> stack;
59    size_t top;
60};
61
62}
63
64#endif