~stewart/drizzle/remove-unused-row-type-in-table-message

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSTokenStream.h

  • Committer: Stewart Smith
  • Date: 2010-07-20 16:35:49 UTC
  • mfrom: (1638.1.28 drizzle)
  • Revision ID: stewart@flamingspork.com-20100720163549-zgcsmroyt0njr92d
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
2
 
 *
3
 
 * PrimeBase Media Stream for MySQL
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published by
7
 
 * the Free Software Foundation; either version 2 of the License, or
8
 
 * (at your option) any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
 
 *
19
 
 * Original author: Paul McCullagh (H&G2JCtL)
20
 
 * Continued development: Barry Leslie
21
 
 *
22
 
 * 2007-06-08
23
 
 *
24
 
 * CORE SYSTEM:
25
 
 * A token stream. The tokens are identified in the same
26
 
 * manner as the UNIX/DOS command line.
27
 
 *
28
 
 * This basically means that all tokens must be sepparated
29
 
 * by at least one space.
30
 
 *
31
 
 * The following punctuation are considered tokens or
32
 
 * have special meaning:
33
 
 *
34
 
 * =[]!#$%&*()"|;'\<>?/~`
35
 
 *
36
 
 * EOL and EOF are also tokens.
37
 
 *
38
 
 * If they appear in words they must be escaped using \,
39
 
 * or the word must be place in quotes " or '.
40
 
 *
41
 
 * The following punctuation can be part of words:
42
 
 *
43
 
 * -{}@^_+:,.
44
 
 *
45
 
 * Words next to each other, without a token or space
46
 
 * between are considered one word, e.g.:
47
 
 *
48
 
 * "hello""world" == helloworld
49
 
 *
50
 
 * Quotes in a quoted string are not allowed, e.g., to
51
 
 * write "it's mine" in single quotes it must be written
52
 
 * as: 'it'\''s mine'
53
 
 *
54
 
 * Characters can be encoded in octal form as follows \xxx where
55
 
 * 0 <= x <= 7
56
 
 *
57
 
 */
58
 
 
59
 
#ifndef __CSTOKENSTREAM_H__
60
 
#define __CSTOKENSTREAM_H__
61
 
 
62
 
#include <stdlib.h>
63
 
#include <string.h>
64
 
 
65
 
#include "CSDefs.h"
66
 
#include "CSStream.h"
67
 
#include "CSStorage.h"
68
 
#include "CSPath.h"
69
 
#include "CSString.h"
70
 
 
71
 
using namespace std;
72
 
 
73
 
#define CS_TKN_EQ               0               // =
74
 
#define CS_TKN_OSQR             1               // [
75
 
#define CS_TKN_CSQR             2               // ]
76
 
#define CS_TKN_BANG             3               // !
77
 
#define CS_TKN_HASH             4               // #
78
 
#define CS_TKN_DOLLAR   5               // $
79
 
#define CS_TKN_PERC             6               // %
80
 
#define CS_TKN_AMPER    7               // &
81
 
#define CS_TKN_STAR             8               // *
82
 
#define CS_TKN_ORND             9               // (
83
 
#define CS_TKN_CRND             10              // )
84
 
#define CS_TKN_PIPE             11              // |
85
 
#define CS_TKN_SEMIC    12              // ;
86
 
#define CS_TKN_LT               13              // <
87
 
#define CS_TKN_GT               14              // >
88
 
#define CS_TKN_QMARK    15              // ?
89
 
#define CS_TKN_TILDA    16              // ~
90
 
#define CS_TKN_EOS              17
91
 
#define CS_TKN_EOL              18
92
 
#define CS_TKN_TEXT             19
93
 
 
94
 
class CSToken : public CSObject {
95
 
public:
96
 
        /* Note this order matches the token numbers above!! */
97
 
        static const char *singletons;
98
 
 
99
 
        CSToken(int type) { iType = type; }
100
 
        virtual ~CSToken() { }
101
 
 
102
 
        /*
103
 
         * Returns true if this token is the
104
 
         * EOS token.
105
 
         */
106
 
