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