Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Page
Library
Module
Module type
Parameter
Class
Class type
Source
mustache_lexer.ml1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559# 22 "mustache/lib/mustache_lexer.mll" open Lexing open Mustache_parser exception Error of string let tok_arg lexbuf f = let start_p = lexbuf.Lexing.lex_start_p in let x = f lexbuf in lexbuf.Lexing.lex_start_p <- start_p; x let lex_tag lexbuf space ident tag_end = tok_arg lexbuf (fun lexbuf -> let () = space lexbuf in let name = ident lexbuf in let () = space lexbuf in let () = tag_end lexbuf in name ) let split_ident ident = if ident = "." then [] else String.split_on_char '.' ident let check_mustaches ~expected ~lexed = if expected <> lexed then raise (Error (Printf.sprintf "'%s' expected" expected)) # 32 "mustache/lib/mustache_lexer.ml" let __ocaml_lex_tables = { Lexing.lex_base = "\000\000\001\000\255\255\000\000\078\000\255\255\156\000\234\000\ \092\001\011\000\012\000\013\000\255\255\202\000\251\255\252\255\ \254\255\203\000\237\000\014\000\255\255\026\001\242\255\243\255\ \245\255\027\001\095\001\017\000\074\001\246\255\247\255\248\255\ \249\255\250\255\251\255\252\255\253\255\254\255"; Lexing.lex_backtrk = "\001\000\255\255\255\255\001\000\000\000\255\255\255\255\000\000\ \000\000\000\000\255\255\000\000\255\255\002\000\255\255\255\255\ \255\255\002\000\002\000\003\000\255\255\011\000\255\255\255\255\ \255\255\011\000\011\000\012\000\000\000\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255"; Lexing.lex_default = "\255\255\255\255\000\000\255\255\255\255\000\000\255\255\255\255\ \008\000\255\255\255\255\255\255\000\000\017\000\000\000\000\000\ \000\000\017\000\017\000\255\255\000\000\025\000\000\000\000\000\ \000\000\025\000\025\000\255\255\255\255\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000"; Lexing.lex_trans = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\002\000\002\000\000\000\001\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\004\000\005\000\004\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\004\000\004\000\000\000\000\000\000\000\000\000\004\000\ \000\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\004\000\004\000\004\000\006\000\004\000\004\000\004\000\ \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \010\000\011\000\012\000\020\000\028\000\000\000\000\000\004\000\ \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\000\000\000\000\000\000\000\000\004\000\000\000\004\000\ \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\007\000\000\000\007\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\016\000\016\000\000\000\018\000\ \018\000\000\000\000\000\000\000\000\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\007\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\007\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\007\000\007\000\007\000\016\000\ \000\000\000\000\018\000\007\000\000\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\007\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\007\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\007\000\007\000\007\000\007\000\ \006\000\007\000\007\000\007\000\007\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\024\000\024\000\000\000\026\000\ \026\000\000\000\000\000\007\000\007\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\007\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\007\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\007\000\015\000\255\255\019\000\ \255\255\007\000\000\000\007\000\007\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\007\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\007\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\007\000\255\255\255\255\000\000\ \255\255\024\000\255\255\029\000\026\000\035\000\030\000\000\000\ \036\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\033\000\000\000\000\000\255\255\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\031\000\000\000\ \032\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\027\000\255\255\023\000\ \255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \034\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\037\000\000\000\000\000\ \000\000\000\000\014\000\255\255\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\ \000\000\255\255\255\255\000\000\255\255\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\255\255\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\022\000\255\255\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\255\255\000\000\000\000\255\255\ "; Lexing.lex_check = "\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\000\000\000\000\001\000\255\255\000\000\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \000\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\003\000\003\000\003\000\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ \003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ \003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ \003\000\003\000\003\000\255\255\255\255\255\255\255\255\003\000\ \255\255\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ \003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ \003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ \003\000\003\000\003\000\004\000\004\000\004\000\004\000\004\000\ \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \009\000\010\000\011\000\019\000\027\000\255\255\255\255\004\000\ \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\255\255\255\255\255\255\255\255\004\000\255\255\004\000\ \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\006\000\255\255\006\000\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\013\000\017\000\255\255\013\000\ \017\000\255\255\255\255\255\255\255\255\006\000\006\000\006\000\ \006\000\006\000\006\000\006\000\006\000\006\000\006\000\006\000\ \006\000\006\000\006\000\006\000\006\000\006\000\006\000\006\000\ \006\000\006\000\006\000\006\000\006\000\006\000\006\000\018\000\ \255\255\255\255\018\000\006\000\255\255\006\000\006\000\006\000\ \006\000\006\000\006\000\006\000\006\000\006\000\006\000\006\000\ \006\000\006\000\006\000\006\000\006\000\006\000\006\000\006\000\ \006\000\006\000\006\000\006\000\006\000\006\000\006\000\007\000\ \007\000\007\000\007\000\007\000\007\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\021\000\025\000\255\255\021\000\ \025\000\255\255\255\255\007\000\007\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\007\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\007\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\007\000\013\000\017\000\013\000\ \017\000\007\000\255\255\007\000\007\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\007\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\007\000\007\000\007\000\007\000\ \007\000\007\000\007\000\007\000\007\000\008\000\008\000\255\255\ \018\000\026\000\018\000\028\000\026\000\028\000\028\000\255\255\ \028\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\028\000\255\255\255\255\008\000\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\028\000\255\255\ \028\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\021\000\025\000\021\000\ \025\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \028\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\028\000\255\255\255\255\ \255\255\255\255\013\000\017\000\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\008\000\ \255\255\008\000\026\000\255\255\026\000\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\018\000\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\021\000\025\000\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\008\000\255\255\255\255\026\000\ "; Lexing.lex_base_code = ""; Lexing.lex_backtrk_code = ""; Lexing.lex_default_code = ""; Lexing.lex_trans_code = ""; Lexing.lex_check_code = ""; Lexing.lex_code = ""; } let rec space lexbuf = __ocaml_lex_space_rec lexbuf 0 and __ocaml_lex_space_rec lexbuf __ocaml_lex_state = match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with | 0 -> # 78 "mustache/lib/mustache_lexer.mll" ( new_line lexbuf; space lexbuf ) # 229 "mustache/lib/mustache_lexer.ml" | 1 -> # 79 "mustache/lib/mustache_lexer.mll" ( () ) # 234 "mustache/lib/mustache_lexer.ml" | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf; __ocaml_lex_space_rec lexbuf __ocaml_lex_state and ident lexbuf = __ocaml_lex_ident_rec lexbuf 3 and __ocaml_lex_ident_rec lexbuf __ocaml_lex_state = match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with | 0 -> # 82 "mustache/lib/mustache_lexer.mll" ( lexeme lexbuf ) # 246 "mustache/lib/mustache_lexer.ml" | 1 -> # 83 "mustache/lib/mustache_lexer.mll" ( raise (Error "ident expected") ) # 251 "mustache/lib/mustache_lexer.ml" | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf; __ocaml_lex_ident_rec lexbuf __ocaml_lex_state and partial_name lexbuf = __ocaml_lex_partial_name_rec lexbuf 8 and __ocaml_lex_partial_name_rec lexbuf __ocaml_lex_state = match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with | 0 -> # 86 "mustache/lib/mustache_lexer.mll" ( lexeme lexbuf ) # 263 "mustache/lib/mustache_lexer.ml" | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf; __ocaml_lex_partial_name_rec lexbuf __ocaml_lex_state and end_on expected lexbuf = __ocaml_lex_end_on_rec expected lexbuf 9 and __ocaml_lex_end_on_rec expected lexbuf __ocaml_lex_state = match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with | 0 -> let # 89 "mustache/lib/mustache_lexer.mll" lexed # 276 "mustache/lib/mustache_lexer.ml" = Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos lexbuf.Lexing.lex_curr_pos in # 89 "mustache/lib/mustache_lexer.mll" ( check_mustaches ~expected ~lexed ) # 280 "mustache/lib/mustache_lexer.ml" | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf; __ocaml_lex_end_on_rec expected lexbuf __ocaml_lex_state and comment acc lexbuf = __ocaml_lex_comment_rec acc lexbuf 13 and __ocaml_lex_comment_rec acc lexbuf __ocaml_lex_state = match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with | 0 -> # 92 "mustache/lib/mustache_lexer.mll" ( String.concat "" (List.rev acc) ) # 292 "mustache/lib/mustache_lexer.ml" | 1 -> # 93 "mustache/lib/mustache_lexer.mll" ( new_line lexbuf; comment ((lexeme lexbuf) :: acc) lexbuf ) # 297 "mustache/lib/mustache_lexer.ml" | 2 -> # 94 "mustache/lib/mustache_lexer.mll" ( comment ((lexeme lexbuf) :: acc) lexbuf ) # 302 "mustache/lib/mustache_lexer.ml" | 3 -> # 95 "mustache/lib/mustache_lexer.mll" ( comment ((lexeme lexbuf) :: acc) lexbuf ) # 307 "mustache/lib/mustache_lexer.ml" | 4 -> # 96 "mustache/lib/mustache_lexer.mll" ( raise (Error "non-terminated comment") ) # 312 "mustache/lib/mustache_lexer.ml" | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf; __ocaml_lex_comment_rec acc lexbuf __ocaml_lex_state and mustache lexbuf = __ocaml_lex_mustache_rec lexbuf 21 and __ocaml_lex_mustache_rec lexbuf __ocaml_lex_state = match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with | 0 -> # 99 "mustache/lib/mustache_lexer.mll" ( ESCAPE (lex_tag lexbuf space ident (end_on "}}") |> split_ident) ) # 324 "mustache/lib/mustache_lexer.ml" | 1 -> # 100 "mustache/lib/mustache_lexer.mll" ( UNESCAPE (lex_tag lexbuf space ident (end_on "}}}") |> split_ident) ) # 329 "mustache/lib/mustache_lexer.ml" | 2 -> # 101 "mustache/lib/mustache_lexer.mll" ( UNESCAPE (lex_tag lexbuf space ident (end_on "}}") |> split_ident) ) # 334 "mustache/lib/mustache_lexer.ml" | 3 -> # 102 "mustache/lib/mustache_lexer.mll" ( OPEN_SECTION (lex_tag lexbuf space ident (end_on "}}") |> split_ident) ) # 339 "mustache/lib/mustache_lexer.ml" | 4 -> # 103 "mustache/lib/mustache_lexer.mll" ( OPEN_INVERTED_SECTION (lex_tag lexbuf space ident (end_on "}}") |> split_ident) ) # 344 "mustache/lib/mustache_lexer.ml" | 5 -> # 104 "mustache/lib/mustache_lexer.mll" ( CLOSE (lex_tag lexbuf space partial_name (end_on "}}")) ) # 349 "mustache/lib/mustache_lexer.ml" | 6 -> # 105 "mustache/lib/mustache_lexer.mll" ( PARTIAL (0, lex_tag lexbuf space partial_name (end_on "}}")) ) # 354 "mustache/lib/mustache_lexer.ml" | 7 -> # 106 "mustache/lib/mustache_lexer.mll" ( OPEN_PARTIAL_WITH_PARAMS (0, lex_tag lexbuf space partial_name (end_on "}}")) ) # 359 "mustache/lib/mustache_lexer.ml" | 8 -> # 107 "mustache/lib/mustache_lexer.mll" ( OPEN_PARAM (0, lex_tag lexbuf space ident (end_on "}}")) ) # 364 "mustache/lib/mustache_lexer.ml" | 9 -> # 108 "mustache/lib/mustache_lexer.mll" ( COMMENT (tok_arg lexbuf (comment [])) ) # 369 "mustache/lib/mustache_lexer.ml" | 10 -> # 109 "mustache/lib/mustache_lexer.mll" ( new_line lexbuf; RAW (lexeme lexbuf) ) # 374 "mustache/lib/mustache_lexer.ml" | 11 -> # 110 "mustache/lib/mustache_lexer.mll" ( RAW (lexeme lexbuf) ) # 379 "mustache/lib/mustache_lexer.ml" | 12 -> # 111 "mustache/lib/mustache_lexer.mll" ( RAW (lexeme lexbuf) ) # 384 "mustache/lib/mustache_lexer.ml" | 13 -> # 112 "mustache/lib/mustache_lexer.mll" ( EOF ) # 389 "mustache/lib/mustache_lexer.ml" | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf; __ocaml_lex_mustache_rec lexbuf __ocaml_lex_state ;; # 114 "mustache/lib/mustache_lexer.mll" (* Trim whitespace around standalone tags. The Mustache specification is careful with its treatment of whitespace. In particular, tags that do not themselves expand to visible content are defined as "standalone", with the requirement that if one or several standalone tags "stand alone" in a line (there is nothing else but whitespace), the whitespace of this line should be ommitted. For example, this means that: {{#foo}} I can access {{var}} inside the section. {{/foo} takes, once rendered, only 1 line instead of 3: the newlines after {{#foo}} and {{/foo}} are part of the "standalone whitespace", so they are not included in the output. Note: if a line contains only whitespace, no standalone tag, then the whitespace is preserved. We implement this by a post-processing past on the lexer token stream. We split the token stream, one sub-stream per line, and then for each token line we determine if satisfies the standalone criterion. Another information collected at the same time, as it is also part of whitespace processing, is the "indentation" of partials: if a partial expands to multi-line content, and if it is intended at the use-site (it is at a non-zero column with only whitespace before it on the line), then the specification mandates that all its lines should be indented by the same amount. We collect this information during the whitespace postprocessing of tokens, and store it in the Partial constructor as the first parameter. *) let handle_standalone lexer lexbuf = let ends_with_newline s = String.length s > 0 && s.[String.length s - 1] = '\n' in let get_loc () = lexbuf.Lexing.lex_curr_p in let get_tok () = let loc_start = get_loc () in let tok = lexer lexbuf in let loc_end = get_loc () in (tok, loc_start, loc_end) in let slurp_line lookahead = let rec start = function | None -> loop [] | Some lookahead -> continue [] lookahead and loop acc = continue acc (get_tok ()) and continue acc tok = match tok with | EOF, _, _ -> (List.rev (tok :: acc), None) | RAW s, _, _ when ends_with_newline s -> let lookahead = get_tok () in (List.rev (tok :: acc), Some lookahead) | _ -> loop (tok :: acc) in start lookahead in let count_indentation s = let i = ref 0 in let len = String.length s in while (!i < len && match s.[!i] with ' ' | '\t' | '\r' | '\n' -> true | _ -> false) do incr i done; !i in let is_blank s = count_indentation s = String.length s in let skip_blanks l = let rec loop skipped = function | (RAW s, _, _) :: toks when is_blank s -> loop (skipped + String.length s) toks | toks -> (skipped, toks) in loop 0 l in let trim_standalone toks lookahead = let toks = (* if the line starts with a partial, turn the skipped blank into partial indentation *) let (skipped, toks_after_blank) = skip_blanks toks in match toks_after_blank with | (PARTIAL (_ , name), loc1, loc2) :: rest -> (PARTIAL (skipped, name), loc1, loc2) :: rest | (OPEN_PARTIAL_WITH_PARAMS (_ , name), loc1, loc2) :: rest -> (OPEN_PARTIAL_WITH_PARAMS (skipped, name), loc1, loc2) :: rest | (OPEN_PARAM (_ , name), loc1, loc2) :: rest -> (* we want to count the indentation of {{$param}} blah blah {{/param}} as the indentation of 'blah blah', not the indentation of '{{$param}}' itself: using the parameter tag instead of the content as indentation would result in the content being over-indented at each occurrence. *) let skipped = match rest, lookahead with | ((RAW end_of_line, _, _) :: _), Some (RAW start_of_next_line, _, _) when ends_with_newline end_of_line -> count_indentation start_of_next_line | _ -> skipped in (OPEN_PARAM (skipped, name), loc1, loc2) :: rest | _ -> toks in let toks = (* if the line only contains whitespace and at least one standalone tags, remove all whitespace *) let rec standalone acc = function | (RAW s, _, _) :: rest when is_blank s -> (* omit whitespace *) standalone acc rest | ((OPEN_SECTION _ | OPEN_INVERTED_SECTION _ | CLOSE _ | PARTIAL _ | OPEN_PARTIAL_WITH_PARAMS _ | OPEN_PARAM _ | COMMENT _), _, _) as tok :: rest -> (* collect standalone tags *) standalone (tok :: acc) rest | [] | (EOF, _, _) :: _ -> (* end of line *) if (acc = []) then (* if acc is empty, the line only contains whitespace, which should be kept *) None else Some (List.rev acc) | _non_blank :: _rest -> (* non-blank, non-standalone token *) None in match standalone [] toks with | None -> toks | Some standalone_toks -> standalone_toks in assert (toks <> []); toks in let line_rest = ref [] in let lookahead = ref None in fun () -> match !line_rest with | next :: rest -> line_rest := rest; next | [] -> let next_line, next_lookahead = slurp_line !lookahead in let next_line = trim_standalone next_line next_lookahead in line_rest := List.tl next_line; lookahead := next_lookahead; List.hd next_line # 560 "mustache/lib/mustache_lexer.ml"