Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ function assigns(tokens) {
idx++
skipWhitespace(+1)
if (tokens[idx].type !== 'ident') continue

// Handle the case of a parameter like "in StructName myArg", where if
// there's one ident after another, assume the one we're on is the
// StructName, identified in the higher scope, and not a declaration
var nextNonWhitespace = peekPastWhitespace()
if (nextNonWhitespace && nextNonWhitespace.type === 'ident') continue

tokens[idx++].declaration = true
skipWhitespace(+1)
skipArrayDimensions()
Expand Down Expand Up @@ -143,6 +150,12 @@ function assigns(tokens) {

return tokens

function peekPastWhitespace() {
var peekIdx = idx + 1;
while (tokens[peekIdx] && tokens[peekIdx].type === 'whitespace') peekIdx++
return tokens[peekIdx];
}

function skipWhitespace(n) {
while (tokens[idx] && tokens[idx].type === 'whitespace') idx++
}
Expand Down
6 changes: 6 additions & 0 deletions test/arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ float aFunction(vec2 a, vec3 b, float c) {
return z;
}

float sFunction(UserStruct structArg);
float sFunction(const UserStruct structArg);
float sFunction(const in UserStruct structArg);

Thing xFunction(vec2 d, Thing e[2], Thing f, Thing g[2][5]);
Thing xFunction(vec2 d, Thing e[2], Thing f, Thing g[2][5]) {
Thing y = Thing(2.0);
Expand Down Expand Up @@ -34,5 +38,7 @@ Another yFunction(
, i: [true]
, j: [true]
, k: [true]
, UserStruct: [false, false, false]
, structArg: [true, true, true]
, Thing: new Array(10).map(() => false)
}))