| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- /* see copyright notice in squirrel.h */
- #ifndef _SQLEXER_H_
- #define _SQLEXER_H_
- #ifdef SQUNICODE
- typedef SQChar LexChar;
- #else
- typedef unsigned char LexChar;
- #endif
- struct SQLexerData
- {
- SQInteger curtoken;
- SQInteger prevtoken;
- SQInteger currentline;
- SQInteger currentcolumn;
- SQInteger lasttokenline;
- SQInteger lasttokencolumn;
- const SQChar *svalue;
- sqvector<SQChar> longstr;
- SQInteger nvalue;
- SQFloat fvalue;
- LexChar currdata;
- SQInteger readcount;
- SQBool reached_eof;
- SQBool isCharacter;
- SQChar lasterror[256];
- SQLexerData()
- {
- clear();
- }
- SQLexerData(SQLexerData *src)
- {
- copy(src);
- }
- void copy(SQLexerData *src)
- {
- curtoken = src->curtoken;
- reached_eof = src->reached_eof;
- isCharacter = src->isCharacter;
- prevtoken = src->prevtoken;
- currentline = src->currentline;
- currentcolumn = src->currentcolumn;
- lasttokenline = src->lasttokenline;
- lasttokencolumn = src->lasttokencolumn;
- longstr.resize(src->longstr.size());
- memcpy(longstr._vals, src->longstr._vals, src->longstr.size());
- svalue = &longstr[0];
- nvalue = src->nvalue;
- fvalue = src->fvalue;
- currdata = src->currdata;
- readcount = src->readcount;
- scstrcpy(lasterror, src->lasterror);
- }
- void clear()
- {
- curtoken = 0;
- reached_eof = SQFalse;
- isCharacter = SQFalse;
- prevtoken = -1;
- currentline = 0;
- currentcolumn = 0;
- lasttokenline = 0;
- lasttokencolumn = 0;
- longstr.resize(0);
- svalue = NULL;
- nvalue = 0;
- fvalue = 0.0;
- currdata = 0;
- lasterror[0] = '\0';
- readcount = 0;
- }
- };
- struct SQLexer
- {
- SQLexer();
- virtual ~SQLexer();
- SQInteger Init(SQSharedState *ss,SQLEXREADFUNC rg,SQUserPointer up,
- CompilerErrorFunc efunc,void *ed, SQBool want_comments=SQFalse,
- SQBool want_stringSingleAndDoubleQuotes=SQFalse);
- SQInteger ResetReader(SQLEXREADFUNC rg, SQUserPointer up, SQInteger line);
- virtual SQTable * GetKeywords();
- SQInteger Error(const SQChar *err, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
- //dontThrowIntegerOverflow for when in 32bits parsing 64bits integer inside excluded ifdef
- SQInteger Lex(bool dontThrowIntegerOverflow=false);
- SQInteger LookaheadLex();
- const SQChar *Tok2Str(SQInteger tok);
- const SQChar *GetTokenName(SQInteger tk_code);
- protected:
- SQInteger GetIDType(const SQChar *s,SQInteger len);
- SQInteger ReadString(SQInteger ndelim,bool verbatim);
- SQInteger ReadNumber(SQInteger startChar=0, bool dontThrowIntegerOverflow=false);
- SQInteger LexBlockComment();
- SQInteger LexLineComment();
- SQInteger ReadID();
- SQInteger Next();
- #ifdef SQUNICODE
- #if WCHAR_SIZE == 2
- SQInteger AddUTF16(SQUnsignedInteger ch);
- #endif
- #else
- SQInteger AddUTF8(SQUnsignedInteger ch);
- #endif
- SQInteger ProcessStringHexEscape(SQChar *dest, SQInteger maxdigits);
- SQLexerData _data, _data_lookahead;
- SQTable *_keywords;
- public:
- SQLexerData *data;
- SQLEXREADFUNC _readf;
- SQUserPointer _up;
- SQSharedState *_sharedstate;
- CompilerErrorFunc _errfunc;
- void *_errtarget;
- SQBool _want_comments;
- SQBool _want_stringSingleAndDoubleQuotes;
- };
- #endif
|