gdscript_tokenizer_buffer.h 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**************************************************************************/
  2. /* gdscript_tokenizer_buffer.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef GDSCRIPT_TOKENIZER_BUFFER_H
  31. #define GDSCRIPT_TOKENIZER_BUFFER_H
  32. #include "gdscript_tokenizer.h"
  33. class GDScriptTokenizerBuffer : public GDScriptTokenizer {
  34. public:
  35. enum CompressMode {
  36. COMPRESS_NONE,
  37. COMPRESS_ZSTD,
  38. };
  39. enum {
  40. TOKEN_BYTE_MASK = 0x80,
  41. TOKEN_BITS = 8,
  42. TOKEN_MASK = (1 << (TOKEN_BITS - 1)) - 1,
  43. };
  44. Vector<StringName> identifiers;
  45. Vector<Variant> constants;
  46. Vector<int> continuation_lines;
  47. HashMap<int, int> token_lines;
  48. HashMap<int, int> token_columns;
  49. Vector<Token> tokens;
  50. int current = 0;
  51. uint32_t current_line = 1;
  52. bool multiline_mode = false;
  53. List<int> indent_stack;
  54. List<List<int>> indent_stack_stack; // For lambdas, which require manipulating the indentation point.
  55. int pending_indents = 0;
  56. bool last_token_was_newline = false;
  57. #ifdef TOOLS_ENABLED
  58. HashMap<int, CommentData> dummy;
  59. #endif // TOOLS_ENABLED
  60. static int _token_to_binary(const Token &p_token, Vector<uint8_t> &r_buffer, int p_start, HashMap<StringName, uint32_t> &r_identifiers_map, HashMap<Variant, uint32_t, VariantHasher, VariantComparator> &r_constants_map);
  61. Token _binary_to_token(const uint8_t *p_buffer);
  62. public:
  63. Error set_code_buffer(const Vector<uint8_t> &p_buffer);
  64. static Vector<uint8_t> parse_code_string(const String &p_code, CompressMode p_compress_mode);
  65. virtual int get_cursor_line() const override;
  66. virtual int get_cursor_column() const override;
  67. virtual void set_cursor_position(int p_line, int p_column) override;
  68. virtual void set_multiline_mode(bool p_state) override;
  69. virtual bool is_past_cursor() const override;
  70. virtual void push_expression_indented_block() override; // For lambdas, or blocks inside expressions.
  71. virtual void pop_expression_indented_block() override; // For lambdas, or blocks inside expressions.
  72. virtual bool is_text() override { return false; }
  73. #ifdef TOOLS_ENABLED
  74. virtual const HashMap<int, CommentData> &get_comments() const override {
  75. return dummy;
  76. }
  77. #endif // TOOLS_ENABLED
  78. virtual Token scan() override;
  79. };
  80. #endif // GDSCRIPT_TOKENIZER_BUFFER_H