1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
3
* PrimeBase Media Stream for MySQL
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.
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.
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
19
* Original author: Paul McCullagh (H&G2JCtL)
20
* Continued development: Barry Leslie
25
* A token stream. The tokens are identified in the same
26
* manner as the UNIX/DOS command line.
28
* This basically means that all tokens must be sepparated
29
* by at least one space.
31
* The following punctuation are considered tokens or
32
* have special meaning:
34
* =[]!#$%&*()"|;'\<>?/~`
36
* EOL and EOF are also tokens.
38
* If they appear in words they must be escaped using \,
39
* or the word must be place in quotes " or '.
41
* The following punctuation can be part of words:
45
* Words next to each other, without a token or space
46
* between are considered one word, e.g.:
48
* "hello""world" == helloworld
50
* Quotes in a quoted string are not allowed, e.g., to
51
* write "it's mine" in single quotes it must be written
54
* Characters can be encoded in octal form as follows \xxx where
59
#ifndef __CSTOKENSTREAM_H__
60
#define __CSTOKENSTREAM_H__
67
#include "CSStorage.h"
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 // ~
92
#define CS_TKN_TEXT 19
94
class CSToken : public CSObject {
96
/* Note this order matches the token numbers above!! */
97
static const char *singletons;
99
CSToken(int type) { iType = type; }
100
virtual ~CSToken() { }
103
* Returns true if this token is the
106
bool isEOF() const { return iType == CS_TKN_EOS; }
109
* Returns true if this token is the
112
bool isEOL() const { return iType == CS_TKN_EOL; }
115
* Return the text of a token as a printable string.
117
virtual CSString *getString() = 0;
119
virtual const char *getCString() = 0;
121
virtual int getInteger() = 0;
124
* Return true of the token matches the given text.
126
virtual bool isEqual(const char *text) = 0;
129
* Return the text of the token as a file system
132
//virtual CSPath *getPath() = 0;
138
class UXToken : public CSToken {
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() { }
144
virtual CSString *getString() { return CSString::newString(iText.getCString()); }
146
virtual const char *getCString() { return iText.getCString(); }
148
virtual int getInteger() { return atoi(iText.getCString()); }
150
//virtual CSPath *getPath();
152
virtual bool isEqual(const char *text) { return(strcmp(iText.getCString(), text) == 0); };
155
CSStringBuffer iText;
158
class CSTokenList : public CSVector {
160
CSTokenList():CSVector(2) { }
161
virtual ~CSTokenList() { }
163
CSToken *takeFront() { return (CSToken *) take(0); }
165
CSToken *getAt(u_int idx) { return (CSToken *) get(idx); }
167
CSToken *getFront() { return (CSToken *) get(0); }
170
class CSTokenStream : public CSObject {
172
CSTokenStream(): iStream(NULL), iLine(0), iChar(-2) { }
174
virtual ~CSTokenStream();
177
* Open assumes the given stream is already referenced!
179
* When an error occurs an line number will be given, unless the
180
* line number is set to 0.
182
* If set to zero, the line number will also not be incremented
183
* when a new line is encountered.
185
virtual void open(CSInputStream *stream, u_int line);
187
virtual void close();
189
virtual void nextChar();
191
virtual CSToken *nextToken() { return NULL; }
193
friend class UXTokenStream;
195
static CSTokenStream *newTokenStream(CSInputStream *stream, u_int line);
198
CSInputStream *iStream;
205
class UXTokenStream : public CSTokenStream {
207
UXTokenStream(): CSTokenStream() { }
209
virtual ~UXTokenStream() { }
211
virtual CSToken *nextToken();
213
virtual CSToken *newToken(int type, const char *text);
215
virtual CSToken *newToken(int type, char ch);
217
static CSTokenStream *newTokenStream(CSInputStream *stream, u_int line);