CCPUScriptLexer.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /****************************************************************************
  2. Copyright (C) 2013 Henry van Merode. All rights reserved.
  3. Copyright (c) 2015-2016 Chukong Technologies Inc.
  4. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. #ifndef __CC_PU_SCRIPT_LEXER_H__
  23. #define __CC_PU_SCRIPT_LEXER_H__
  24. #include "base/CCRef.h"
  25. #include <vector>
  26. #include <string>
  27. NS_CC_BEGIN
  28. enum{
  29. TID_LBRACKET = 0, // {
  30. TID_RBRACKET, // }
  31. TID_COLON, // :
  32. TID_VARIABLE, // $...
  33. TID_WORD, // *
  34. TID_QUOTE, // "*"
  35. TID_NEWLINE, // \n
  36. TID_UNKNOWN,
  37. TID_END
  38. };
  39. /** This struct represents a token, which is an ID'd lexeme from the
  40. parsing input stream.
  41. */
  42. struct PUScriptToken
  43. {
  44. /// This is the lexeme for this token
  45. std::string lexeme, file;
  46. /// This is the id associated with the lexeme, which comes from a lexeme-token id mapping
  47. unsigned int type;
  48. /// This holds the line number of the input stream where the token was found.
  49. unsigned int line;
  50. };
  51. typedef std::vector<PUScriptToken*> PUScriptTokenList;
  52. class PUScriptLexer
  53. {
  54. public:
  55. PUScriptLexer();
  56. ~PUScriptLexer();
  57. void openLexer(const std::string &str,const std::string &source,PUScriptTokenList& tokenList);
  58. /** Tokenizes the given input and returns the list of tokens found */
  59. //tokenize(const std::string &str, const std::string &source);
  60. private: // Private utility operations
  61. void setToken(const std::string &lexeme, int line, const std::string &source, PUScriptTokenList *tokens);
  62. bool isWhitespace(char c) const;
  63. bool isNewline(char c) const;
  64. };
  65. NS_CC_END
  66. #endif