BsLexerFX.l 16 KB

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