title: Syntax error in GLSL - unexpected NEW_IDENTIFIER
body: <p>I have been writing a shading language that is meant to simplify writing GLSL. Because of this, I can't really rely on line numbers given by the GLSL compiler. I therefore can't find what this error is trying to say. What does it mean first of all, and then how can I fix it?</p>
  
  <p>Error code:</p>
  
  <pre><code>0:8(18): error: syntax error, unexpected NEW_IDENTIFIER, expecting '{'
  </code></pre>
  
  <p>I believe that this just means there is a syntax error with the generated GLSL, but I can't find one. What does this error message actually mean?</p>
  
  <p>-- EDIT --</p>
  
  <p>Sorry for not providing code, I wanted to know what the error meant so I could provide the relevant areas of code.</p>
  
  <p>Generated vertex shader:</p>
  
  <pre><code>#version 120
  
  attribute vec3 position;
  attribute vec2 texCoord;
  attribute vec3 normal;
  attribute vec3 tangent;
  
  varying vec2 fragTexCoords;
  varying vec3 worldPos;
  varying vec4 shadowMapCoords;
  varying mat3 tbnMatrix;
  
  uniform mat4 modelMatrix;
  uniform mat4 MVPMatrix;
  uniform mat4 lightMatrix;
  
  void main() {
      gl_Position = MVPMatrix * vec4(position, 1);
      fragTexCoords = texCoord;
      shadowMapCoords = lightMatrix * vec4(position, 1);
      worldPos = (modelMatrix * vec4(position, 1)).xyz;
  
      vec3 n = normalize((modelMatrix * vec4(normal, 0)).xyz);
      vec3 t = normalize((modelMatrix * vec4(tangent, 0)).xyz);
      t = normalize(t - dot(t, n) * n);
  
      vec3 biTangent = cross(t, n);
      tbnMatrix = mat3(t, biTangent, n);
  }
  </code></pre>
  
  <p>And the generated fragment shader:</p>
  
  <pre><code>#version 120
  
  varying vec2 fragTexCoords;
  varying vec3 worldPos;
  varying vec4 shadowMapCoords;
  varying mat3 tbnMatrix;
  
  uniform Material material;
  uniform Light light;
  uniform vec3 eyePos;
  
  uniform sampler2D shadowMap;
  uniform float shadowVarianceMin;
  uniform float shadowLightBleedReduction;
  
  bool inRange(float value) {
      return value &gt;= 0 &amp;&amp; value &lt;= 1;
  }
  
  float linStep(float low, float high, float v) {
      return clamp((v - low) / (high - low), 0, 1);
  }
  
  vec2 calcParallaxTexCoords(sampler2D dispMap, mat3 tbnMatrix, vec3 directionToEye, vec2 texCoords, float scale, float bias) {
      return texCoords.xy + (directionToEye * tbnMatrix).xy * (texture2D(dispMap, texCoords.xy).r * scale + bias);
  }
  
  float sampleShadowMap(sampler2D shadowMap, vec2 coords, float compare) {
      return step(compare, texture2D(shadowMap, coords.xy).r);
  }
  
  float sampleVarianceShadowMap(sampler2D shadowMap, vec2 coords, float compare, float varianceMin, float lightBleedReduction) {
      vec2 moments = texture2D(shadowMap, coords.xy).xy;
  
      float p = step(compare, moments.x);
      float variance = max(moments.y - moments.x * moments.x, varianceMin);
  
      float d = compare - moments.x;
      float pMax = linStep(lightBleedReduction, 1, variance / (variance + d * d));
  
      return min(max(p, pMax), 1);
  }
  
  struct Light {
      vec3 color;
      float intensity;
      vec3 direction;
  };
  
  struct Material {
      float roughness;
      float fresnelReflectance;
  
      sampler2D diffuseTexture;
      sampler2D normalMap;
      sampler2D dispMap;
  
      float dispMapScale;
      float dispMapBias;
  };
  
  vec3 calcLight(Light light, Material material, vec3 surfaceNormal, vec3 eyePos, vec3 diffuseColor, vec3 specularColor) {
      vec3 halfVector     = normalize(light.direction + eyePos);
      float NdotL         = clamp(dot(surfaceNormal, light.direction),    0.0, 1.0);
      float NdotH         = clamp(dot(surfaceNormal, halfVector),         0.0, 1.0);
      float NdotV         = clamp(dot(surfaceNormal, eyePos),             0.0, 1.0);
      float VdotH         = clamp(dot(eyePos, halfVector),                0.0, 1.0);
      float rSq           = material.roughness * material.roughness;
  
      // ----- Fresnel term -----
      float fresnel = pow(1 - VdotH, 5.0);
      fresnel *= 1 - material.fresnelReflectance;
      fresnel += material.fresnelReflectance;
  
      // ----- Geometric attenuation term -----
      float geoNum = 2.0 * NdotV;
      float geoB   = (geoNum * NdotV) / VdotH;
      float geoC   = (geoNum * NdotL) / VdotH;
      float geo    = min(1.0, min(geoB, geoC));
  
      // ----- Roughness term -----
      float roughnessA = rSq * pow(NdotH, 4.0);
      float roughnessB = (NdotH * NdotH - 1.0) / (rSq * NdotH * NdotH);
      float roughness = 1.0 / roughnessA * exp(roughnessB);
  
      // ----- Cook-Torrance calculation -----
      vec3 specular = vec3(fresnel * roughness * geo) / (NdotV * NdotL);
  
      return max(0.0, NdotL) * (specularColor * specular + diffuseColor);
  }
  
  float calcShadowAmount(sampler2D shadowMap, vec4 initialShadowMapCoords) {
      vec3 shadowMapCoords = (initialShadowMapCoords.xyz / initialShadowMapCoords.w);
  
      if (inRange(shadowMapCoords.x) &amp;&amp; inRange(shadowMapCoords.y) &amp;&amp; inRange(shadowMapCoords.z)) {
          return sampleVarianceShadowMap(shadowMap, shadowMapCoords.xy, shadowMapCoords.z, shadowVarianceMin, shadowLightBleedReduction);
      } else {
          return 1.0;
      }
  }
  
  float calcBasicShadowAmount(sampler2D shadowMap, vec4 initialShadowMapCoords) {
      vec3 shadowMapCoords = (initialShadowMapCoords.xyz / initialShadowMapCoords.w);
  
      return sampleShadowMap(shadowMap, shadowMapCoords.xy, shadowMapCoords.z);
  }
  
  void main() {
      vec3 directionToEye = normalize(eyePos - worldPos);
      vec2 texCoords = calcParallaxTexCoords(dispMap, tbnMatrix, directionToEye, fragTexCoords, dispMapScale, dispMapBias);
      vec3 normal = normalize(tbnMatrix * (255.0 / 128.0 * texture2D(normalMap, texCoords).xyz - 1));
  
      gl_FragColor = calcLight(light, material, normal, eyePos, texture2D(diffuse, texCoords), vec3(1, 1, 1));
  }
  </code></pre>