Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef TOKENREADER_H
  8. #define TOKENREADER_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "tier0/basetypes.h"
  13. #include "tier2/utlstreambuffer.h"
  14. #include <assert.h>
  15. typedef enum
  16. {
  17. TOKENSTRINGTOOLONG = -4,
  18. TOKENERROR = -3,
  19. TOKENNONE = -2,
  20. TOKENEOF = -1,
  21. OPERATOR,
  22. INTEGER,
  23. STRING,
  24. IDENT
  25. } trtoken_t;
  26. #define IsToken(s1, s2) !strcmpi(s1, s2)
  27. #define MAX_TOKEN 128 + 1
  28. #define MAX_IDENT 64 + 1
  29. #define MAX_STRING 128 + 1
  30. class TokenReader
  31. {
  32. public:
  33. TokenReader();
  34. bool Open(const char *pszFilename);
  35. trtoken_t NextToken(char *pszStore, int nSize);
  36. trtoken_t NextTokenDynamic(char **ppszStore);
  37. void Close();
  38. void IgnoreTill(trtoken_t ttype, const char *pszToken);
  39. void Stuff(trtoken_t ttype, const char *pszToken);
  40. bool Expecting(trtoken_t ttype, const char *pszToken);
  41. const char *Error(char *error, ...);
  42. trtoken_t PeekTokenType(char* = NULL, int maxlen = 0);
  43. inline int GetErrorCount(void);
  44. private:
  45. trtoken_t GetString(char *pszStore, int nSize);
  46. bool SkipWhiteSpace(void);
  47. CUtlStreamBuffer m_file;
  48. int m_nLine;
  49. int m_nErrorCount;
  50. char m_szFilename[128];
  51. char m_szStuffed[128];
  52. bool m_bStuffed;
  53. trtoken_t m_eStuffed;
  54. };
  55. //-----------------------------------------------------------------------------
  56. // Purpose: Returns the total number of parsing errors since this file was opened.
  57. //-----------------------------------------------------------------------------
  58. int TokenReader::GetErrorCount(void)
  59. {
  60. return(m_nErrorCount);
  61. }
  62. #endif // TOKENREADER_H