summaryrefslogtreecommitdiff
path: root/modules/gdscript/gd_tokenizer.h
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript/gd_tokenizer.h')
-rw-r--r--modules/gdscript/gd_tokenizer.h122
1 files changed, 58 insertions, 64 deletions
diff --git a/modules/gdscript/gd_tokenizer.h b/modules/gdscript/gd_tokenizer.h
index 1e9eda7947..c1ed8ad92e 100644
--- a/modules/gdscript/gd_tokenizer.h
+++ b/modules/gdscript/gd_tokenizer.h
@@ -29,15 +29,14 @@
#ifndef GD_TOKENIZER_H
#define GD_TOKENIZER_H
+#include "gd_functions.h"
+#include "string_db.h"
#include "ustring.h"
#include "variant.h"
-#include "string_db.h"
-#include "gd_functions.h"
#include "vmap.h"
class GDTokenizer {
public:
-
enum Token {
TK_EMPTY,
@@ -137,37 +136,36 @@ public:
};
protected:
-
enum StringMode {
STRING_SINGLE_QUOTE,
STRING_DOUBLE_QUOTE,
STRING_MULTILINE
};
- static const char* token_names[TK_MAX];
+ static const char *token_names[TK_MAX];
+
public:
static const char *get_token_name(Token p_token);
- virtual const Variant& get_token_constant(int p_offset=0) const=0;
- virtual Token get_token(int p_offset=0) const=0;
- virtual StringName get_token_identifier(int p_offset=0) const=0;
- virtual GDFunctions::Function get_token_built_in_func(int p_offset=0) const=0;
- virtual Variant::Type get_token_type(int p_offset=0) const=0;
- virtual int get_token_line(int p_offset=0) const=0;
- virtual int get_token_column(int p_offset=0) const=0;
- virtual int get_token_line_indent(int p_offset=0) const=0;
- virtual String get_token_error(int p_offset=0) const=0;
- virtual void advance(int p_amount=1)=0;
+ virtual const Variant &get_token_constant(int p_offset = 0) const = 0;
+ virtual Token get_token(int p_offset = 0) const = 0;
+ virtual StringName get_token_identifier(int p_offset = 0) const = 0;
+ virtual GDFunctions::Function get_token_built_in_func(int p_offset = 0) const = 0;
+ virtual Variant::Type get_token_type(int p_offset = 0) const = 0;
+ virtual int get_token_line(int p_offset = 0) const = 0;
+ virtual int get_token_column(int p_offset = 0) const = 0;
+ virtual int get_token_line_indent(int p_offset = 0) const = 0;
+ virtual String get_token_error(int p_offset = 0) const = 0;
+ virtual void advance(int p_amount = 1) = 0;
virtual ~GDTokenizer(){};
-
};
class GDTokenizerText : public GDTokenizer {
enum {
- MAX_LOOKAHEAD=4,
- TK_RB_SIZE=MAX_LOOKAHEAD*2+1
+ MAX_LOOKAHEAD = 4,
+ TK_RB_SIZE = MAX_LOOKAHEAD * 2 + 1
};
@@ -179,17 +177,21 @@ class GDTokenizerText : public GDTokenizer {
Variant::Type vtype; //for type types
GDFunctions::Function func; //function for built in functions
};
- int line,col;
- TokenData() { type = TK_EMPTY; line=col=0; vtype=Variant::NIL; }
+ int line, col;
+ TokenData() {
+ type = TK_EMPTY;
+ line = col = 0;
+ vtype = Variant::NIL;
+ }
};
void _make_token(Token p_type);
- void _make_newline(int p_spaces=0);
- void _make_identifier(const StringName& p_identifier);
+ void _make_newline(int p_spaces = 0);
+ void _make_identifier(const StringName &p_identifier);
void _make_built_in_func(GDFunctions::Function p_func);
- void _make_constant(const Variant& p_constant);
- void _make_type(const Variant::Type& p_type);
- void _make_error(const String& p_error);
+ void _make_constant(const Variant &p_constant);
+ void _make_type(const Variant::Type &p_type);
+ void _make_error(const String &p_error);
String code;
int len;
@@ -197,66 +199,58 @@ class GDTokenizerText : public GDTokenizer {
const CharType *_code;
int line;
int column;
- TokenData tk_rb[TK_RB_SIZE*2+1];
+ TokenData tk_rb[TK_RB_SIZE * 2 + 1];
int tk_rb_pos;
String last_error;
bool error_flag;
void _advance();
-public:
-
- void set_code(const String& p_code);
- virtual Token get_token(int p_offset=0) const;
- virtual StringName get_token_identifier(int p_offset=0) const;
- virtual GDFunctions::Function get_token_built_in_func(int p_offset=0) const;
- virtual Variant::Type get_token_type(int p_offset=0) const;
- virtual int get_token_line(int p_offset=0) const;
- virtual int get_token_column(int p_offset=0) const;
- virtual int get_token_line_indent(int p_offset=0) const;
- virtual const Variant& get_token_constant(int p_offset=0) const;
- virtual String get_token_error(int p_offset=0) const;
- virtual void advance(int p_amount=1);
+public:
+ void set_code(const String &p_code);
+ virtual Token get_token(int p_offset = 0) const;
+ virtual StringName get_token_identifier(int p_offset = 0) const;
+ virtual GDFunctions::Function get_token_built_in_func(int p_offset = 0) const;
+ virtual Variant::Type get_token_type(int p_offset = 0) const;
+ virtual int get_token_line(int p_offset = 0) const;
+ virtual int get_token_column(int p_offset = 0) const;
+ virtual int get_token_line_indent(int p_offset = 0) const;
+ virtual const Variant &get_token_constant(int p_offset = 0) const;
+ virtual String get_token_error(int p_offset = 0) const;
+ virtual void advance(int p_amount = 1);
};
-
-
-
class GDTokenizerBuffer : public GDTokenizer {
-
enum {
- TOKEN_BYTE_MASK=0x80,
- TOKEN_BITS=8,
- TOKEN_MASK=(1<<TOKEN_BITS)-1,
- TOKEN_LINE_BITS=24,
- TOKEN_LINE_MASK=(1<<TOKEN_LINE_BITS)-1,
+ TOKEN_BYTE_MASK = 0x80,
+ TOKEN_BITS = 8,
+ TOKEN_MASK = (1 << TOKEN_BITS) - 1,
+ TOKEN_LINE_BITS = 24,
+ TOKEN_LINE_MASK = (1 << TOKEN_LINE_BITS) - 1,
};
-
Vector<StringName> identifiers;
Vector<Variant> constants;
- VMap<uint32_t,uint32_t> lines;
+ VMap<uint32_t, uint32_t> lines;
Vector<uint32_t> tokens;
Variant nil;
int token;
public:
-
-
- Error set_code_buffer(const Vector<uint8_t> & p_buffer);
- static Vector<uint8_t> parse_code_string(const String& p_code);
- virtual Token get_token(int p_offset=0) const;
- virtual StringName get_token_identifier(int p_offset=0) const;
- virtual GDFunctions::Function get_token_built_in_func(int p_offset=0) const;
- virtual Variant::Type get_token_type(int p_offset=0) const;
- virtual int get_token_line(int p_offset=0) const;
- virtual int get_token_column(int p_offset=0) const;
- virtual int get_token_line_indent(int p_offset=0) const;
- virtual const Variant& get_token_constant(int p_offset=0) const;
- virtual String get_token_error(int p_offset=0) const;
- virtual void advance(int p_amount=1);
+ Error set_code_buffer(const Vector<uint8_t> &p_buffer);
+ static Vector<uint8_t> parse_code_string(const String &p_code);
+ virtual Token get_token(int p_offset = 0) const;
+ virtual StringName get_token_identifier(int p_offset = 0) const;
+ virtual GDFunctions::Function get_token_built_in_func(int p_offset = 0) const;
+ virtual Variant::Type get_token_type(int p_offset = 0) const;
+ virtual int get_token_line(int p_offset = 0) const;
+ virtual int get_token_column(int p_offset = 0) const;
+ virtual int get_token_line_indent(int p_offset = 0) const;
+ virtual const Variant &get_token_constant(int p_offset = 0) const;
+ virtual String get_token_error(int p_offset = 0) const;
+ virtual void advance(int p_amount = 1);
GDTokenizerBuffer();
};