Team Fortress 2 Source Code as on 22/4/2020
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.

99 lines
2.0 KiB

  1. //========= Copyright 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. #ifdef _WIN32
  14. #pragma warning(push, 1)
  15. #pragma warning(disable:4701 4702 4530)
  16. #endif
  17. #undef min
  18. #undef max
  19. #include <fstream>
  20. #include "valve_minmax_on.h"
  21. #ifdef _WIN32
  22. #pragma warning(pop)
  23. #endif
  24. #include <assert.h>
  25. typedef enum
  26. {
  27. TOKENSTRINGTOOLONG = -4,
  28. TOKENERROR = -3,
  29. TOKENNONE = -2,
  30. TOKENEOF = -1,
  31. OPERATOR,
  32. INTEGER,
  33. STRING,
  34. IDENT
  35. } trtoken_t;
  36. #define IsToken(s1, s2) !strcmpi(s1, s2)
  37. #define MAX_TOKEN 128 + 1
  38. #define MAX_IDENT 64 + 1
  39. #define MAX_STRING 128 + 1
  40. class TokenReader : private std::ifstream
  41. {
  42. public:
  43. TokenReader();
  44. bool Open(const char *pszFilename);
  45. trtoken_t NextToken(char *pszStore, int nSize);
  46. trtoken_t NextTokenDynamic(char **ppszStore);
  47. void Close();
  48. void IgnoreTill(trtoken_t ttype, const char *pszToken);
  49. void Stuff(trtoken_t ttype, const char *pszToken);
  50. bool Expecting(trtoken_t ttype, const char *pszToken);
  51. const char *Error(char *error, ...);
  52. trtoken_t PeekTokenType(char* = NULL, int maxlen = 0);
  53. inline int GetErrorCount(void);
  54. private:
  55. // compiler can't generate an assignment operator since descended from std::ifstream
  56. inline TokenReader(TokenReader const &);
  57. inline int operator=(TokenReader const &);
  58. trtoken_t GetString(char *pszStore, int nSize);
  59. bool SkipWhiteSpace(void);
  60. int m_nLine;
  61. int m_nErrorCount;
  62. char m_szFilename[128];
  63. char m_szStuffed[128];
  64. bool m_bStuffed;
  65. trtoken_t m_eStuffed;
  66. };
  67. //-----------------------------------------------------------------------------
  68. // Purpose: Returns the total number of parsing errors since this file was opened.
  69. //-----------------------------------------------------------------------------
  70. int TokenReader::GetErrorCount(void)
  71. {
  72. return(m_nErrorCount);
  73. }
  74. #endif // TOKENREADER_H