40 #ifndef __EST_TOKEN_H__
41 #define __EST_TOKEN_H__
47 #include "EST_String.h"
48 #include "EST_common.h"
52 extern const EST_String EST_Token_Default_WhiteSpaceChars;
54 extern const EST_String EST_Token_Default_SingleCharSymbols;
56 extern const EST_String EST_Token_Default_PunctuationSymbols;
58 extern const EST_String EST_Token_Default_PrePunctuationSymbols;
92 void init() {p_quoted=linenum=linepos=p_filepos=0;}
99 void set_token(
const char *p) { pname = p; }
103 void set_whitespace(
const char *p) { space = p; }
107 void set_punctuation(
const char *p) { punc = p; }
111 void set_prepunctuation(
const char *p) { prepunc = p; }
113 const EST_String &whitespace() {
return space; }
115 const EST_String &punctuation() {
return punc; }
117 const EST_String &prepunctuation() {
return prepunc; }
121 const EST_String &string()
const {
return String(); }
132 int Int(
bool &valid)
const {
return String().Int(valid); }
133 int Int()
const {
return String().Int(); }
134 int I(
bool &valid)
const {
return Int(valid); }
135 int I()
const {
return Int(); }
136 operator int()
const {
return Int(); }
141 long Long(
bool &valid)
const {
return String().Long(valid); }
142 long Long()
const {
return String().Long(); }
143 long L(
bool &valid)
const {
return Long(valid); }
144 long L()
const {
return Long(); }
145 operator long()
const {
return Long(); }
150 float Float(
bool &valid)
const {
return String().Float(valid); }
151 float Float()
const {
return String().Float(); }
152 float F(
bool &valid)
const {
return Float(valid); }
153 float F()
const {
return Float(); }
154 operator float()
const {
return Float(); }
159 double Double(
bool &valid)
const {
return String().Double(valid); }
160 double Double()
const {
return String().Double(); }
161 double D(
bool &valid)
const {
return Double(valid); }
162 double D()
const {
return Double(); }
163 operator double()
const {
return Double(); }
176 void set_row(
int r) { linenum = r; }
178 void set_col(
int c) { linepos = c; }
186 int row(
void)
const {
return linenum; }
188 int col(
void)
const {
return linepos; }
196 friend ostream& operator << (ostream& s,
const EST_Token &p);
203 int operator == (
const EST_String &a) {
return (pname == a); }
205 int operator != (
const EST_String &a) {
return (pname != a); }
207 int operator == (
const char *a) {
return (strcmp(pname,a)==0); }
209 int operator != (
const char *a) {
return (strcmp(pname,a)!=0); }
212 enum EST_tokenstream_type {tst_none, tst_file, tst_pipe, tst_string, tst_istream};
242 EST_tokenstream_type type;
267 void default_values(
void);
294 inline int getch_internal();
295 inline int peekch_internal();
296 inline int getpeeked_internal();
306 int open(FILE *ofp,
int close_when_finished);
308 int open(istream &newis);
324 {
return must_get(expected, &ok); }
326 {
return must_get(expected, (
bool *)NULL); }
334 {
if (!peeked_tokp)
get();
335 peeked_tokp = TRUE;
return current_tok; }
337 int fread(
void *buff,
int size,
int nitems);
343 { WhiteSpaceChars = ws; p_table_wrong=1;}
346 { SingleCharSymbols = sc; p_table_wrong=1;}
349 { PunctuationSymbols = ps; p_table_wrong=1;}
352 { PrePunctuationSymbols = ps; p_table_wrong=1;}
354 void set_quotes(
char q,
char e) { quotes = TRUE; quote = q; escape = e; p_table_wrong=1;}
364 {
return (eof_flag || ((!quotes) && (peek() ==
""))); }
368 int filepos(
void)
const {
return (type == tst_string) ? pos : p_filepos; }
370 int tell(
void)
const {
return filepos(); }
372 int seek(
int position);
398 #endif // __EST_TOKEN_H__
void set_WhiteSpaceChars(const EST_String &ws)
set which characters are to be treated as whitespace
int row(void) const
Line number in original EST_TokenStream.
FILE * filedescriptor()
For the people who need the actual description (if possible)
void set_prepunctuation(const EST_String &p)
set prepunction
EST_String lstring()
Return lower case version of token name.
void set_SingleCharSymbols(const EST_String &sc)
set which characters are to be treated as single character symbols
int tell(void) const
tell, synonym for filepos
const EST_String filename() const
The originating filename (if there is one)
int quoted() const
TRUE is token was quoted.
int quoted_mode(void)
query quote mode
void set_punctuation(const EST_String &p)
set (post) punctuation of token.
void set_PrePunctuationSymbols(const EST_String &ps)
set which characters are to be treated as (post) punctuation
void set_PunctuationSymbols(const EST_String &ps)
set which characters are to be treated as (post) punctuation
void set_token(const EST_String &p)
set token from a string
int linenum(void) const
returns line number of EST_TokenStream
const EST_String & S() const
Access token as a string.
void set_filepos(int c)
Set file position in original EST_TokenStream.
int col(void) const
Line position in original EST_TokenStream.
EST_Token & peek(void)
peek at next token
int filepos(void) const
file position in original EST_TokenStream.
EST_String ustring()
Return upper case version of token name.
void set_quotes(char q, char e)
set characters to be used as quotes and escape, and set quote mode
int filepos(void) const
current file position in EST_TokenStream
const EST_String & String() const
Access token as a string.
void set_whitespace(const EST_String &p)
set whitespace of token.
void set_quoted(int q)
Note that this token was quoted (or not)