sqlexer.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* see copyright notice in squirrel.h */
  2. #ifndef _SQLEXER_H_
  3. #define _SQLEXER_H_
  4. #ifdef SQUNICODE
  5. typedef SQChar LexChar;
  6. #else
  7. typedef unsigned char LexChar;
  8. #endif
  9. struct SQLexerData
  10. {
  11. SQInteger curtoken;
  12. SQInteger prevtoken;
  13. SQInteger currentline;
  14. SQInteger currentcolumn;
  15. SQInteger lasttokenline;
  16. SQInteger lasttokencolumn;
  17. const SQChar *svalue;
  18. sqvector<SQChar> longstr;
  19. SQInteger nvalue;
  20. SQFloat fvalue;
  21. LexChar currdata;
  22. SQInteger readcount;
  23. SQBool reached_eof;
  24. SQBool isCharacter;
  25. SQChar lasterror[256];
  26. SQLexerData()
  27. {
  28. clear();
  29. }
  30. SQLexerData(SQLexerData *src)
  31. {
  32. copy(src);
  33. }
  34. void copy(SQLexerData *src)
  35. {
  36. curtoken = src->curtoken;
  37. reached_eof = src->reached_eof;
  38. isCharacter = src->isCharacter;
  39. prevtoken = src->prevtoken;
  40. currentline = src->currentline;
  41. currentcolumn = src->currentcolumn;
  42. lasttokenline = src->lasttokenline;
  43. lasttokencolumn = src->lasttokencolumn;
  44. longstr.resize(src->longstr.size());
  45. memcpy(longstr._vals, src->longstr._vals, src->longstr.size());
  46. svalue = &longstr[0];
  47. nvalue = src->nvalue;
  48. fvalue = src->fvalue;
  49. currdata = src->currdata;
  50. readcount = src->readcount;
  51. scstrcpy(lasterror, src->lasterror);
  52. }
  53. void clear()
  54. {
  55. curtoken = 0;
  56. reached_eof = SQFalse;
  57. isCharacter = SQFalse;
  58. prevtoken = -1;
  59. currentline = 0;
  60. currentcolumn = 0;
  61. lasttokenline = 0;
  62. lasttokencolumn = 0;
  63. longstr.resize(0);
  64. svalue = NULL;
  65. nvalue = 0;
  66. fvalue = 0.0;
  67. currdata = 0;
  68. lasterror[0] = '\0';
  69. readcount = 0;
  70. }
  71. };
  72. struct SQLexer
  73. {
  74. SQLexer();
  75. virtual ~SQLexer();
  76. SQInteger Init(SQSharedState *ss,SQLEXREADFUNC rg,SQUserPointer up,
  77. CompilerErrorFunc efunc,void *ed, SQBool want_comments=SQFalse,
  78. SQBool want_stringSingleAndDoubleQuotes=SQFalse);
  79. SQInteger ResetReader(SQLEXREADFUNC rg, SQUserPointer up, SQInteger line);
  80. virtual SQTable * GetKeywords();
  81. SQInteger Error(const SQChar *err, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
  82. //dontThrowIntegerOverflow for when in 32bits parsing 64bits integer inside excluded ifdef
  83. SQInteger Lex(bool dontThrowIntegerOverflow=false);
  84. SQInteger LookaheadLex();
  85. const SQChar *Tok2Str(SQInteger tok);
  86. const SQChar *GetTokenName(SQInteger tk_code);
  87. protected:
  88. SQInteger GetIDType(const SQChar *s,SQInteger len);
  89. SQInteger ReadString(SQInteger ndelim,bool verbatim);
  90. SQInteger ReadNumber(SQInteger startChar=0, bool dontThrowIntegerOverflow=false);
  91. SQInteger LexBlockComment();
  92. SQInteger LexLineComment();
  93. SQInteger ReadID();
  94. SQInteger Next();
  95. #ifdef SQUNICODE
  96. #if WCHAR_SIZE == 2
  97. SQInteger AddUTF16(SQUnsignedInteger ch);
  98. #endif
  99. #else
  100. SQInteger AddUTF8(SQUnsignedInteger ch);
  101. #endif
  102. SQInteger ProcessStringHexEscape(SQChar *dest, SQInteger maxdigits);
  103. SQLexerData _data, _data_lookahead;
  104. SQTable *_keywords;
  105. public:
  106. SQLexerData *data;
  107. SQLEXREADFUNC _readf;
  108. SQUserPointer _up;
  109. SQSharedState *_sharedstate;
  110. CompilerErrorFunc _errfunc;
  111. void *_errtarget;
  112. SQBool _want_comments;
  113. SQBool _want_stringSingleAndDoubleQuotes;
  114. };
  115. #endif