19
19
#ifndef __scan_buffer_h__
20
20
#define __scan_buffer_h__
27
typedef enum { STATE_END, STATE_ERROR, STATE_OK } State;
29
typedef enum { STATE_NEW, STATE_END, STATE_ERROR, STATE_OK } State;
32
int _token; // start position of current token
33
int _pos; // current position (in token; _pos >= _token && pos < filled)
34
char *_buffer; // token to the buffer that contains all input characters
35
int _buff_size; // size of the input buffer
39
ScanBuffer () : _state (STATE_NEW) {}
41
// init buffer to directly scan from a string
42
void init (const char *str, int l = 0);
29
virtual ~ScanBuffer () {}
31
virtual char next () = 0;
32
virtual char *token () = 0;
33
virtual int len () const = 0;
34
virtual void reset () = 0;
35
virtual void retry () = 0;
36
virtual void accept (int len) = 0;
37
virtual void more (int len) = 0;
38
virtual State state () const = 0;
44
char next () { return _buffer[_pos++]; }
45
char lookahead () { return _buffer[_pos]; }
46
char *token () const { return _buffer + _token; }
47
int len () const { return _pos - _token; }
48
void reset () { _token = _pos = 0; }
49
void retry () { _pos = _token; }
50
void accept (int len) {
54
void more (int len) { _pos = _token + len; }
56
if (_state == STATE_OK && _pos >= _buff_size)