40#ifndef __EST_TOKEN_H__
41#define __EST_TOKEN_H__
47#include "EST_String.h"
48#include "EST_common.h"
52extern const EST_String EST_Token_Default_WhiteSpaceChars;
54extern const EST_String EST_Token_Default_SingleCharSymbols;
56extern const EST_String EST_Token_Default_PunctuationSymbols;
58extern 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; }
111 const EST_String &whitespace() {
return space; }
113 const EST_String &punctuation() {
return punc; }
115 const EST_String &prepunctuation() {
return prepunc; }
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); }
208enum 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; }
365 int seek(
int position);
int restart(void)
Reset to start of file/string.
int filepos(void) const
current file position in \Ref{EST_TokenStream}
EST_Token & get()
get next token in stream
void set_SingleCharSymbols(const EST_String &sc)
set which characters are to be treated as single character symbols
EST_Token get_upto(const EST_String &s)
get up to {\tt s} in stream as a single token.
int fread(void *buff, int size, int nitems) EST_WARN_UNUSED_RESULT
Reading binary data, (don't use peek() immediately beforehand)
const EST_String filename() const
The originating filename (if there is one)
void set_PrePunctuationSymbols(const EST_String &ps)
set which characters are to be treated as (post) punctuation
~EST_TokenStream()
will close file if appropriate for type
const EST_String pos_description()
A string describing current position, suitable for error messages.
int open_string(const EST_String &newbuffer)
open a \Ref{EST_TokenStream} for string rather than a file
int linenum(void) const
returns line number of \Ref{EST_TokenStream}
void set_quotes(char q, char e)
set characters to be used as quotes and escape, and set quote mode
EST_Token get_upto_eoln(void)
get up to {\tt s} in end of line as a single token.
void set_PunctuationSymbols(const EST_String &ps)
set which characters are to be treated as (post) punctuation
EST_Token & peek(void)
peek at next token
void close(void)
Close stream.
int tell(void) const
tell, synonym for filepos
int open(const EST_String &filename)
open a \Ref{EST_TokenStream} for a file.
FILE * filedescriptor()
For the people who need the actual description (if possible)
void set_WhiteSpaceChars(const EST_String &ws)
set which characters are to be treated as whitespace
int seek(int position)
seek, reposition file pointer
int quoted_mode(void)
query quote mode
int quoted() const
TRUE is token was quoted.
EST_String ustring()
Return upper case version of token name.
int col(void) const
Line position in original \Ref{EST_TokenStream}.
const EST_String & String() const
Access token as a string.
void set_prepunctuation(const EST_String &p)
set prepunction
void set_whitespace(const EST_String &p)
set whitespace of token.
void set_punctuation(const EST_String &p)
set (post) punctuation of token.
const EST_String pos_description() const
A string describing current position, suitable for error messages.
void set_filepos(int c)
Set file position in original \Ref{EST_TokenStream}.
EST_String lstring()
Return lower case version of token name.
void set_quoted(int q)
Note that this token was quoted (or not)
int row(void) const
Line number in original \Ref{EST_TokenStream}.
const EST_String & S() const
Access token as a string.
void set_token(const EST_String &p)
set token from a string
int filepos(void) const
file position in original \Ref{EST_TokenStream}.