CCPUScriptLexer.h 2.7 KB

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