BsLexerFX.l 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. %{
  2. #include "BsParserFX.h"
  3. #define YY_USER_ACTION yylloc->first_column = yycolumn + 1; yylloc->first_line = yylineno + 1; yycolumn += (int)yyleng; yylloc->filename = getCurrentFilename(yyextra);
  4. #define YY_USER_INIT yylineno = 0; yycolumn = 0;
  5. %}
  6. %option yylineno reentrant noyywrap nounistd never-interactive warn nodefault bison-bridge bison-locations
  7. %option outfile="BsLexerFX.c" header-file="BsLexerFX.h"
  8. %option extra-type="struct tagParseState *"
  9. INTEGER -?[0-9][0-9]*
  10. INTEGER_16 0[xX][0-9a-fA-F]+
  11. FLOAT [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]?
  12. STRING \"[^"\n]*\"
  13. IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]*
  14. WS [ \r\n\t]*
  15. SINGLEWS [ \r\n\t]
  16. COMMENT \/\/[^\n]*
  17. /* Start conditions */
  18. %x INCLUDE
  19. %x CODEBLOCK_HEADER
  20. %x CODEBLOCK_EQUALS
  21. %x CODEBLOCK
  22. %x CODEBLOCK_END
  23. %%
  24. {WS} { /* Skip blank */ }
  25. {INTEGER} { yylval->intValue = atoi(yytext); return TOKEN_INTEGER; }
  26. {INTEGER_16} { yylval->intValue = (int)strtol(yytext, 0, 0); return TOKEN_INTEGER; }
  27. {FLOAT} { yylval->floatValue = (float)atof(yytext); return TOKEN_FLOAT; }
  28. {STRING} { yylval->strValue = mmalloc_strdup(yyextra->memContext, yytext); return TOKEN_STRING; }
  29. true { yylval->intValue = 1; return TOKEN_BOOLEAN; }
  30. false { yylval->intValue = 0; return TOKEN_BOOLEAN; }
  31. /* Value types */
  32. int { yylval->intValue = PT_Int; return TOKEN_INTTYPE; }
  33. int2 { yylval->intValue = PT_Int2; return TOKEN_INT2TYPE; }
  34. int3 { yylval->intValue = PT_Int3; return TOKEN_INT3TYPE; }
  35. int4 { yylval->intValue = PT_Int4; return TOKEN_INT4TYPE; }
  36. float { yylval->intValue = PT_Float; return TOKEN_FLOATTYPE; }
  37. float2 { yylval->intValue = PT_Float2; return TOKEN_FLOAT2TYPE; }
  38. float3 { yylval->intValue = PT_Float3; return TOKEN_FLOAT3TYPE; }
  39. float4 { yylval->intValue = PT_Float4; return TOKEN_FLOAT4TYPE; }
  40. color { yylval->intValue = PT_Color; return TOKEN_COLORTYPE; }
  41. mat2x2 { yylval->intValue = PT_Mat2x2; return TOKEN_MAT2x2TYPE; }
  42. mat2x3 { yylval->intValue = PT_Mat2x3; return TOKEN_MAT2x3TYPE; }
  43. mat2x4 { yylval->intValue = PT_Mat2x4; return TOKEN_MAT2x4TYPE; }
  44. mat3x2 { yylval->intValue = PT_Mat3x2; return TOKEN_MAT3x2TYPE; }
  45. mat3x3 { yylval->intValue = PT_Mat3x3; return TOKEN_MAT3x3TYPE; }
  46. mat3x4 { yylval->intValue = PT_Mat3x4; return TOKEN_MAT3x4TYPE; }
  47. mat4x2 { yylval->intValue = PT_Mat4x2; return TOKEN_MAT4x2TYPE; }
  48. mat4x3 { yylval->intValue = PT_Mat4x3; return TOKEN_MAT4x3TYPE; }
  49. mat4x4 { yylval->intValue = PT_Mat4x4; return TOKEN_MAT4x4TYPE; }
  50. Sampler1D { yylval->intValue = PT_Sampler1D; return TOKEN_SAMPLER1D; }
  51. Sampler2D { yylval->intValue = PT_Sampler2D; return TOKEN_SAMPLER2D; }
  52. Sampler3D { yylval->intValue = PT_Sampler3D; return TOKEN_SAMPLER3D; }
  53. SamplerCUBE { yylval->intValue = PT_SamplerCUBE; return TOKEN_SAMPLERCUBE; }
  54. Sampler2DMS { yylval->intValue = PT_Sampler2DMS; return TOKEN_SAMPLER2DMS; }
  55. Texture1D { yylval->intValue = PT_Texture1D; return TOKEN_TEXTURE1D; }
  56. Texture2D { yylval->intValue = PT_Texture2D; return TOKEN_TEXTURE2D; }
  57. Texture3D { yylval->intValue = PT_Texture3D; return TOKEN_TEXTURE3D; }
  58. TextureCUBE { yylval->intValue = PT_TextureCUBE; return TOKEN_TEXTURECUBE; }
  59. Texture2DMS { yylval->intValue = PT_Texture2DMS; return TOKEN_TEXTURE2DMS; }
  60. ByteBuffer { yylval->intValue = PT_ByteBuffer; return TOKEN_BYTEBUFFER; }
  61. StructBuffer { yylval->intValue = PT_StructBuffer; return TOKEN_STRUCTBUFFER; }
  62. TypedBufferRW { yylval->intValue = PT_TypedBufferRW; return TOKEN_RWTYPEDBUFFER; }
  63. ByteBufferRW { yylval->intValue = PT_ByteBufferRW; return TOKEN_RWBYTEBUFFER; }
  64. StructBufferRW { yylval->intValue = PT_StructBufferRW; return TOKEN_RWSTRUCTBUFFER; }
  65. AppendBuffer { yylval->intValue = PT_AppendBuffer; return TOKEN_RWAPPENDBUFFER; }
  66. ConsumeBuffer { yylval->intValue = PT_ConsumeBuffer; return TOKEN_RWCONSUMEBUFFER; }
  67. Block { return TOKEN_PARAMSBLOCK; }
  68. /* Shader keywords */
  69. Separable { return TOKEN_SEPARABLE; }
  70. Queue { return TOKEN_QUEUE; }
  71. Priority { return TOKEN_PRIORITY; }
  72. Transparent { return TOKEN_TRANSPARENT; }
  73. Technique { return TOKEN_TECHNIQUE; }
  74. Parameters { return TOKEN_PARAMETERS; }
  75. Blocks { return TOKEN_BLOCKS; }
  76. /* Technique keywords */
  77. Renderer { return TOKEN_RENDERER; }
  78. Language { return TOKEN_LANGUAGE; }
  79. Pass { return TOKEN_PASS; }
  80. /* Pass keywords */
  81. StencilRef { return TOKEN_STENCILREF; }
  82. /* Rasterizer state keywords */
  83. Fill { return TOKEN_FILLMODE; }
  84. Cull { return TOKEN_CULLMODE; }
  85. DepthBias { return TOKEN_DEPTHBIAS; }
  86. ScaledDepthBias { return TOKEN_SDEPTHBIAS; }
  87. DepthClip { return TOKEN_DEPTHCLIP; }
  88. Scissor { return TOKEN_SCISSOR; }
  89. Multisample { return TOKEN_MULTISAMPLE; }
  90. AALine { return TOKEN_AALINE; }
  91. /* Depth-stencil state keywords */
  92. DepthRead { return TOKEN_DEPTHREAD; }
  93. DepthWrite { return TOKEN_DEPTHWRITE; }
  94. CompareFunc { return TOKEN_COMPAREFUNC; }
  95. Stencil { return TOKEN_STENCIL; }
  96. StencilReadMask { return TOKEN_STENCILREADMASK; }
  97. StencilWriteMask { return TOKEN_STENCILWRITEMASK; }
  98. StencilOpFront { return TOKEN_STENCILOPFRONT; }
  99. StencilOpBack { return TOKEN_STENCILOPBACK; }
  100. Fail { return TOKEN_FAIL; }
  101. ZFail { return TOKEN_ZFAIL; }
  102. /* Blend state keywords */
  103. AlphaToCoverage { return TOKEN_ALPHATOCOVERAGE; }
  104. IndependantBlend { return TOKEN_INDEPENDANTBLEND; }
  105. Target { return TOKEN_TARGET; }
  106. Index { return TOKEN_INDEX; }
  107. Blend { return TOKEN_BLEND; }
  108. Color { return TOKEN_COLOR; }
  109. Alpha { return TOKEN_ALPHA; }
  110. WriteMask { return TOKEN_WRITEMASK; }
  111. Source { return TOKEN_SOURCE; }
  112. Dest { return TOKEN_DEST; }
  113. Op { return TOKEN_OP; }
  114. /* Sampler state keywords */
  115. AddressMode { return TOKEN_ADDRMODE; }
  116. MinFilter { return TOKEN_MINFILTER; }
  117. MagFilter { return TOKEN_MAGFILTER; }
  118. MipFilter { return TOKEN_MIPFILTER; }
  119. MaxAniso { return TOKEN_MAXANISO; }
  120. MipmapBias { return TOKEN_MIPBIAS; }
  121. MipMin { return TOKEN_MIPMIN; }
  122. MipMax { return TOKEN_MIPMAX; }
  123. BorderColor { return TOKEN_BORDERCOLOR; }
  124. U { return TOKEN_U; }
  125. V { return TOKEN_V; }
  126. W { return TOKEN_W; }
  127. /* Qualifiers */
  128. auto { return TOKEN_AUTO; }
  129. alias { return TOKEN_ALIAS; }
  130. shared { return TOKEN_SHARED; }
  131. usage { return TOKEN_USAGE; }
  132. /* State values */
  133. WIRE { yylval->intValue = FMV_Wire; return TOKEN_FILLMODEVALUE; }
  134. SOLID { yylval->intValue = FMV_Solid; return TOKEN_FILLMODEVALUE; }
  135. NOCULL { yylval->intValue = CMV_None; return TOKEN_CULLMODEVALUE; }
  136. CW { yylval->intValue = CMV_CW; return TOKEN_CULLMODEVALUE; }
  137. CCW { yylval->intValue = CMV_CCW; return TOKEN_CULLMODEVALUE; }
  138. FAIL { yylval->intValue = CFV_Fail; return TOKEN_COMPFUNCVALUE; }
  139. PASS { yylval->intValue = CFV_Pass; return TOKEN_COMPFUNCVALUE; }
  140. LT { yylval->intValue = CFV_LT; return TOKEN_COMPFUNCVALUE; }
  141. LTE { yylval->intValue = CFV_LTE; return TOKEN_COMPFUNCVALUE; }
  142. EQ { yylval->intValue = CFV_EQ; return TOKEN_COMPFUNCVALUE; }
  143. NEQ { yylval->intValue = CFV_NEQ; return TOKEN_COMPFUNCVALUE; }
  144. GTE { yylval->intValue = CFV_GTE; return TOKEN_COMPFUNCVALUE; }
  145. GT { yylval->intValue = CFV_GT; return TOKEN_COMPFUNCVALUE; }
  146. KEEP { yylval->intValue = OV_Keep; return TOKEN_OPVALUE; }
  147. ZERO { yylval->intValue = OV_Zero; return TOKEN_OPVALUE; }
  148. REPLACE { yylval->intValue = OV_Replace; return TOKEN_OPVALUE; }
  149. INC { yylval->intValue = OV_Incr; return TOKEN_OPVALUE; }
  150. DEC { yylval->intValue = OV_Decr; return TOKEN_OPVALUE; }
  151. INCWRAP { yylval->intValue = OV_IncrWrap; return TOKEN_OPVALUE; }
  152. DECWRAP { yylval->intValue = OV_DecrWrap; return TOKEN_OPVALUE; }
  153. INV { yylval->intValue = OV_Invert; return TOKEN_OPVALUE; }
  154. ONE { yylval->intValue = OV_One; return TOKEN_OPVALUE; }
  155. DSTRGB { yylval->intValue = OV_DestColor; return TOKEN_OPVALUE; }
  156. SRCRGB { yylval->intValue = OV_SrcColor; return TOKEN_OPVALUE; }
  157. DSTIRGB { yylval->intValue = OV_InvDestColor; return TOKEN_OPVALUE; }
  158. SRCIRGB { yylval->intValue = OV_InvSrcColor; return TOKEN_OPVALUE; }
  159. DSTA { yylval->intValue = OV_DestAlpha; return TOKEN_OPVALUE; }
  160. SRCA { yylval->intValue = OV_SrcAlpha; return TOKEN_OPVALUE; }
  161. DSTIA { yylval->intValue = OV_InvDestAlpha; return TOKEN_OPVALUE; }
  162. SRCIA { yylval->intValue = OV_InvSrcAlpha; return TOKEN_OPVALUE; }
  163. ADD { yylval->intValue = BOV_Add; return TOKEN_BLENDOPVALUE; }
  164. SUB { yylval->intValue = BOV_Subtract; return TOKEN_BLENDOPVALUE; }
  165. RSUB { yylval->intValue = BOV_RevSubtract; return TOKEN_BLENDOPVALUE; }
  166. MIN { yylval->intValue = BOV_Min; return TOKEN_BLENDOPVALUE; }
  167. MAX { yylval->intValue = BOV_Max; return TOKEN_BLENDOPVALUE; }
  168. NOCOLOR { yylval->intValue = 0x0; return TOKEN_COLORMASK; }
  169. R { yylval->intValue = 0x1; return TOKEN_COLORMASK; }
  170. G { yylval->intValue = 0x2; return TOKEN_COLORMASK; }
  171. B { yylval->intValue = 0x4; return TOKEN_COLORMASK; }
  172. A { yylval->intValue = 0x8; return TOKEN_COLORMASK; }
  173. RG { yylval->intValue = 0x3; return TOKEN_COLORMASK; }
  174. RB { yylval->intValue = 0x5; return TOKEN_COLORMASK; }
  175. RA { yylval->intValue = 0x9; return TOKEN_COLORMASK; }
  176. GB { yylval->intValue = 0x6; return TOKEN_COLORMASK; }
  177. GA { yylval->intValue = 0xA; return TOKEN_COLORMASK; }
  178. BA { yylval->intValue = 0xC; return TOKEN_COLORMASK; }
  179. RGB { yylval->intValue = 0x7; return TOKEN_COLORMASK; }
  180. RGA { yylval->intValue = 0xB; return TOKEN_COLORMASK; }
  181. RBA { yylval->intValue = 0xD; return TOKEN_COLORMASK; }
  182. GBA { yylval->intValue = 0xE; return TOKEN_COLORMASK; }
  183. RGBA { yylval->intValue = 0xF; return TOKEN_COLORMASK; }
  184. WRAP { yylval->intValue = AMV_Wrap; return TOKEN_ADDRMODEVALUE; }
  185. MIRROR { yylval->intValue = AMV_Mirror; return TOKEN_ADDRMODEVALUE; }
  186. CLAMP { yylval->intValue = AMV_Clamp; return TOKEN_ADDRMODEVALUE; }
  187. BORDER { yylval->intValue = AMV_Border; return TOKEN_ADDRMODEVALUE; }
  188. NOFILTER { yylval->intValue = FV_None; return TOKEN_FILTERVALUE; }
  189. POINT { yylval->intValue = FV_Point; return TOKEN_FILTERVALUE; }
  190. LINEAR { yylval->intValue = FV_Linear; return TOKEN_FILTERVALUE; }
  191. ANISO { yylval->intValue = FV_Anisotropic; return TOKEN_FILTERVALUE; }
  192. POINTC { yylval->intValue = FV_PointCmp; return TOKEN_FILTERVALUE; }
  193. LINEARC { yylval->intValue = FV_LinearCmp; return TOKEN_FILTERVALUE; }
  194. ANISOC { yylval->intValue = FV_AnisotropicCmp; return TOKEN_FILTERVALUE; }
  195. STATIC { yylval->intValue = BUV_Static; return TOKEN_BUFFERUSAGE; }
  196. DYNAMIC { yylval->intValue = BUV_Dynamic; return TOKEN_BUFFERUSAGE; }
  197. /* Preprocessor */
  198. #include { BEGIN(INCLUDE); }
  199. <INCLUDE>{WS} { /* Skip blank */ }
  200. <INCLUDE>{STRING} {
  201. int size = 0;
  202. char* includeBuffer = includePush(yyextra, yytext, yylineno, yycolumn, &size);
  203. if(!includeBuffer)
  204. yyterminate();
  205. YY_BUFFER_STATE currentBuffer = YY_CURRENT_BUFFER;
  206. YY_BUFFER_STATE newBuffer = yy_scan_buffer(includeBuffer, size, yyscanner);
  207. yy_switch_to_buffer(currentBuffer, yyscanner);
  208. yypush_buffer_state(newBuffer, yyscanner);
  209. yylineno = 0;
  210. yycolumn = 0;
  211. BEGIN(INITIAL);
  212. }
  213. <INCLUDE>. { return yytext[0]; }
  214. <<EOF>> {
  215. if(!yyextra->includeStack)
  216. yyterminate();
  217. yypop_buffer_state(yyscanner);
  218. includePop(yyextra);
  219. }
  220. /* Code blocks */
  221. Vertex { BEGIN(CODEBLOCK_HEADER); return TOKEN_VERTEX; }
  222. Fragment { BEGIN(CODEBLOCK_HEADER); return TOKEN_FRAGMENT; }
  223. Geometry { BEGIN(CODEBLOCK_HEADER); return TOKEN_GEOMETRY; }
  224. Hull { BEGIN(CODEBLOCK_HEADER); return TOKEN_HULL; }
  225. Domain { BEGIN(CODEBLOCK_HEADER); return TOKEN_DOMAIN; }
  226. Compute { BEGIN(CODEBLOCK_HEADER); return TOKEN_COMPUTE; }
  227. Common { BEGIN(CODEBLOCK_HEADER); return TOKEN_COMMON; }
  228. /* Track when the code block begins, insert all code block characters into our own buffer, record a sequential index */
  229. /* of all code blocks in the text, and track bracket open/closed state so we know when we're done with the code block. */
  230. /* And finally output a sequential code block index to the parser (it shouldn't be aware of anything else in the block). */
  231. <CODEBLOCK_HEADER>= { BEGIN(CODEBLOCK_EQUALS); return yytext[0]; }
  232. <CODEBLOCK_HEADER>{WS} { /* Skip blank */ }
  233. <CODEBLOCK_HEADER>. { return yytext[0]; }
  234. <CODEBLOCK_EQUALS>\{ { BEGIN(CODEBLOCK); beginCodeBlock(yyextra); yyextra->numOpenBrackets = 1; return yytext[0]; }
  235. <CODEBLOCK_EQUALS>{WS} { /* Skip blank */ }
  236. <CODEBLOCK_EQUALS>. { return yytext[0]; }
  237. <CODEBLOCK>\{ { yyextra->numOpenBrackets++; appendCodeBlock(yyextra, yytext[0]); }
  238. <CODEBLOCK>\} {
  239. yyextra->numOpenBrackets--;
  240. if(yyextra->numOpenBrackets == 0)
  241. {
  242. BEGIN(CODEBLOCK_END);
  243. unput('0');
  244. }
  245. else
  246. appendCodeBlock(yyextra, yytext[0]);
  247. }
  248. <CODEBLOCK>.|{SINGLEWS} { appendCodeBlock(yyextra, yytext[0]); }
  249. /* Logic for manually inserting "Index = codeBlockIndex;". We insert arbitrary numbers which allows us to sequentially */
  250. /* output all the tokens we need. We use only single-character values so we don't override anything in the text buffer */
  251. /* (since the starting value was also a single character "{"). */
  252. <CODEBLOCK_END>0 { unput('1'); return TOKEN_INDEX; }
  253. <CODEBLOCK_END>1 { unput('2'); return '='; }
  254. <CODEBLOCK_END>2 { yylval->intValue = getCodeBlockIndex(yyextra); unput('3'); return TOKEN_INTEGER; }
  255. <CODEBLOCK_END>3 { unput('4'); return ';'; }
  256. <CODEBLOCK_END>4 { BEGIN(INITIAL); return '}'; }
  257. <CODEBLOCK_END>.|{WS} { /* Never reached */ }
  258. /* Catch all rules */
  259. {COMMENT} { }
  260. {IDENTIFIER} { yylval->strValue = mmalloc_strdup(yyextra->memContext, yytext); return TOKEN_IDENTIFIER; }
  261. . { return yytext[0]; }
  262. %%