1
/* $Id: scanner.hpp 2394 2008-12-23 17:27:53Z bennylp $ */
3
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#ifndef __PJPP_SCANNER_HPP__
21
#define __PJPP_SCANNER_HPP__
23
#include <pjlib-util/scanner.h>
24
#include <pj++/string.hpp>
37
pj_cis_buf_init(&buf_);
47
friend class Pj_Scanner;
50
Pj_Cis(Pj_Cis_Buffer *buf)
52
pj_cis_init(&buf->buf_, &cis_);
55
Pj_Cis(const Pj_Cis &rhs)
57
pj_cis_dup(&cis_, (pj_cis_t*)&rhs.cis_);
60
void add_range(int start, int end)
62
pj_cis_add_range(&cis_, start, end);
67
pj_cis_add_alpha(&cis_);
72
pj_cis_add_num(&cis_);
75
void add_str(const char *str)
77
pj_cis_add_str(&cis_, str);
80
void add_cis(const Pj_Cis &rhs)
82
pj_cis_add_cis(&cis_, &rhs.cis_);
85
void del_range(int start, int end)
87
pj_cis_del_range(&cis_, start, end);
90
void del_str(const char *str)
92
pj_cis_del_str(&cis_, str);
100
bool match(int c) const
102
return pj_cis_match(&cis_, c) != 0;
120
static void syntax_error_handler_throw_pj(pj_scanner *);
122
typedef pj_scan_state State;
124
void init(char *buf, int len, unsigned options=PJ_SCAN_AUTOSKIP_WS,
125
pj_syn_err_func_ptr callback = &syntax_error_handler_throw_pj)
127
pj_scan_init(&scanner_, buf, len, options, callback);
132
pj_scan_fini(&scanner_);
137
return pj_scan_is_eof(&scanner_);
140
int peek_char() const
142
return *scanner_.curptr;
145
int peek(const Pj_Cis *cis, Pj_String *out)
147
return pj_scan_peek(&scanner_, &cis->cis_, out);
150
int peek_n(pj_size_t len, Pj_String *out)
152
return pj_scan_peek_n(&scanner_, len, out);
155
int peek_until(const Pj_Cis *cis, Pj_String *out)
157
return pj_scan_peek_until(&scanner_, &cis->cis_, out);
160
void get(const Pj_Cis *cis, Pj_String *out)
162
pj_scan_get(&scanner_, &cis->cis_, out);
165
void get_n(unsigned N, Pj_String *out)
167
pj_scan_get_n(&scanner_, N, out);
172
return pj_scan_get_char(&scanner_);
175
void get_quote(int begin_quote, int end_quote, Pj_String *out)
177
pj_scan_get_quote(&scanner_, begin_quote, end_quote, out);
182
pj_scan_get_newline(&scanner_);
185
void get_until(const Pj_Cis *cis, Pj_String *out)
187
pj_scan_get_until(&scanner_, &cis->cis_, out);
190
void get_until_ch(int until_ch, Pj_String *out)
192
pj_scan_get_until_ch(&scanner_, until_ch, out);
195
void get_until_chr(const char *spec, Pj_String *out)
197
pj_scan_get_until_chr(&scanner_, spec, out);
200
void advance_n(unsigned N, bool skip_ws=true)
202
pj_scan_advance_n(&scanner_, N, skip_ws);
205
int strcmp(const char *s, int len)
207
return pj_scan_strcmp(&scanner_, s, len);
210
int stricmp(const char *s, int len)
212
return pj_scan_stricmp(&scanner_, s, len);
217
pj_scan_skip_whitespace(&scanner_);
220
void save_state(State *state) const
222
pj_scan_save_state(&scanner_, state);
225
void restore_state(State *state)
227
pj_scan_restore_state(&scanner_, state);
230
int get_pos_line() const
232
return scanner_.line;
235
int get_pos_col() const
237
return pj_scan_get_col(&scanner_);
245
#endif /* __PJPP_SCANNER_HPP__ */