Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file michelson_v1_parser.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)openProtocolopenTezos_michelineopenMicheline_parseropenMichelinetypeparsed={source:string;unexpanded:stringcanonical;expanded:Michelson_v1_primitives.primcanonical;expansion_table:(int*(Micheline_parser.location*intlist))list;unexpansion_table:(int*int)list;}letcompare_parsed=Stdlib.compare(* Unexpanded toplevel expression should be a sequence *)letexpand_allsourceasterrors=letunexpanded,loc_table=extract_locationsastinletexpanded,expansion_errors=Michelson_v1_macros.expand_rec(rootunexpanded)inletexpanded,unexpansion_table=extract_locationsexpandedinletexpansion_table=letsorted=List.sort(fun(_,a)(_,b)->Stdlib.compareab)unexpansion_tableinletgrouped=letrecgroup=function|acc,[]->acc|[],(u,e)::r->group([(e,[u])],r)|((pe,us)::raccasacc),(u,e)::r->ife=pethengroup((e,u::us)::racc,r)elsegroup((e,[u])::acc,r)ingroup([],sorted)inmatchList.map2~when_different_lengths:()(fun(l,ploc)(l',elocs)->assert(l=l');(l,(ploc,elocs)))(List.sortStdlib.compareloc_table)(List.sortStdlib.comparegrouped)with|Okv->v|Error()->invalid_arg"Michelson_v1_parser.expand_all"inmatchEnvironment.wrap_error(Michelson_v1_primitives.prims_of_stringsexpanded)with|Okexpanded->({source;unexpanded;expanded;expansion_table;unexpansion_table},errors@expansion_errors)|Errorerrs->({source;unexpanded;expanded=Micheline.strip_locations(Seq((),[]));expansion_table;unexpansion_table;},errors@expansion_errors@errs)letparse_toplevel?checksource=lettokens,lexing_errors=Micheline_parser.tokenizesourceinletasts,parsing_errors=Micheline_parser.parse_toplevel?checktokensinletast=letstart=min_pointastsandstop=max_pointastsinSeq({start;stop},asts)inexpand_allsourceast(lexing_errors@parsing_errors)letparse_expression?checksource=lettokens,lexing_errors=Micheline_parser.tokenizesourceinletast,parsing_errors=Micheline_parser.parse_expression?checktokensinexpand_allsourceast(lexing_errors@parsing_errors)letexpand_all~source~original=expand_allsourceoriginal[]