123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268(**************************************************************************)(* *)(* ACG development toolkit *)(* *)(* Copyright 2008-2021 INRIA *)(* *)(* More information on "http://acg.gforge.inria.fr/" *)(* License: CeCILL, see the LICENSE file or "http://www.cecill.info" *)(* Authors: see the AUTHORS file *)(* *)(* *)(* *)(* *)(* $Rev:: $: Revision of last commit *)(* $Author:: $: Author of last commit *)(* $Date:: $: Date of last commit *)(* *)(**************************************************************************)openUtilsLibletupdate_loclexbuffile=letpos=lexbuf.Lexing.lex_curr_pinletnew_file=matchfilewith|None->pos.Lexing.pos_fname|Somes->sinlexbuf.Lexing.lex_curr_p<-{poswithLexing.pos_fname=new_file;Lexing.pos_lnum=pos.Lexing.pos_lnum+1;Lexing.pos_bol=pos.Lexing.pos_cnum;}letinfix_as_prefix=refNoneletset_infixl=infix_as_prefix:=Somelletunset_infix()=infix_as_prefix:=None(*let bad_infix_usage () = !infix_as_prefix *)typelex_error=|Unstarted_comment|Unstarted_bracket|Mismatch_parenthesesofchar|Unclosed_comment|Expectofstring|Bad_tokentypeparse_error=|Syntax_errorofstring|Duplicated_termofstring|Duplicated_typeofstring|Binder_expectedofstring|Unknown_constantofstring|Not_def_as_infixofstring|Unknown_constant_nor_variableofstring|Unknown_constant_nor_typeofstring|Unknown_typeofstring|Missing_arg_of_Infixofstring|No_such_signatureofstring|No_such_lexiconofstring|Not_associativeofstring|Not_infixofstring|Prefix_missing_argofstring|Infix_missing_first_argofstring|Infix_missing_second_argofstringtypetype_error=|Already_defined_varofstring|Not_defined_varofstring|Not_defined_constofstring|Not_well_typed_termofstring*string|Not_well_typed_term_plusofstring*string*string|Not_well_kinded_typeofstring|Non_linear_varofstring|Linear_varofstring|Other|Is_Usedofstring*string|Two_occurrences_of_linear_variableof(Lexing.position*Lexing.position)|Non_empty_contextof(string*(Lexing.position*Lexing.position)*(Lexing.position*Lexing.position)*string)|Not_normal|Vacuous_abstractionof(string*(Lexing.position*Lexing.position))typeenv_error=|Duplicated_signatureofstring|Duplicated_lexiconofstring|Duplicated_entryofstringtypeversion_error=Outdated_versionof(string*string)typelexicon_error=|Missing_interpretationsof(string*string*(stringlist))typeerror=|Parse_errorofparse_error*(Lexing.position*Lexing.position)|Lexer_erroroflex_error*(Lexing.position*Lexing.position)|Type_erroroftype_error*(Lexing.position*Lexing.position)|Env_errorofenv_error*(Lexing.position*Lexing.position)|Version_errorofversion_error|Lexicon_erroroflexicon_error*(Lexing.position*Lexing.position)|System_errorofstringtypewarning=|Variable_or_constantof(string*(Lexing.position*Lexing.position))exceptionErroroferrorletcompute_comment_for_positionpos1pos2=letline2=pos2.Lexing.pos_lnuminletcol2=pos2.Lexing.pos_cnum-pos2.Lexing.pos_bolinletpos1=pos1inletline1=pos1.Lexing.pos_lnuminletcol1=pos1.Lexing.pos_cnum-pos1.Lexing.pos_bolinifline1=line2thenPrintf.sprintf"line %d, characters %d-%d"line2col1col2elsePrintf.sprintf"line %d, character %d to line %d, character %d"line1col1line2col2letlex_error_to_string=function|Unstarted_comment->"Syntax error: No comment opened before this closing of comment"|Unstarted_bracket->"Syntax error: No bracket opened before this right bracket"|Unclosed_comment->"Syntax error: Unclosed comment"|Mismatch_parenthesesc->Printf.sprintf"Syntax error: Unclosed parenthesis '%c'"c|Expects->Printf.sprintf"Syntax error: %s expected"s|Bad_token->"Lexing error: no such token allowed"letparse_error_to_string=function|Syntax_errors->Printf.sprintf"Syntax error: %s"s|Duplicated_typety->Printf.sprintf"Syntax error: Type \"%s\" has already been defined"ty|Duplicated_termte->Printf.sprintf"Syntax error: Term \"%s\" has already been defined"te|Binder_expectedid->Printf.sprintf"Syntax error: Unknown binder \"%s\""id|Unknown_constantid->Printf.sprintf"Syntax error: Unknown constant \"%s\""id|Not_def_as_infixid->Printf.sprintf"Syntax error: \"%s\" is not an infix operator"id|Unknown_constant_nor_variableid->Printf.sprintf"Syntax error: Unknown constant or variable \"%s\""id|Unknown_constant_nor_typeid->Printf.sprintf"Syntax error: Unknown constant or type \"%s\""id|Unknown_typeid->Printf.sprintf"Syntax error: Unknown atomic type \"%s\""id|Missing_arg_of_Infixid->Printf.sprintf"Syntax error: \"%s\" is defined as infix but used here with less than two arguments"id|No_such_signatures->Printf.sprintf"Syntax error: Signature id \"%s\" not in the current environment"s|No_such_lexicons->Printf.sprintf"Syntax error: Lexicon id \"%s\" not in the current environment"s|Not_associatives->Printf.sprintf"Syntax error: Operator \"%s\" is not associative but is used without parenthesis"s|Not_infixs->Printf.sprintf"Syntax error: Operator \"%s\" is not infix but is used as infix"s|Prefix_missing_args->Printf.sprintf"Syntax error: The prefix operator \"%s\" is missing its argument"s|Infix_missing_first_args->Printf.sprintf"Syntax error: The infix operator \"%s\" is missing its first argument"s|Infix_missing_second_args->Printf.sprintf"Syntax error: The infix operator \"%s\" is missing its first argument"slettype_error_to_string=function|Already_defined_vars->Printf.sprintf"Var \"%s\" is already defined"s|Not_defined_vars->Printf.sprintf"Var \"%s\" is not defined"s|Not_defined_consts->Printf.sprintf"Const \"%s\" is not defined"s|Not_well_typed_term(s,typ)->Printf.sprintf"Term \"%s\" not well typed.\nType expected : %s\n"styp|Not_well_typed_term_plus(s,typ,wrong_typ)->Printf.sprintf"Term \"%s\" not well typed.\n \"%s\" is of type %s but is here used with type %s\n"sstypwrong_typ|Not_well_kinded_types->Printf.sprintf"Type \"%s\" not well kinded"s|Non_linear_vars->Printf.sprintf"Var \"%s\" is supposed to be non linear"s|Linear_vars->Printf.sprintf"Var \"%s\" is supposed to be linear"s|Other->"Not yet implemented"|Is_Used(s1,s2)->Printf.sprintf"The type of this expression is \"%s\" but is used with type %s"s1s2|Two_occurrences_of_linear_variable(s,e)->Printf.sprintf"This linear variable was already used: %s"(compute_comment_for_positionse)|Non_empty_context(x,(s,e),funct_pos,funct_type)->Printf.sprintf"This term contains a free linear variable \"%s\" at %s and is argument the term of type \"%s\" at %s )"x(compute_comment_for_positionse)funct_type(compute_comment_for_position(fstfunct_pos)(sndfunct_pos))|Not_normal->"This term is not in normal form"|Vacuous_abstraction(x,(s,e))->Printf.sprintf"This linear variable \"%s\" is abstracted over but not used in term %s"x(compute_comment_for_positionse)letenv_error_to_string=function|Duplicated_signatures->Printf.sprintf"Syntax error: Signature id \"%s\" is used twice in this environment"s|Duplicated_lexicons->Printf.sprintf"Syntax error: Lexicon id \"%s\" is used twice in this environment"s|Duplicated_entrys->Printf.sprintf"Syntax error: Entry id \"%s\" is used twice in this environment"sletlexicon_error_to_string=function|Missing_interpretations(lex_name,abs_name,missing_inters)->Printf.sprintf"Lexicon definition error: Lexicon \"%s\" is missing the interpretations of the following terms of the abstract signature \"%s\":\n%s"lex_nameabs_name(Utils.string_of_list"\n"(funx->Printf.sprintf"\t%s"x)missing_inters)letversion_error_to_string=function|Outdated_version(old_v,current_v)->Printf.sprintf"You are trying to use an object file that was generated with a former version of the acgc compiler (version %s) while the current version of the compiler is %s"old_vcurrent_vletwarning_to_stringwinput_file=matchwwith|Variable_or_constant(s,(start,e))->Printf.sprintf"File \"%s\", %s\nWarning: %s"input_file(compute_comment_for_positionstarte)(Printf.sprintf"\"%s\" is a variable here, but is also declared as constant in the signature"s)leterror_msgeinput_file=letmsg,location_msg=matchewith|Parse_error(er,(s,e))->parse_error_to_stringer,Some(compute_comment_for_positionse)|Lexer_error(er,(s,e))->lex_error_to_stringer,Some(compute_comment_for_positionse)|Type_error(er,(s,e))->type_error_to_stringer,Some(compute_comment_for_positionse)|Env_error(er,(s,e))->env_error_to_stringer,Some(compute_comment_for_positionse)|Version_errorer->version_error_to_stringer,None|Lexicon_error(er,(s,e))->lexicon_error_to_stringer,Some(compute_comment_for_positionse)|System_errors->Printf.sprintf"System error: \"%s\""s,Noneinmatchlocation_msgwith|None->msg|Someloc->Printf.sprintf"File \"%s\", %s\n%s"input_filelocmsg(*
let dyp_error lexbuf =
let pos1=Lexing.lexeme_start_p lexbuf in
let pos2=Lexing.lexeme_end_p lexbuf in
match bad_infix_usage () with
| None -> Error (Parse_error (Dyp_error,(pos1,pos2)))
| Some (sym,(s,e)) -> Error (Parse_error (Missing_arg_of_Infix sym,(s,e)))
*)(*
let emit_warning w input_file =
match w with
| Variable_or_constant (_,(pos1,pos2)) ->
let msg = warning_to_string w input_file in
let line2 = pos2.Lexing.pos_lnum in
let col2 = pos2.Lexing.pos_cnum - pos2.Lexing.pos_bol in
let pos1 = pos1 in
let line1 = pos1.Lexing.pos_lnum in
let col1 = pos1.Lexing.pos_cnum - pos1.Lexing.pos_bol in
if line1=line2 then
Printf.sprintf "File \"%s\", line %d, characters %d-%d\nWarning: %s"
input_file line2 col1 col2 msg
else
Printf.sprintf "File \"%s\", from l:%d, c:%d to l:%d,c:%d\nWarning: %s"
input_file line1 col1 line2 col2 msg
*)letwarnings_to_stringinput_filews=Utils.string_of_list"\n"(funw->warning_to_stringwinput_file)wsletget_loc_error=function|Parse_error(_,(s,e))|Lexer_error(_,(s,e))|Type_error(_,(s,e))|Env_error(_,(s,e))|Lexicon_error(_,(s,e))->(s,e)|(Version_error_|System_error_)->failwith"Bug: should not occur"letget_string_error=function|Parse_error(er,pos)->parse_error_to_stringer,pos|Lexer_error(er,pos)->lex_error_to_stringer,pos|Type_error(er,pos)->type_error_to_stringer,pos|Env_error(er,pos)->env_error_to_stringer,pos|Lexicon_error(er,pos)->lexicon_error_to_stringer,pos|(Version_error_|System_error_)->failwith"Bug: should not occur"letchange_locerrpos=matcherrwith|Parse_error(er,_)->Parse_error(er,pos)|Lexer_error(er,_)->Lexer_error(er,pos)|Type_error(er,_)->Type_error(er,pos)|Env_error(er,_)->Env_error(er,pos)|Lexicon_error(er,_)->Lexicon_error(er,pos)|(Version_error_|System_error_)->failwith"Bug: should not occur"