123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117(* This file is free software, part of dolmen. See file "LICENSE" for more information *)(* Printing of identifiers *)(* ************************************************************************* *)moduleL=LexerexceptionCannot_printofstringlet_cannot_printformat=Format.kasprintf(funmsg->raise(Cannot_printmsg))format(* lexical definitions taken from the smtlib specification *)let[@inline]is_whitespacec=letc=Char.codecinc=9(* tab *)||c=10(* line feed *)||c=13(* cariage return *)||c=32(* space *)let[@inline]is_printablec=letc=Char.codecin(32<=c&&c<=126)||128<=cletis_quoted_symbol_charc=(is_whitespacec||is_printablec)&&(c<>'|'&&c<>'\\')let[@inline]is_letter=function|'a'..'z'|'A'..'Z'->true|_->falselet[@inline]is_digit=function|'0'..'9'->true|_->falselet[@inline]is_other_simple_symbol_chars=function|'~'|'!'|'@'|'$'|'%'|'^'|'&'|'*'|'_'|'-'|'+'|'='|'<'|'>'|'.'|'?'|'/'->true|_->falseletis_simple_symbol_charc=is_letterc||is_digitc||is_other_simple_symbol_charsc(* symbol categorization *)typesymbol=|Simple|Quoted|Unprintableletcategorize_symbols=matchswith|""->Unprintable|"_"|"!"|"as"|"let"|"exists"|"forall"|"match"|"par"|"assert"|"check-sat"|"check-sat-assuming"|"declare-const"|"declare-datatype"|"declare-datatypes"|"declare-fun"|"declare-sort"|"define-fun"|"define-fun-rec"|"define-funs-rec"|"define-sort"|"echo"|"exit"|"get-assertions"|"get-assignment"|"get-info"|"get-model"|"get-option"|"get-proof"|"get-unsat-assumptions"|"get-unsat-core"|"get-value"|"pop"|"push"|"reset"|"reset-assertions"|"set-info"|"set-logic"|"set-option"->Quoted|_->(* we are guaranteed that `s` is not the empty string *)ifnot(is_digits.[0])&&(Dolmen_std.Misc.string_for_allis_simple_symbol_chars)thenSimpleelseifDolmen_std.Misc.string_for_allis_quoted_symbol_charsthenQuotedelseUnprintableletidfmtname=letauxfmts=(* TODO: expose/add a cache to not redo the `categorize_symbol` computation each time *)matchcategorize_symbolswith|Simple->Format.pp_print_stringfmts|Quoted->Format.fprintffmt"|%s|"s|Unprintable->_cannot_print"symbol \"%s\" cannot be printed due to lexical constraints"sinmatch(name:Dolmen_std.Name.t)with|Simples->auxfmts|Indexed{basename=_;indexes=[]}->_cannot_print"indexed id with no indexes: %a"Dolmen_std.Name.printname|Indexed{basename;indexes;}->letpp_sepfmt()=Format.fprintffmt" "inFormat.fprintffmt"(_ %a %a)"auxbasename(Format.pp_print_list~pp_sepaux)indexes|Qualified_->_cannot_print"qualified identifier: %a"Dolmen_std.Name.printname