as_tokenizer.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2013 Andreas Jonsson
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any
  6. damages arising from the use of this software.
  7. Permission is granted to anyone to use this software for any
  8. purpose, including commercial applications, and to alter it and
  9. redistribute it freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you
  11. must not claim that you wrote the original software. If you use
  12. this software in a product, an acknowledgment in the product
  13. documentation would be appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and
  15. must not be misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source
  17. distribution.
  18. The original version of this library can be located at:
  19. http://www.angelcode.com/angelscript/
  20. Andreas Jonsson
  21. andreas@angelcode.com
  22. */
  23. //
  24. // as_tokenizer.cpp
  25. //
  26. // This class identifies tokens from the script code
  27. //
  28. #ifndef AS_TOKENIZER_H
  29. #define AS_TOKENIZER_H
  30. #include "as_config.h"
  31. #include "as_tokendef.h"
  32. #include "as_map.h"
  33. #include "as_string.h"
  34. BEGIN_AS_NAMESPACE
  35. class asCTokenizer
  36. {
  37. public:
  38. eTokenType GetToken(const char *source, size_t sourceLength, size_t *tokenLength, asETokenClass *tc = 0) const;
  39. static const char *GetDefinition(int tokenType);
  40. protected:
  41. friend class asCScriptEngine;
  42. asCTokenizer();
  43. ~asCTokenizer();
  44. asETokenClass ParseToken(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const;
  45. bool IsWhiteSpace(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const;
  46. bool IsComment(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const;
  47. bool IsConstant(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const;
  48. bool IsKeyWord(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const;
  49. bool IsIdentifier(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const;
  50. bool IsDigitInRadix(char ch, int radix) const;
  51. const asCScriptEngine *engine;
  52. const sTokenWord **keywordTable[256];
  53. };
  54. END_AS_NAMESPACE
  55. #endif