Skip to content

Commit

Permalink
allow comments and whitespace before shader_type declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
brainsick authored and akien-mga committed Jul 25, 2018
1 parent 96ce66e commit 9423f23
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion servers/visual/shader_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,8 @@ ShaderLanguage::Token ShaderLanguage::_get_token() {
}
ERR_PRINT("BUG");
return Token();

#undef GETCHAR
}

String ShaderLanguage::token_debug(const String &p_code) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9423f23

Please sign in to comment.