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;
90 void init() {p_quoted=linenum=linepos=p_filepos=0;}
97 void set_token(
const char *p) { pname = p; }
101 void set_whitespace(
const char *p) { space = p; }
105 void set_punctuation(
const char *p) { punc = p; }
109 void set_prepunctuation(
const char *p) { prepunc = p; }
111 const EST_String &whitespace() {
return space; }
113 const EST_String &punctuation() {
return punc; }
115 const EST_String &prepunctuation() {
return prepunc; }
119 const EST_String &string()
const {
return String(); }
130 int Int(
bool &valid)
const {
return String().Int(valid); }
131 int Int()
const {
return String().Int(); }
132 int I(
bool &valid)
const {
return Int(valid); }
133 int I()
const {
return Int(); }
134 operator int()
const {
return Int(); }
139 long Long(
bool &valid)
const {
return String().Long(valid); }
140 long Long()
const {
return String().Long(); }
141 long L(
bool &valid)
const {
return Long(valid); }
142 long L()
const {
return Long(); }
143 operator long()
const {
return Long(); }
148 float Float(
bool &valid)
const {
return String().Float(valid); }
149 float Float()
const {
return String().Float(); }
150 float F(
bool &valid)
const {
return Float(valid); }
151 float F()
const {
return Float(); }
152 operator float()
const {
return Float(); }
157 double Double(
bool &valid)
const {
return String().Double(valid); }
158 double Double()
const {
return String().Double(); }
159 double D(
bool &valid)
const {
return Double(valid); }
160 double D()
const {
return Double(); }
161 operator double()
const {
return Double(); }
172 void set_row(
int r) { linenum = r; }
174 void set_col(
int c) { linepos = c; }
182 int row(
void)
const {
return linenum; }
184 int col(
void)
const {
return linepos; }
192 friend ostream& operator << (ostream& s,
const EST_Token &p);
199 int operator == (
const EST_String &a) {
return (pname == a); }
201 int operator != (
const EST_String &a) {
return (pname != a); }
203 int operator == (
const char *a) {
return (strcmp(pname,a)==0); }
205 int operator != (
const char *a) {
return (strcmp(pname,a)!=0); }
208 enum EST_tokenstream_type {tst_none, tst_file, tst_pipe, tst_string, tst_istream};
237 EST_tokenstream_type type;
262 void default_values(
void);
289 inline int getch_internal();
290 inline int peekch_internal();
291 inline int getpeeked_internal();
301 int open(FILE *ofp,
int close_when_finished);
303 int open(istream &newis);
319 {
return must_get(expected, &ok); }
321 {
return must_get(expected, (
bool *)NULL); }
330 int fread(
void *buff,
int size,
int nitems) EST_WARN_UNUSED_RESULT;
336 { WhiteSpaceChars = ws; p_table_wrong=1;}
339 { SingleCharSymbols = sc; p_table_wrong=1;}
342 { PunctuationSymbols = ps; p_table_wrong=1;}
345 { PrePunctuationSymbols = ps; p_table_wrong=1;}
347 void set_quotes(
char q,
char e) { quotes = TRUE; quote = q; escape = e; p_table_wrong=1;}
357 {
return (eof_flag || ((!quotes) && (peek() ==
""))); }
361 int filepos(
void)
const {
return (type == tst_string) ? pos : p_filepos; }
363 int tell(
void)
const {
return filepos(); }
365 int seek(
int position);
391 #endif // __EST_TOKEN_H__ void set_WhiteSpaceChars(const EST_String &ws)
set which characters are to be treated as whitespace
int tell(void) const
tell, synonym for filepos
FILE * filedescriptor()
For the people who need the actual description (if possible)
int linenum(void) const
returns line number of {EST_TokenStream}
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 filepos(void) const
current file position in {EST_TokenStream}
const EST_String filename() const
The originating filename (if there is one)
int col(void) const
Line position in original {EST_TokenStream}.
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
int quoted() const
TRUE is token was quoted.
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
void set_filepos(int c)
Set file position in original {EST_TokenStream}.
const EST_String & String() const
Access token as a string.
const EST_String & S() const
Access token as a string.
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 row(void) const
Line number in original {EST_TokenStream}.
int filepos(void) const
file position in original {EST_TokenStream}.
void set_whitespace(const EST_String &p)
set whitespace of token.
void set_quoted(int q)
Note that this token was quoted (or not)