        bool isEOF() const { return iType == CS_TKN_EOS; }
107
 
        
108
 
        /*
109
 
         * Returns true if this token is the
110
 
         * EOL token.
111
 
         */
112
 
        bool isEOL() const { return iType == CS_TKN_EOL; }
113
 
 
114
 
        /*
115
 
         * Return the text of a token as a printable string.
116
 
         */
117
 
        virtual CSString *getString() = 0;
118
 
 
119
 
        virtual const char *getCString() = 0;
120
 
 
121
 
        virtual int getInteger() = 0;
122
 
 
123
 
        /*
124
 
         * Return true of the token matches the given text.
125
 
         */
126
 
        virtual bool isEqual(const char *text) = 0;
127
 
 
128
 
        /*
129
 
         * Return the text of the token as a file system
130
 
         * path.
131
 
         */
132
 
        //virtual CSPath *getPath() = 0;
133
 
 
134
 
private:
135
 
        int iType;
136
 
};
137
 
 
138
 
class UXToken : public CSToken {
139
 
public:
140
 
        UXToken(int type, const char *text): CSToken(type) { iText.append(text); }
141
 
        UXToken(int type, char ch): CSToken(type) { iText.append(ch); }
142
 
        virtual ~UXToken() { }
143
 
 
144
 
        virtual CSString *getString() { return CSString::newString(iText.getCString()); }
145
 
 
146
 
        virtual const char *getCString() { return iText.getCString(); }
147
 
 
148
 
        virtual int getInteger() { return atoi(iText.getCString()); }
149
 
 
150
 
        //virtual CSPath *getPath();
151
 
 
152
 
        virtual bool isEqual(const char *text) { return(strcmp(iText.getCString(), text) == 0); };
153
 
 
154
 
private:
155
 
        CSStringBuffer iText;
156
 
};
157
 
 
158
 
class CSTokenList : public CSVector {
159
 
public:
160
 
        CSTokenList():CSVector(2) { }
161
 
        virtual ~CSTokenList() { }
162
 
 
163
 
        CSToken *takeFront() { return (CSToken *) take(0); }
164
 
 
165
 
        CSToken *getAt(uint32_t idx) { return (CSToken *) get(idx); }
166
 
 
167
 
        CSToken *getFront() { return (CSToken *) get(0); }
168
 
};
169
 
 
170
 
class CSTokenStream : public CSObject {
171
 
public:
172
 
        CSTokenStream(): iStream(NULL), iLine(0), iChar(-2) { }
173
 
 
174
 
        virtual ~CSTokenStream();
175
 
 
176
 
        /*
177
 
         * Open assumes the given stream is already referenced!
178
 
         *
179
 
         * When an error occurs an line number will be given, unless the
180
 
         * line number is set to 0.
181
 
         *
182
 
         * If set to zero, the line number will also not be incremented
183
 
         * when a new line is encountered.
184
 
         */
185
 
        virtual void open(CSInputStream *stream, uint32_t line);
186
 
 
187
 
        virtual void close();
188
 
        
189
 
        virtual void nextChar();
190
 
 
191
 
        virtual CSToken *nextToken() { return NULL; }
192
 
 
193
 
        friend class UXTokenStream;
194
 
 
195
 
        static CSTokenStream *newTokenStream(CSInputStream *stream, uint32_t line);
196
 
 
197
 
private:
198
 
        CSInputStream *iStream;
199
 
        
200
 
        uint32_t iLine;
201
 
 
202
 
        int iChar;
203
 
};
204
 
 
205
 
class UXTokenStream : public CSTokenStream {
206
 
public:
207
 
        UXTokenStream(): CSTokenStream() { }
208
 
 
209
 
        virtual ~UXTokenStream() { }
210
 
 
211
 
        virtual CSToken *nextToken();
212
 
 
213
 
        virtual CSToken *newToken(int type, const char *text);
214
 
 
215
 
        virtual CSToken *newToken(int type, char ch);
216
 
 
217
 
        static CSTokenStream *newTokenStream(CSInputStream *stream, uint32_t line);
218
 
private:
219
 
};
220
 
 
221
 
#endif