123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559# 22 "mustache/lib/mustache_lexer.mll"openLexingopenMustache_parserexceptionErrorofstringlettok_arglexbuff=letstart_p=lexbuf.Lexing.lex_start_pinletx=flexbufinlexbuf.Lexing.lex_start_p<-start_p;xletlex_taglexbufspaceidenttag_end=tok_arglexbuf(funlexbuf->let()=spacelexbufinletname=identlexbufinlet()=spacelexbufinlet()=tag_endlexbufinname)letsplit_identident=ifident="."then[]elseString.split_on_char'.'identletcheck_mustaches~expected~lexed=ifexpected<>lexedthenraise(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="";}letrecspacelexbuf=__ocaml_lex_space_reclexbuf0and__ocaml_lex_space_reclexbuf__ocaml_lex_state=matchLexing.engine__ocaml_lex_tables__ocaml_lex_statelexbufwith|0-># 78 "mustache/lib/mustache_lexer.mll"(new_linelexbuf;spacelexbuf)# 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_bufflexbuf;__ocaml_lex_space_reclexbuf__ocaml_lex_stateandidentlexbuf=__ocaml_lex_ident_reclexbuf3and__ocaml_lex_ident_reclexbuf__ocaml_lex_state=matchLexing.engine__ocaml_lex_tables__ocaml_lex_statelexbufwith|0-># 82 "mustache/lib/mustache_lexer.mll"(lexemelexbuf)# 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_bufflexbuf;__ocaml_lex_ident_reclexbuf__ocaml_lex_stateandpartial_namelexbuf=__ocaml_lex_partial_name_reclexbuf8and__ocaml_lex_partial_name_reclexbuf__ocaml_lex_state=matchLexing.engine__ocaml_lex_tables__ocaml_lex_statelexbufwith|0-># 86 "mustache/lib/mustache_lexer.mll"(lexemelexbuf)# 263 "mustache/lib/mustache_lexer.ml"|__ocaml_lex_state->lexbuf.Lexing.refill_bufflexbuf;__ocaml_lex_partial_name_reclexbuf__ocaml_lex_stateandend_onexpectedlexbuf=__ocaml_lex_end_on_recexpectedlexbuf9and__ocaml_lex_end_on_recexpectedlexbuf__ocaml_lex_state=matchLexing.engine__ocaml_lex_tables__ocaml_lex_statelexbufwith|0->let# 89 "mustache/lib/mustache_lexer.mll"lexed# 276 "mustache/lib/mustache_lexer.ml"=Lexing.sub_lexemelexbuflexbuf.Lexing.lex_start_poslexbuf.Lexing.lex_curr_posin# 89 "mustache/lib/mustache_lexer.mll"(check_mustaches~expected~lexed)# 280 "mustache/lib/mustache_lexer.ml"|__ocaml_lex_state->lexbuf.Lexing.refill_bufflexbuf;__ocaml_lex_end_on_recexpectedlexbuf__ocaml_lex_stateandcommentacclexbuf=__ocaml_lex_comment_recacclexbuf13and__ocaml_lex_comment_recacclexbuf__ocaml_lex_state=matchLexing.engine__ocaml_lex_tables__ocaml_lex_statelexbufwith|0-># 92 "mustache/lib/mustache_lexer.mll"(String.concat""(List.revacc))# 292 "mustache/lib/mustache_lexer.ml"|1-># 93 "mustache/lib/mustache_lexer.mll"(new_linelexbuf;comment((lexemelexbuf)::acc)lexbuf)# 297 "mustache/lib/mustache_lexer.ml"|2-># 94 "mustache/lib/mustache_lexer.mll"(comment((lexemelexbuf)::acc)lexbuf)# 302 "mustache/lib/mustache_lexer.ml"|3-># 95 "mustache/lib/mustache_lexer.mll"(comment((lexemelexbuf)::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_bufflexbuf;__ocaml_lex_comment_recacclexbuf__ocaml_lex_stateandmustachelexbuf=__ocaml_lex_mustache_reclexbuf21and__ocaml_lex_mustache_reclexbuf__ocaml_lex_state=matchLexing.engine__ocaml_lex_tables__ocaml_lex_statelexbufwith|0-># 99 "mustache/lib/mustache_lexer.mll"(ESCAPE(lex_taglexbufspaceident(end_on"}}")|>split_ident))# 324 "mustache/lib/mustache_lexer.ml"|1-># 100 "mustache/lib/mustache_lexer.mll"(UNESCAPE(lex_taglexbufspaceident(end_on"}}}")|>split_ident))# 329 "mustache/lib/mustache_lexer.ml"|2-># 101 "mustache/lib/mustache_lexer.mll"(UNESCAPE(lex_taglexbufspaceident(end_on"}}")|>split_ident))# 334 "mustache/lib/mustache_lexer.ml"|3-># 102 "mustache/lib/mustache_lexer.mll"(OPEN_SECTION(lex_taglexbufspaceident(end_on"}}")|>split_ident))# 339 "mustache/lib/mustache_lexer.ml"|4-># 103 "mustache/lib/mustache_lexer.mll"(OPEN_INVERTED_SECTION(lex_taglexbufspaceident(end_on"}}")|>split_ident))# 344 "mustache/lib/mustache_lexer.ml"|5-># 104 "mustache/lib/mustache_lexer.mll"(CLOSE(lex_taglexbufspacepartial_name(end_on"}}")))# 349 "mustache/lib/mustache_lexer.ml"|6-># 105 "mustache/lib/mustache_lexer.mll"(PARTIAL(0,lex_taglexbufspacepartial_name(end_on"}}")))# 354 "mustache/lib/mustache_lexer.ml"|7-># 106 "mustache/lib/mustache_lexer.mll"(OPEN_PARTIAL_WITH_PARAMS(0,lex_taglexbufspacepartial_name(end_on"}}")))# 359 "mustache/lib/mustache_lexer.ml"|8-># 107 "mustache/lib/mustache_lexer.mll"(OPEN_PARAM(0,lex_taglexbufspaceident(end_on"}}")))# 364 "mustache/lib/mustache_lexer.ml"|9-># 108 "mustache/lib/mustache_lexer.mll"(COMMENT(tok_arglexbuf(comment[])))# 369 "mustache/lib/mustache_lexer.ml"|10-># 109 "mustache/lib/mustache_lexer.mll"(new_linelexbuf;RAW(lexemelexbuf))# 374 "mustache/lib/mustache_lexer.ml"|11-># 110 "mustache/lib/mustache_lexer.mll"(RAW(lexemelexbuf))# 379 "mustache/lib/mustache_lexer.ml"|12-># 111 "mustache/lib/mustache_lexer.mll"(RAW(lexemelexbuf))# 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_bufflexbuf;__ocaml_lex_mustache_reclexbuf__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.
*)lethandle_standalonelexerlexbuf=letends_with_newlines=String.lengths>0&&s.[String.lengths-1]='\n'inletget_loc()=lexbuf.Lexing.lex_curr_pinletget_tok()=letloc_start=get_loc()inlettok=lexerlexbufinletloc_end=get_loc()in(tok,loc_start,loc_end)inletslurp_linelookahead=letrecstart=function|None->loop[]|Somelookahead->continue[]lookaheadandloopacc=continueacc(get_tok())andcontinueacctok=matchtokwith|EOF,_,_->(List.rev(tok::acc),None)|RAWs,_,_whenends_with_newlines->letlookahead=get_tok()in(List.rev(tok::acc),Somelookahead)|_->loop(tok::acc)instartlookaheadinletcount_indentations=leti=ref0inletlen=String.lengthsinwhile(!i<len&&matchs.[!i]with' '|'\t'|'\r'|'\n'->true|_->false)doincridone;!iinletis_blanks=count_indentations=String.lengthsinletskip_blanksl=letrecloopskipped=function|(RAWs,_,_)::tokswhenis_blanks->loop(skipped+String.lengths)toks|toks->(skipped,toks)inloop0linlettrim_standalonetokslookahead=lettoks=(* if the line starts with a partial,
turn the skipped blank into partial indentation *)let(skipped,toks_after_blank)=skip_blankstoksinmatchtoks_after_blankwith|(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.
*)letskipped=matchrest,lookaheadwith|((RAWend_of_line,_,_)::_),Some(RAWstart_of_next_line,_,_)whenends_with_newlineend_of_line->count_indentationstart_of_next_line|_->skippedin(OPEN_PARAM(skipped,name),loc1,loc2)::rest|_->toksinlettoks=(* if the line only contains whitespace and at least one standalone tags,
remove all whitespace *)letrecstandaloneacc=function|(RAWs,_,_)::restwhenis_blanks->(* omit whitespace *)standaloneaccrest|((OPEN_SECTION_|OPEN_INVERTED_SECTION_|CLOSE_|PARTIAL_|OPEN_PARTIAL_WITH_PARAMS_|OPEN_PARAM_|COMMENT_),_,_)astok::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 *)NoneelseSome(List.revacc)|_non_blank::_rest->(* non-blank, non-standalone token *)Noneinmatchstandalone[]tokswith|None->toks|Somestandalone_toks->standalone_toksinassert(toks<>[]);toksinletline_rest=ref[]inletlookahead=refNoneinfun()->match!line_restwith|next::rest->line_rest:=rest;next|[]->letnext_line,next_lookahead=slurp_line!lookaheadinletnext_line=trim_standalonenext_linenext_lookaheadinline_rest:=List.tlnext_line;lookahead:=next_lookahead;List.hdnext_line# 560 "mustache/lib/mustache_lexer.ml"