summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Ross <github@brainsick.com>2018-01-24 19:00:51 -0600
committerRĂ©mi Verschelde <rverschelde@gmail.com>2018-07-26 00:17:57 +0200
commit9423f23ffb80c946dec380f73f3f313ec44d0d18 (patch)
tree49d22ccfbf1c81cc008a050106c8c3c80275d45f
parent96ce66e00f345147f9280bdbf7113972094e031e (diff)
allow comments and whitespace before shader_type declaration
-rw-r--r--servers/visual/shader_language.cpp49
1 files changed, 48 insertions, 1 deletions
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp
index 146f0235a6..7ce7254313 100644
--- a/servers/visual/shader_language.cpp
+++ b/servers/visual/shader_language.cpp
@@ -612,6 +612,8 @@ ShaderLanguage::Token ShaderLanguage::_get_token() {
}
ERR_PRINT("BUG");
return Token();
+
+#undef GETCHAR
}
String ShaderLanguage::token_debug(const String &p_code) {
@@ -4073,13 +4075,58 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
return OK;
}
+// skips over whitespace and /* */ and // comments
+static int _get_first_ident_pos(const String &p_code) {
+
+ int idx = 0;
+
+#define GETCHAR(m_idx) (((idx + m_idx) < p_code.length()) ? p_code[idx + m_idx] : CharType(0))
+
+ while (true) {
+ if (GETCHAR(0) == '/' && GETCHAR(1) == '/') {
+ idx += 2;
+ while (true) {
+ if (GETCHAR(0) == 0) return 0;
+ if (GETCHAR(0) == '\n') {
+ idx++;
+ break; // loop
+ }
+ idx++;
+ }
+ } else if (GETCHAR(0) == '/' && GETCHAR(1) == '*') {
+ idx += 2;
+ while (true) {
+ if (GETCHAR(0) == 0) return 0;
+ if (GETCHAR(0) == '*' && GETCHAR(1) == '/') {
+ idx += 2;
+ break; // loop
+ }
+ idx++;
+ }
+ } else {
+ switch (GETCHAR(0)) {
+ case ' ':
+ case '\t':
+ case '\r':
+ case '\n': {
+ idx++;
+ } break; // switch
+ default:
+ return idx;
+ }
+ }
+ }
+
+#undef GETCHAR
+}
+
String ShaderLanguage::get_shader_type(const String &p_code) {
bool reading_type = false;
String cur_identifier;
- for (int i = 0; i < p_code.length(); i++) {
+ for (int i = _get_first_ident_pos(p_code); i < p_code.length(); i++) {
if (p_code[i] == ';') {
break;