Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file ast_payload.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)openPpxlibtypet=Parsetree.payloadletis_single_string(x:t)=matchxwith(* TODO also need detect empty phrase case *)|PStr[{pstr_desc=Pstr_eval({pexp_desc=Pexp_constant(Pconst_string(name,_,dec));_},_);_;};]->Some(name,dec)|_->None(* TODO also need detect empty phrase case *)letis_single_int(x:t):intoption=matchxwith|PStr[{pstr_desc=Pstr_eval({pexp_desc=Pexp_constant(Pconst_integer(name,_));_},_);_;};]->Some(int_of_stringname)|_->Noneletas_ident(x:t)=matchxwith|PStr[{pstr_desc=Pstr_eval({pexp_desc=Pexp_identident;_},_);_}]->Someident|_->Nonetypelid=stringAsttypes.loctypeaction=lid*Parsetree.expressionoption(* None means punning is hit
{[ { x } ]}
otherwise it comes with a payload
{[ { x = exp }]}
*)letunrecognizedConfigRecordtext="deriving: "^textletident_or_record_as_config(x:t):((stringLocation.loc*Parsetree.expressionoption)list,string)result=matchxwith|PStr[{pstr_desc=Pstr_eval({pexp_desc=Pexp_record(label_exprs,with_obj);_},_);_;};]->(matchwith_objwith|None->(letexceptionLocalintryOk(List.map(funu->matchuwith|({txt=Lidentname;loc},{Parsetree.pexp_desc=Pexp_ident{txt=Lidentname2;_};_;})whenname2=name->({Asttypes.txt=name;loc},None)|{txt=Lidentname;loc},y->({Asttypes.txt=name;loc},Somey)|_->raiseLocal)label_exprs)withLocal->Error(unrecognizedConfigRecord"Qualified label is not allowed"))|Some_->Error(unrecognizedConfigRecord"`with` is not supported, discarding"))|PStr[{pstr_desc=Pstr_eval({pexp_desc=Pexp_ident{loc=lloc;txt=Lidenttxt};_},_);_;};]->Ok[({Asttypes.txt;loc=lloc},None)]|PStr[]->Ok[]|_->Error(unrecognizedConfigRecord"invalid attribute config-record, ignoring")letassert_stringsloc(x:t):stringlist=letexceptionNot_strinmatchxwith|PStr[{pstr_desc=Pstr_eval({pexp_desc=Pexp_tuplestrs;_},_);pstr_loc=loc;_;};]->(tryList.map(fune->match(e:Parsetree.expression)with|{pexp_desc=Pexp_constant(Pconst_string(name,_,_));_}->name|_->raiseNot_str)strswithNot_str->Location.raise_errorf~loc"expect string tuple list")|PStr[{pstr_desc=Pstr_eval({pexp_desc=Pexp_constant(Pconst_string(name,_,_));_},_);_;};]->[name]|PStr[]->[]|PSig_|PStr_|PTyp_|PPat_->Location.raise_errorf~loc"expect string tuple list"lettable_dispatchtable(action:action)=matchactionwith|{txt=name;_},y->(matchMap_string.find_exntablenamewith|fn->Ok(fny)|exception_->Error("Unused attribute: "^name)(* Location.raise_errorf ~loc "%s is not supported" name *))letextract_mel_as_ident~locx=matchxwith|PStr[{pstr_desc=Pstr_eval({pexp_desc;_},_);_}]->(matchpexp_descwith|Pexp_constant(Pconst_string(name,_,_))|Pexp_construct({txt=Lidentname;_},_)|Pexp_ident{txt=Lidentname;_}->name|_->Location.raise_errorf~loc"Invalid `%@mel.as' payload. Expected a string or an ident.")|_->Location.raise_errorf~loc"Invalid attribute payload."