| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
#ifndef _CST_TOKENSTREAM_H__ |
| 41 |
#define _CST_TOKENSTREAM_H__ |
| 42 |
|
| 43 |
#include "cst_alloc.h" |
| 44 |
#include "cst_string.h" |
| 45 |
#include "cst_file.h" |
| 46 |
|
| 47 |
typedef struct cst_tokenstream_struct { |
| 48 |
cst_file fd; |
| 49 |
int file_pos; |
| 50 |
int line_number; |
| 51 |
cst_string *string_buffer; |
| 52 |
|
| 53 |
int current_char; |
| 54 |
|
| 55 |
int token_pos; |
| 56 |
int ws_max; |
| 57 |
cst_string *whitespace; |
| 58 |
int prep_max; |
| 59 |
cst_string *prepunctuation; |
| 60 |
int token_max; |
| 61 |
cst_string *token; |
| 62 |
int postp_max; |
| 63 |
cst_string *postpunctuation; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
const cst_string *p_whitespacesymbols; |
| 68 |
const cst_string *p_singlecharsymbols; |
| 69 |
const cst_string *p_prepunctuationsymbols; |
| 70 |
const cst_string *p_postpunctuationsymbols; |
| 71 |
|
| 72 |
cst_string charclass[256]; |
| 73 |
} cst_tokenstream; |
| 74 |
|
| 75 |
#define TS_CHARCLASS_NONE 0 |
| 76 |
#define TS_CHARCLASS_WHITESPACE 2 |
| 77 |
#define TS_CHARCLASS_SINGLECHAR 4 |
| 78 |
#define TS_CHARCLASS_PREPUNCT 8 |
| 79 |
#define TS_CHARCLASS_POSTPUNCT 16 |
| 80 |
#define TS_CHARCLASS_QUOTE 32 |
| 81 |
|
| 82 |
#define ts_charclass(C,CLASS,TS) ((TS)->charclass[(unsigned char)C] & CLASS) |
| 83 |
|
| 84 |
extern const cst_string * const cst_ts_default_whitespacesymbols; |
| 85 |
extern const cst_string * const cst_ts_default_prepunctuationsymbols; |
| 86 |
extern const cst_string * const cst_ts_default_postpunctuationsymbols; |
| 87 |
extern const cst_string * const cst_ts_default_singlecharsymbols; |
| 88 |
|
| 89 |
|
| 90 |
cst_tokenstream *ts_open(const char *filename, |
| 91 |
const cst_string *whitespacesymbols, |
| 92 |
const cst_string *singlecharsymbols, |
| 93 |
const cst_string *prepunctsymbols, |
| 94 |
const cst_string *postpunctsymbols); |
| 95 |
cst_tokenstream *ts_open_string(const cst_string *string, |
| 96 |
const cst_string *whitespacesymbols, |
| 97 |
const cst_string *singlecharsymbols, |
| 98 |
const cst_string *prepunctsymbols, |
| 99 |
const cst_string *postpunctsymbols); |
| 100 |
void ts_close(cst_tokenstream *ts); |
| 101 |
|
| 102 |
int ts_eof(cst_tokenstream *ts); |
| 103 |
const cst_string *ts_get(cst_tokenstream *ts); |
| 104 |
|
| 105 |
const cst_string *ts_get_quoted_token(cst_tokenstream *ts, |
| 106 |
char quote, |
| 107 |
char escape); |
| 108 |
|
| 109 |
void set_charclasses(cst_tokenstream *ts, |
| 110 |
const cst_string *whitespace, |
| 111 |
const cst_string *singlecharsymbols, |
| 112 |
const cst_string *prepunctuation, |
| 113 |
const cst_string *postpunctuation); |
| 114 |
|
| 115 |
int ts_read(void *buff, int size, int num, cst_tokenstream *ts); |
| 116 |
|
| 117 |
int ts_set_stream_pos(cst_tokenstream *ts,int pos); |
| 118 |
int ts_get_stream_pos(cst_tokenstream *ts); |
| 119 |
|
| 120 |
#endif |