summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorRémi Verschelde <remi@verschelde.fr>2015-12-14 17:40:57 +0100
committerRémi Verschelde <remi@verschelde.fr>2015-12-14 17:40:57 +0100
commit9e9e4f96a254c6d1108a98ebfd89cc9a5c416907 (patch)
treeab1831d69ca507f454c607876b4004eea832b78d /modules
parent89629d35bba75f677d9172083b7fad13a11127b7 (diff)
parent897cf2140c6e11f8d1ba5adfd00efd3aa1ca2121 (diff)
Merge pull request #3051 from eska014/add-export-hints
Add GDScript export hints for named bit flags, exponential ranges and global filesystem
Diffstat (limited to 'modules')
-rw-r--r--modules/gdscript/gd_parser.cpp114
1 files changed, 106 insertions, 8 deletions
diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp
index c55bfee591..4339a13edf 100644
--- a/modules/gdscript/gd_parser.cpp
+++ b/modules/gdscript/gd_parser.cpp
@@ -2381,10 +2381,48 @@ void GDParser::_parse_class(ClassNode *p_class) {
current_export.hint=PROPERTY_HINT_ALL_FLAGS;
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_CLOSE) {
- _set_error("Expected ')' in hint.");
+
+ if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ break;
+ }
+ if (tokenizer->get_token()!=GDTokenizer::TK_COMMA)
+ {
+ _set_error("Expected ')' or ',' in bit flags hint.");
return;
}
+
+ current_export.hint=PROPERTY_HINT_FLAGS;
+ tokenizer->advance();
+
+ bool first = true;
+ while(true) {
+
+ if (tokenizer->get_token()!=GDTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type()!=Variant::STRING) {
+ current_export=PropertyInfo();
+ _set_error("Expected a string constant in named bit flags hint.");
+ return;
+ }
+
+ String c = tokenizer->get_token_constant();
+ if (!first)
+ current_export.hint_string+=",";
+ else
+ first=false;
+
+ current_export.hint_string+=c.xml_escape();
+
+ tokenizer->advance();
+ if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE)
+ break;
+
+ if (tokenizer->get_token()!=GDTokenizer::TK_COMMA) {
+ current_export=PropertyInfo();
+ _set_error("Expected ')' or ',' in named bit flags hint.");
+ return;
+ }
+ tokenizer->advance();
+ }
+
break;
}
@@ -2439,6 +2477,23 @@ void GDParser::_parse_class(ClassNode *p_class) {
break;
}
+ // range
+ if (tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier()=="EXP") {
+
+ current_export.hint=PROPERTY_HINT_EXP_RANGE;
+ tokenizer->advance();
+
+ if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE)
+ break;
+ else if (tokenizer->get_token()!=GDTokenizer::TK_COMMA) {
+ _set_error("Expected ')' or ',' in exponential range hint.");
+ return;
+ }
+ tokenizer->advance();
+ }
+ else
+ current_export.hint=PROPERTY_HINT_RANGE;
+
float sign=1.0;
if (tokenizer->get_token()==GDTokenizer::TK_OP_SUB) {
@@ -2452,8 +2507,6 @@ void GDParser::_parse_class(ClassNode *p_class) {
return;
}
- //enumeration
- current_export.hint=PROPERTY_HINT_RANGE;
current_export.hint_string=rtos(sign*double(tokenizer->get_token_constant()));
tokenizer->advance();
@@ -2556,10 +2609,32 @@ void GDParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier()=="DIR") {
- current_export.hint=PROPERTY_HINT_DIR;
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_CLOSE) {
- _set_error("Expected ')' in hint.");
+
+ if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE)
+ current_export.hint=PROPERTY_HINT_DIR;
+ else if (tokenizer->get_token()==GDTokenizer::TK_COMMA ) {
+
+ tokenizer->advance();
+
+ if (tokenizer->get_token()!=GDTokenizer::TK_IDENTIFIER || !(tokenizer->get_token_identifier()=="GLOBAL")) {
+ _set_error("Expected 'GLOBAL' after comma in directory hint.");
+ return;
+ }
+ if (!p_class->tool) {
+ _set_error("Global filesystem hints may only be used in tool scripts.");
+ return;
+ }
+ current_export.hint=PROPERTY_HINT_GLOBAL_DIR;
+ tokenizer->advance();
+
+ if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ _set_error("Expected ')' in hint.");
+ return;
+ }
+ }
+ else {
+ _set_error("Expected ')' or ',' in hint.");
return;
}
break;
@@ -2573,9 +2648,32 @@ void GDParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token()==GDTokenizer::TK_COMMA) {
tokenizer->advance();
+
+ if (tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier()=="GLOBAL") {
+
+ if (!p_class->tool) {
+ _set_error("Global filesystem hints may only be used in tool scripts.");
+ return;
+ }
+ current_export.hint=PROPERTY_HINT_GLOBAL_FILE;
+ tokenizer->advance();
+
+ if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE)
+ break;
+ else if (tokenizer->get_token()==GDTokenizer::TK_COMMA)
+ tokenizer->advance();
+ else {
+ _set_error("Expected ')' or ',' in hint.");
+ return;
+ }
+ }
+
if (tokenizer->get_token()!=GDTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type()!=Variant::STRING) {
- _set_error("Expected string constant with filter");
+ if (current_export.hint==PROPERTY_HINT_GLOBAL_FILE)
+ _set_error("Expected string constant with filter");
+ else
+ _set_error("Expected 'GLOBAL' or string constant with filter");
return;
}
current_export.hint_string=tokenizer->get_token_constant();