12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849openBaseopenPpxlibmoduleDirective=structtypet=If|Else|Elif|Endif|Ifdef|Ifndef|Define|Undef|Error|Warning|Import|(* deprecated, but provide useful warnings *)Elifdef|Elifndefletmatches~expectedmatched=String.(=)expectedmatched||String.(=)("optcomp."^expected)matched(* not using [matches] here because I'm pretty sure the pattern matching
compiler will make this faster than string equality. *)letof_string_opts=matchswith|"optcomp.if"|"if"->SomeIf|"optcomp.else"|"else"->SomeElse|"optcomp.elif"|"elif"->SomeElif|"optcomp.endif"|"endif"->SomeEndif|"optcomp.ifdef"|"ifdef"->SomeIfdef|"optcomp.ifndef"|"ifndef"->SomeIfndef|"optcomp.define"|"define"->SomeDefine|"optcomp.undef"|"undef"->SomeUndef|"optcomp.error"->SomeError|"optcomp.warning"|"warning"->SomeWarning|"optcomp.import"|"import"->SomeImport|"optcomp.elifdef"|"elifdef"->SomeElifdef|"optcomp.elifndef"|"elifndef"->SomeElifndef|_->Noneendtype'at=|Blockof'alist(** blocks with no optcomp extensions in it *)|DirectiveofDirective.t*location*payloadletmake_directivenamelocpayload=matchDirective.of_string_optnamewith|Somedir->Directive(dir,loc,payload)|None->Location.raise_errorf~loc"optcomp: unknown directive"letjust_directives_exn~locls=List.filter_mapls~f:(funtoken->matchtokenwith|Directive_asdir->Somedir|Block[]->None|Block_->Location.raise_errorf~loc"optcomp: only optcomp directives allowed in this context")