Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file ast_payload.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161(* 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. *)openImportletis_single_string=(* TODO also need detect empty phrase case *)function|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=function|PStr[{pstr_desc=Pstr_eval({pexp_desc=Pexp_constant(Pconst_integer(name,_));_},_);_;};]->Some(int_of_stringname)|_->Noneletas_ident=function|PStr[{pstr_desc=Pstr_eval({pexp_desc=Pexp_identident;_},_);_}]->Someident|_->None(* None means punning is hit
{[ { x } ]}
otherwise it comes with a payload
{[ { x = exp }]}
*)letident_or_record_as_config=letexceptionLocalinletbase_error="Unsupported attribute payload. Expected a configuration record literal"inleterrormore=letmsg=matchmorewith|""->base_error|s->Format.sprintf"%s %s"base_errorsinErrormsginfunpayload:((stringLocation.loc*expressionoption)list,string)result->matchpayloadwith|PStr[{pstr_desc=Pstr_eval({pexp_desc=Pexp_record(label_exprs,with_obj);_},_);_;};]->(matchwith_objwith|None->(matchList.maplabel_exprs~f:(function|({txt=Lidentname;loc},{pexp_desc=Pexp_ident{txt=Lidentname2;_};_})whenString.equalname2name->({Asttypes.txt=name;loc},None)|{txt=Lidentname;loc},y->({Asttypes.txt=name;loc},Somey)|_->raiseLocal)with|r->Okr|exceptionLocal->error"(qualified labels aren't supported)")|Some_->error"(`with' not supported)")|PStr[{pstr_desc=Pstr_eval({pexp_desc=Pexp_ident{loc=lloc;txt=Lidenttxt};_},_);_;};]->Ok[({Asttypes.txt;loc=lloc},None)]|PStr[]->Ok[]|_->error""letassert_strings~locpayload:stringlist=matchpayloadwith|PStr[{pstr_desc=Pstr_eval({pexp_desc=Pexp_tuplestrs;_},_);_}]->List.mapstrs~f:(function|{pexp_desc=Pexp_constant(Pconst_string(name,_,_));_}->name|{pexp_loc;_}->Location.raise_errorf~loc:pexp_loc"Expected a tuple of string literals")|PStr[{pstr_desc=Pstr_eval({pexp_desc=Pexp_constant(Pconst_string(name,_,_));_},_);_;};]->[name]|PStr[]->[]|PSig_|PStr_|PTyp_|PPat_->Location.raise_errorf~loc"Expected a string or tuple of strings"letextract_mel_as_ident~locpayload=matchpayloadwith|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 string or simple ident.")|_->Location.raise_errorf~loc"Invalid attribute payload."