diff --git a/src/printer.fs b/src/printer.fs index dda4efb8..ee4ff583 100644 --- a/src/printer.fs +++ b/src/printer.fs @@ -117,7 +117,8 @@ type PrinterImpl(withLocations) = | Op "?:", [a1; a2; a3] -> let prec = precedence.["?:"] let res = out "%s?%s%s:%s%s" (exprToSLevel indent (prec+1) a1) - (nl (indent+1)) (exprToSLevel (indent+1) prec a2) + // The middle expression of ?: is parsed as if grouped: precedence doesn't apply to it. + (nl (indent+1)) (exprToSLevel (indent+1) 0 a2) (nl (indent+1)) (exprToSLevel (indent+1) prec a3) if prec < level then out "(%s)" res else res diff --git a/tests/real/controllable-machinery.frag.expected b/tests/real/controllable-machinery.frag.expected index 2ec346ad..fd311392 100644 --- a/tests/real/controllable-machinery.frag.expected +++ b/tests/real/controllable-machinery.frag.expected @@ -28,13 +28,13 @@ vec4 BPos(float t) float a; t=mod(t,tCyc); p=t<5.? - (a=0.,vec3(-1.018+2.118*t/5.,bEdge,0)): + a=0.,vec3(-1.018+2.118*t/5.,bEdge,0): t<10.? - (a=1.57079635*(t-5.)/5.,vec3(1.1,bEdge+sin(a),1.-cos(a))): + a=1.57079635*(t-5.)/5.,vec3(1.1,bEdge+sin(a),1.-cos(a)): t<15.? - (a=1.57079635,vec3(1.1-2.118*(t-10.)/5.,1.+bEdge,1)): + a=1.57079635,vec3(1.1-2.118*(t-10.)/5.,1.+bEdge,1): t<17.5? - (a=1.57079635,vec3(-1.018,1.+bEdge,1.-(t-15.)/2.5)): + a=1.57079635,vec3(-1.018,1.+bEdge,1.-(t-15.)/2.5): (t-=17.5,a=-1.57079635*t,vec3(-1.018,1.+bEdge-t*t,0)); return vec4(p,a); } @@ -355,7 +355,7 @@ vec3 ShowScene(vec3 ro,vec3 rd) idObjT=idObj; dstGear=GearRay(ro,rd); idObj=dstGear2.5?" - "(z.xz=r.xz-v.xz,z.y=0.,z/=v.w,vec2(z.x,r.y)):" + "z.xz=r.xz-v.xz,z.y=0.,z/=v.w,vec2(z.x,r.y):" "m.w>1.5?" - "(z=v.xyz,r.xz*.2):" + "z=v.xyz,r.xz*.2:" "(z=(r-v.xyz)/v.w,z.xy);" "return z;" "}" diff --git a/tests/real/mouton/mouton.expected b/tests/real/mouton/mouton.expected index 3c0ce2b8..d2bb5234 100644 --- a/tests/real/mouton/mouton.expected +++ b/tests/real/mouton/mouton.expected @@ -200,7 +200,7 @@ const char *mouton_vert = "f=vec3(0);" "x=vec3(0,0,-8);" "e=mod(v,3.)<1.5?" - "(d=0.,c=vec3(0,2,-8),vec3(0,3,0)):" + "d=0.,c=vec3(0,2,-8),vec3(0,3,0):" "(c=vec3(0,5.5,2),vec3(0,5.75,0));" "l=vec3(0,-.1,1);" "o=3.+v*.1;" @@ -361,7 +361,7 @@ const char *mouton_frag = "v.y-=-z.y;" "float y=v.y+smoothstep(1.,20.,length(v.xz));" "return y<.4?" - "(y-=pow((B(v*.9)*.5+B(v*1.6)*.3+B(v*2.7)*.1)*.5+.5,3.)*.45*(1.-exp((-t+137.3)*3.)),vec2(y,12)):" + "y-=pow((B(v*.9)*.5+B(v*1.6)*.3+B(v*2.7)*.1)*.5+.5,3.)*.45*(1.-exp((-t+137.3)*3.)),vec2(y,12):" "vec2(9e7,0);" "}" "mat3 A(vec3 v,vec3 y)" diff --git a/tests/unit/ternary.frag.expected b/tests/unit/ternary.frag.expected index 8732a92f..2944fe6f 100644 --- a/tests/unit/ternary.frag.expected +++ b/tests/unit/ternary.frag.expected @@ -15,7 +15,7 @@ void main() { int d=0,e=0; k==0? - (sin(O.x),d=1): + sin(O.x),d=1: (cos(O.x),e=2); O.x=float(d); O.y=float(e); @@ -25,3 +25,4 @@ int f2() k++; return k; } +