123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115openBaseopenLiquid_syntaxopenSyntaxopenToolsletis_operator=function|"=="|">="|">"|"<="|"<"|"!="|"<>"->true|_->falseletlex_keywordtext=letkeywords=[("elsif",ElseIf);("else",Else);("if",If);("endif",EndIf);("unless",Unless);("endunless",EndUnless);("case",Case);("endcase",EndCase);("raw",Raw);("endraw",EndRaw);("when",When);("with",LexWith);("form",LexForm);("endform",LexEndForm);("style",LexStyle);("endstyle",LexEndStyle);("for",LexFor);("endfor",LexEndFor);("capture",Capture);("endcapture",EndCapture);("break",LexBreak);("continue",LexContinue);("cycle",Cycle);("tablerow",TableRow);("endtablerow",EndTableRow);("paginate",Paginate);("endpaginate",EndPaginate);("assign",Assign);("increment",Increment);("decrement",Decrement);("include",LexInclude);("layout",LexLayout);("render",LexRender);("section",LexSection);("in",In);("by",By);("as",LexAs);("==",OperatorEq);(">=",OperatorGte);(">",OperatorGt);("<=",OperatorLte);("<",OperatorLt);("!=",OperatorNe);("<>",OperatorNe);("contains",OperatorContains);("and",LexCombinerLexAnd);("or",LexCombinerLexOr);(":",Colon);("|",Pipe);("=",Equals);(",",Comma);(" ",Space);("\n",Newline);("nil",LexValueLexNil);("blank",LexValueLexBlank);("none",LexNone)]iniftext=" "||text="\n"thenNoneelsebegin(* words need a space, newline or eos (example: aspen != Keyword(As) Id(Pen)) *)letfinder(check_literal,_)=ifString.lengthcheck_literal=1||is_operatorcheck_literalthenstarts_withtextcheck_literalelsestarts_withtext(check_literal^" ")||starts_withtext(check_literal^"\n")||text=check_literal^" "inletfound_keyword=List.findkeywords~f:finderinmatchfound_keywordwith|Some(literal,token)->lettrimmed=remove_prefixtextliteralinSome(token,trimmed)|None->Noneendletblock_token_of_string=function|"{%"->StatementStartWhite|"%}"->StatementEndWhite|"{{"->ExpressionStartWhite|"}}"->ExpressionEndWhite|"{%-"->StatementStartTrim|"-%}"->StatementEndTrim|"{{-"->ExpressionStartTrim|"-}}"->ExpressionEndTrim|other->RawTextotherletis_block_token_stringt=matchblock_token_of_stringtwith|StatementStart_|StatementEnd_|ExpressionStart_|ExpressionEnd_->true|_->falseletis_block_token_whitespace_stringt=String.is_substringt~substring:"-"&&is_block_token_stringt