(***********************************************************************) (* *) (* Objective Caml *) (* *) (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) (* *) (* Copyright 1997 Institut National de Recherche en Informatique et *) (* Automatique. Distributed only by permission. *) (* *) (***********************************************************************) (* $Id: nsyntaxerr.ml,v 1.1.1.1 2002/01/16 09:01:22 cookcu Exp $ *) (* Auxiliary type for reporting syntax errors *) open Format open Location type err_kinds = IllegalAsPat | IllegalLabel | IllegalField | IllegalPat | IllegalRecBind | UnknownError | IllegalExpSeq | IllegalType | IllegalTypeId | IllegalExp | IllegalVarId | IllegalTypeVar | IllegalConId | IllegalDec | IllegalStrId | IllegalFctId | IllegalSigId | IllegalStrExp | IllegalSigExp type errmsg_kinds = EngGentle | HanGentle | HanTough let errmsg_type = ref HanGentle type error = Unclosed of Location.t * string * Location.t * string | Duptyid of Location.t * Location.t * string | Dupdatacon of Location.t * Location.t * string | Duppatvar of Location.t * Location.t * string | Orpaterr of Location.t | Other of Location.t * err_kinds exception Error of error exception Escape_error let msglist = [(IllegalAsPat, "As pattern must be used with variable pattern.", "As ÆÐÅÏ¿¡¼­Àº Ç×»ó º¯¼ö ÆÐÅϰú ¾²¿©¾ß ÇÕ´Ï´Ù.", "As ¾Õ¿¡´Â Ç×»ó º¯¼ö¸¸ ¿Â´Ù´Ï±î!!"); (IllegalLabel, "Illegal record label.", "À߸øµÈ ·¹ÄÚµå Ç¥Áö(label)ÀÔ´Ï´Ù.", "ÀÌ»óÇѰŠÀÚ²Ù ·¹ÄÚµå Ç¥Áö·Î ¾²Áö¸¶¶ó, ¼ýÀÚ¸¸ÀÌ´ø°¡ ¹®ÀÚ¸¸ÀÌ´ø°¡ ÇØ¾ß ÇѴٴϱî!!"); (IllegalField, "Illegal field of record pattern.", "·¹ÄÚµåÆÐÅÏÀÇ Çʵ尡 ÀÌ»óÇÕ´Ï´Ù.", "·¹ÄÚµå ¾È¿¡´Ù°¡ ÀÌ»óÇѰоµ·¡??"); (IllegalPat, "Illegal pattern.", "À߸øµÈ ÆÐÅÏÀÔ´Ï´Ù.", "À̰͵µ ÆÐÅÏÀ̶ó°í ½è³Ä??"); (IllegalRecBind, "Recursive variable must be bound to 'fn' expression.", "Àç±ÍÀûÀ¸·Î Á¤ÀÇµÈ º¯¼ö¿¡´Â Ç×»ó 'fn' Ç¥Çö¸¸ ¿Í¾ß ÇÕ´Ï´Ù.", "let rec ·Î Á¤ÀÇÇÒ·Á¸é, 'fn'¸¸ ¾²°Å¶ó, ´Ù¸¥°Ç ³­ ¾î¶»°Ô ÇÒ ÁÙ ¸ð¸£´Ï±î."); (IllegalExpSeq, "Sequence of expression must end with expression(Not semi-colon).", "ÇÁ·Î±×·¥ Ç¥ÇöÀÇ ³ª¿­Àº Ç×»ó ÇÁ·Î±×·¥ Ç¥ÇöÀ¸·Î ³¡³ª¾ß ÇÕ´Ï´Ù(¼¼¹ÌÄÝ·ÐÀº ¾ÈµË´Ï´Ù).", "ÇÁ·Î±×·¥ Ç¥ÇöÀ» ³ª¿­ÇÒ·Á¸é ¸Ç ³¡ÀÌ ÇÁ·Î±×·¥ Ç¥ÇöÀ̾î¾ß ÇÑ´Ù±¸. ¼¼¹ÌÄÝ·Ð °°Àº °É·Î ³¡³ª¸é ¾ÈµÅ."); (IllegalType, "This should be a proper type.", "¿Ã¹Ù¸¥ ŸÀÔÀÌ ¿Í¾ß ÇÕ´Ï´Ù.", "¿Ã¹Ù¸¥ ŸÀÔÀÌ ¿Í¾ß ÇÕ´Ï´Ù."); (IllegalTypeId, "This should be proper type identifier.", "¿Ã¹Ù¸¥ ŸÀÔ ½Äº°ÀÚ°¡ ¿Í¾ß ÇÕ´Ï´Ù.", "¿Ã¹Ù¸¥ ŸÀÔ ½Äº°ÀÚ°¡ ¿Í¾ß ÇÕ´Ï´Ù."); (IllegalExp, "This should be a proper expression.", "¿Ã¹Ù¸¥ Ç¥ÇöÀÌ ¿Í¾ß ÇÕ´Ï´Ù.", "¿Ã¹Ù¸¥ Ç¥ÇöÀÌ ¿Í¾ß ÇÕ´Ï´Ù."); (IllegalVarId, "This should be proper variable identifier.", "¿Ã¹Ù¸¥ º¯¼ö ½Äº°ÀÚ°¡ ¿Í¾ß ÇÕ´Ï´Ù.", "¿Ã¹Ù¸¥ º¯¼ö ½Äº°ÀÚ°¡ ¿Í¾ß ÇÕ´Ï´Ù."); (IllegalTypeVar, "This should be proper type variable.", "¿Ã¹Ù¸¥ ŸÀÔ º¯¼ö°¡ ¿Í¾ß ÇÕ´Ï´Ù.", "¿Ã¹Ù¸¥ ŸÀÔ º¯¼ö°¡ ¿Í¾ß ÇÕ´Ï´Ù."); (IllegalConId, "This should be proper constructor identifier.", "¿Ã¹Ù¸¥ »ý¼ºÀÚ ½Äº°ÀÚ°¡ ¿Í¾ß ÇÕ´Ï´Ù.", "¿Ã¹Ù¸¥ »ý¼ºÀÚ ½Äº°ÀÚ°¡ ¿Í¾ß ÇÕ´Ï´Ù."); (IllegalDec, "This should be proper declaration.", "¿Ã¹Ù¸¥ ¼±¾ðÀÌ ¿Í¾ß ÇÕ´Ï´Ù.", "¿Ã¹Ù¸¥ ¼±¾ðÀÌ ¿Í¾ß ÇÕ´Ï´Ù."); (IllegalStrId, "This should be proper structure identifer.", "¿Ã¹Ù¸¥ ±¸Á¶ ½Äº°ÀÚ°¡ ¿Í¾ß ÇÕ´Ï´Ù.", "¿Ã¹Ù¸¥ ±¸Á¶ ½Äº°ÀÚ°¡ ¿Í¾ß ÇÕ´Ï´Ù."); (IllegalFctId, "This should be proper functor identifer.", "¿Ã¹Ù¸¥ ÆãÅÍ ½Äº°ÀÚ°¡ ¿Í¾ß ÇÕ´Ï´Ù.", "¿Ã¹Ù¸¥ ÆãÅÍ ½Äº°ÀÚ°¡ ¿Í¾ß ÇÕ´Ï´Ù."); (IllegalSigId, "This should be proper signature identifier.", "¿Ã¹Ù¸¥ ½Ã±×³Êó ½Äº°ÀÚ°¡ ¿Í¾ß ÇÕ´Ï´Ù.", "¿Ã¹Ù¸¥ ½Ã±×³Êó ½Äº°ÀÚ°¡ ¿Í¾ß ÇÕ´Ï´Ù."); (IllegalStrExp, "This should be proper structure expressions.", "¿Ã¹Ù¸¥ ±¸Á¶ Ç¥ÇöÀÌ ¿Í¾ß ÇÕ´Ï´Ù.", "¿Ã¹Ù¸¥ ±¸Á¶ Ç¥ÇöÀÌ ¿Í¾ß ÇÕ´Ï´Ù."); (IllegalSigExp, "This should be proper signature expressions.", "¿Ã¹Ù¸¥ ½Ã±×³Êó Ç¥ÇöÀÌ ¿Í¾ß ÇÕ´Ï´Ù.", "¿Ã¹Ù¸¥ ½Ã±×³Êó Ç¥ÇöÀÌ ¿Í¾ß ÇÕ´Ï´Ù.") ] let print_err_kinds e = let (k,msg1,msg2,msg3) = try List.find (function (k,_,_,_) -> k = e) msglist with Not_found -> (UnknownError, "Unknown error ocurred.", "¾ËÁö¸øÇÏ´Â ¿À·ù°¡ ¹ß»ýÇß½À´Ï´Ù.", "ÀÌ°Ç ³ªµµ ¸ð¸£°Ú´Ù. ´Ï ¾Ë¾Æ¼­ ¾Ë¾ÆºÁ¶ó.") in print_string (match !errmsg_type with EngGentle -> msg1 | HanGentle -> msg2 | HanTough -> msg3) let report_error = function Unclosed(opening_loc, opening, closing_loc, closing) -> if String.length !Location.input_name = 0 && Location.highlight_locations opening_loc closing_loc then begin print_string (match !errmsg_type with EngGentle -> "Syntax error: '" | HanGentle -> "¹®¹ý»ó ¿À·ù: '" | HanTough -> "¸ÛûÇÑ ½Ç¼ö: '"); print_string closing; print_string (match !errmsg_type with EngGentle -> "' expected, the highlighted '" | HanGentle -> "' ÀÌ(°¡) ºüÁ® ÀÖ½À´Ï´Ù. Ç¥½ÃµÈ '" | HanTough -> "' À» »©¸Ô³Ä! ³»°¡ Ç¥½ÃÇÑ '"); print_string opening; print_string (match !errmsg_type with EngGentle -> "' might be unmatched" | HanGentle -> "' ÀÌ(°¡) ¦ÀÌ ¸ÂÁö ¾Ê´Â °Í °°½À´Ï´Ù." | HanTough -> "' ÀÌ ¾È¸ÂÀ» °ÍÀÌ´Ù. °íÃĶó."); end else begin Location.print std_formatter closing_loc; print_string (match !errmsg_type with EngGentle -> "Syntax error: '" | HanGentle -> "¹®¹ý»ó ¿À·ù: '" | HanTough -> "¸ÛûÇÑ ½Ç¼ö: '"); print_string closing; print_string (match !errmsg_type with EngGentle -> "' expected " | HanGentle -> "' ÀÌ(°¡) ºüÁ® ÀÖ½À´Ï´Ù. " | HanTough -> "' À» »©¸Ô¾ú±º! "); force_newline(); Location.print std_formatter opening_loc; print_string (match !errmsg_type with EngGentle -> "This '" | HanGentle -> "À§ÀÇ À§Ä¡ÀÇ '" | HanTough -> "À§¿¡ Ç¥½ÃÇÑ '"); print_string opening; print_string (match !errmsg_type with EngGentle -> "' might be unmatched" | HanGentle -> "' ÀÌ(°¡) ¦ÀÌ ¸ÂÁö ¾Ê´Â °Í °°½À´Ï´Ù." | HanTough -> "' ÀÌ ¾È¸ÂÀ» °ÍÀÌ´Ù. °íÃĶó.") end | Duptyid(previous_loc, current_loc, name) -> if String.length !Location.input_name = 0 && Location.highlight_locations previous_loc current_loc then begin print_string (match !errmsg_type with EngGentle -> "Syntax error: type name '" | HanGentle -> "¹®¹ý»ó ¿À·ù: ŸÀÔ À̸§ÀÎ '" | HanTough -> "¸ÛûÇÑ ½Ç¼ö: ŸÀÔ À̸§ÀÎ '"); print_string name; print_string (match !errmsg_type with EngGentle -> "' is duplicated at the highlighted positions" | HanGentle -> "' À»(¸¦) ÇϳªÀÇ Å¸ÀÔÁ¤Àdz»¿¡¼­ µÎ¹ø Á¤ÀÇÇÏ¿´½À´Ï´Ù. " ^"Ç¥½ÃµÈ ºÎºÐÀÌ µÎ ¹ø Á¤ÀÇµÈ ºÎºÐÀº ÀÔ´Ï´Ù." | HanTough -> "' ÀÌ Ç¥½ÃÇÑ ºÎºÐ¿¡ ¶È°°ÀÌ ³ª¿À´Â ±¸¸¸. ±×·³ ¾ÈµÇ¿©~") end else begin Location.print std_formatter current_loc; print_string (match !errmsg_type with EngGentle -> "Syntax error: type name '" | HanGentle -> "¹®¹ý»ó ¿À·ù: ŸÀÔ À̸§ÀÎ '" | HanTough -> "¸ÛûÇÑ ½Ç¼ö: ŸÀÔ À̸§ÀÎ '"); print_string name; print_string (match !errmsg_type with EngGentle -> "' previously appeared."; | HanGentle -> "' ÀÌ ÀÌ¹Ì ÇϳªÀÇ Å¸ÀÔÁ¤Àdz»¿¡¼­ ÀÌ¹Ì Á¤ÀǵǾú½À´Ï´Ù." | HanTough -> "' ÀÌ ÀÌ¹Ì ¾Õ¿¡µµ ÀÖ±º. ±×·³ ¾ÈµÇ¿©~~"); force_newline(); Location.print std_formatter previous_loc; print_string (match !errmsg_type with EngGentle -> "Previous position of the type name '"; | HanGentle -> "À§ÀÇ À§Ä¡¿¡ ÀÌ¹Ì Á¤ÀǵǾî ÀÖ½À´Ï´Ù." | HanTough -> "À§¿¡ ¸»ÇÑ °÷¿¡ ÀÖÀ¸´Ï, µÑÁßÀÇ Çϳª´Â ¹Ù²ã."); if !errmsg_type = EngGentle then ( print_string name; print_string "'" ) else () end | Duppatvar(previous_loc, current_loc, name) -> if String.length !Location.input_name = 0 && Location.highlight_locations previous_loc current_loc then begin print_string (match !errmsg_type with EngGentle -> "Syntax error: pattern variable '" | HanGentle -> "¹®¹ý»ó ¿À·ù: ÆÐÅÏ º¯¼öÀÎ '" | HanTough -> "¸ÛûÇÑ ½Ç¼ö: ÆÐÅÏ º¯¼öÀÎ '"); print_string name; print_string (match !errmsg_type with EngGentle -> "' is duplicated at the highlighted positions" | HanGentle -> "' ÀÌ(°¡) ÇÑ ÆÐÅÏ¿¡ µÎ¹ø ¾²¿´½À´Ï´Ù. "^ "Ç¥½ÃµÈ °÷ÀÇ È®ÀÎÇϼ¼¿ä" | HanTough -> "' À» ÇÑ ÆÐÅÏ¿¡ µÎ¹ø ¾²¸é ³ªº¸°í ¾î¶»°Ô Ç϶ó°í? "^ "³»°¡ Ç¥½ÃÇÑ °÷À» È®ÀÎÇØ º¸¼Å.") end else begin Location.print std_formatter current_loc; print_string (match !errmsg_type with EngGentle -> "Syntax error: pattern variable '" | HanGentle -> "¹®¹ý»ó ¿À·ù: ÆÐÅÏ º¯¼öÀÎ '" | HanTough -> "¸ÛûÇÑ ½Ç¼ö: ÆÐÅÏ º¯¼öÀÎ '"); print_string name; print_string (match !errmsg_type with EngGentle -> "' previously appeared." | HanGentle -> "' ÀÌ(°¡) °°Àº ÆÐÅϳ»¿¡¼­ ÀÌ¹Ì ¾²¿´½À´Ï´Ù." | HanTough -> "' Àº ÀÌ¹Ì ¾²°í ÀÖ´Â °ÍÀ̱¸¸¸. "); force_newline(); Location.print std_formatter previous_loc; print_string (match !errmsg_type with EngGentle -> "Previous position of the pattern variable '" | HanGentle -> "À§ÀÇ À§Ä¡¿¡ ÀÌ¹Ì Á¤ÀǵǾî ÀÖ½À´Ï´Ù." | HanTough -> "À§¿¡ ¸»ÇÑ °÷¿¡ ÀÖÀ¸´Ï, µÑÁßÀÇ Çϳª´Â ¹Ù²ã."); if !errmsg_type = EngGentle then ( print_string name; print_string "'" ) else () end | Dupdatacon(previous_loc, current_loc, name) -> if String.length !Location.input_name = 0 && Location.highlight_locations previous_loc current_loc then begin print_string (match !errmsg_type with EngGentle -> "Syntax error: data constructor '" | HanGentle -> "¹®¹ý»ó ¿À·ù: µ¥ÀÌŸ »ý¼ºÀÚ '" | HanTough -> "¸ÛûÇÑ ½Ç¼ö: µ¥ÀÌŸ »ý¼ºÀÚ '"); print_string name; print_string (match !errmsg_type with EngGentle -> "' is duplicated at the highlighted positions." | HanGentle -> "' °¡ ÇÑ Á¤Àdz»¿¡¼­ µÎ ¹øÀÌ»ó ¾²¿´½À´Ï´Ù." | HanTough -> "' ¸¦ µÎ¹ø Á¤ÀÇÇØ ¹ö¸®¸é ¾î¶»°Ô ÇϳÄ? Çϳª´Â ¹Ù²ã¶ó.") end else begin Location.print std_formatter current_loc; print_string (match !errmsg_type with EngGentle -> "Syntax error: data constructor '" | HanGentle -> "¹®¹ý»ó ¿À·ù: µ¥ÀÌŸ »ý¼ºÀÚ '" | HanTough -> "¸ÛûÇÑ ½Ç¼ö: µ¥ÀÌŸ »ý¼ºÀÚ '"); print_string name; print_string (match !errmsg_type with EngGentle -> "' previously appeared." | HanGentle -> "' ´Â °°Àº Á¤Àdz»¿¡¼­ ÀÌ¹Ì ¾²À̰í ÀÖ½À´Ï´Ù." | HanTough -> "' ´Â ÀÌ¹Ì Á¤ÀÇµÈ °ÍÀε¥? -.-"); force_newline(); Location.print std_formatter previous_loc; print_string (match !errmsg_type with EngGentle -> "Previous position of the data constructor '" | HanGentle -> "À§ÀÇ À§Ä¡¿¡ ÀÌ¹Ì Á¤ÀǵǾî ÀÖ½À´Ï´Ù." | HanTough -> "À§¿¡ ¸»ÇÑ °÷¿¡ ÀÖÀ¸´Ï, µÑÁßÀÇ Çϳª´Â ¹Ù²ã."); print_string name; print_string "'" end | Orpaterr (loc) -> if String.length !Location.input_name = 0 && Location.highlight_locations loc loc then begin print_string (match !errmsg_type with EngGentle -> "Syntax error: Or patterns must have same "^ "pattern variables" | HanGentle -> "¹®¹ý»ó ¿À·ù: Or ÆÐÅÏÀ¸·Î ¹­ÀÎ ÆÐÅϵéÀº ¾²´Â "^ "º¯¼öµéÀÌ °°¾Æ¾ß ÇÕ´Ï´Ù." | HanTough -> "¸ÛûÇÑ ½Ç¼ö: Or ÆÐÅϵ鿡 ¾²ÀÎ º¯¼ö´Â ¸ðµÎ "^ "°°¾Æ¾ß ÇÑ´Ù±¸. ¾È±×·¯¸é ÀÌ»óÇÏÀݾÆ?"); end else begin Location.print std_formatter loc; print_string (match !errmsg_type with EngGentle -> "Syntax error: Or patterns must have same "^ "pattern variables" | HanGentle -> "¹®¹ý»ó ¿À·ù: Or ÆÐÅÏÀ¸·Î ¹­ÀÎ ÆÐÅϵéÀº ¾²´Â "^ "º¯¼öµéÀÌ °°¾Æ¾ß ÇÕ´Ï´Ù." | HanTough -> "¸ÛûÇÑ ½Ç¼ö: Or ÆÐÅϵ鿡 ¾²ÀÎ º¯¼ö´Â ¸ðµÎ "^ "°°¾Æ¾ß ÇÑ´Ù±¸. ¾È±×·¯¸é ÀÌ»óÇÏÀݾÆ?"); end | Other (loc,e) -> if String.length !Location.input_name = 0 && Location.highlight_locations loc loc then begin print_string (match !errmsg_type with EngGentle -> "Syntax error: " | HanGentle -> "¹®¹ý»ó ¿À·ù: " | HanTough -> "¸ÛûÇÑ ½Ç¼ö: "); print_err_kinds e end else begin Location.print std_formatter loc; print_string (match !errmsg_type with EngGentle -> "Syntax error: " | HanGentle -> "¹®¹ý»ó ¿À·ù: " | HanTough -> "¸ÛûÇÑ ½Ç¼ö: "); print_err_kinds e end