@@ -115,6 +115,7 @@ def __init__(self,
115115 self ._last_tactic_was_modified = False
116116 self ._last_modified_tactic : str | None = None
117117 self ._recursion_depth = 0
118+ self .max_threshold_for_tactic_length = 575 # Max 575 characters for a tactic
118119 if self ._enable_search :
119120 pass
120121 pass
@@ -166,6 +167,7 @@ def reset(self,
166167 self ._last_tactic_was_modified = False
167168 self ._last_modified_tactic : str | None = None
168169 self ._recursion_depth = 0
170+ self .max_threshold_for_tactic_length = 575 # Max 575 characters for a tactic
169171 if self ._enable_search :
170172 pass
171173 pass
@@ -285,7 +287,7 @@ def _get_lean_code_with_tactics(self, idx: int, stmt: str):
285287 tactics_so_far = self ._get_tactics_so_far ()
286288 assert len (tactics_so_far ) > 0 , "There should be at least one tactic so far"
287289 _ , _ , theorem_stmt = self ._last_theorem
288- return theorem_stmt + tactics_so_far
290+ return theorem_stmt + " \n " + tactics_so_far + " \n "
289291
290292 def _backtrack_tactic_line (self , idx : int ):
291293 # identify the keys to remove
@@ -354,7 +356,8 @@ def _reset_proof_context(self):
354356 def _set_proof_context (self ,
355357 proof_is_running : bool ,
356358 proof_goal_messages : List [str ],
357- last_tactic : LeanLineInfo ):
359+ last_tactic : LeanLineInfo ,
360+ errors : List [ErrorInfo ]):
358361 self ._proof_running = proof_is_running
359362 if self ._proof_running :
360363 proof_goals = []
@@ -363,13 +366,23 @@ def _set_proof_context(self,
363366 else :
364367 proof_goals = [g_text for g_text in proof_goal_messages
365368 if g_text is not None and len (g_text ) > 0 ]
366- self .proof_context = self ._parse_proof_context (proof_goals )
367- if self .proof_context == ProofContext .empty () and \
368- ((self ._enforce_qed and last_tactic .text .strip () == "done" ) or not self ._enforce_qed ):
369- self ._reset_proof_context ()
369+ if len (proof_goals ) == 0 and len (errors ) > 0 :
370+ # This means there are some errors which are similar to
371+ # masquerading as missing alignment or indentation errors
372+ # Ask to fix indentation or add an extra return to get the states
373+ self .lean_error_messages = [
374+ "The tactic seems to be correct but seems to have indentation issues."
375+ " Please check the proof steps and try adding appropriate indentation or add line breaks to fix the issue."
376+ ]
377+ else :
378+ self .proof_context = self ._parse_proof_context (proof_goals )
379+ if self .proof_context == ProofContext .empty () and \
380+ ((self ._enforce_qed and last_tactic .text .strip () == "done" ) or not self ._enforce_qed ):
381+ self ._reset_proof_context ()
382+ self .lean_error_messages .clear ()
370383 else :
371384 self .proof_context : ProofContext | None = None
372- self .lean_error_messages .clear ()
385+ self .lean_error_messages .clear ()
373386
374387 def _get_nested_haves_count (self , tactics : List [LeanLineInfo ], errors : List [ErrorInfo ]) -> int :
375388 # See all goal related error messages
@@ -383,7 +396,7 @@ def _get_nested_haves_count(self, tactics: List[LeanLineInfo], errors: List[Erro
383396 if tactic .text .strip ().startswith ("have" ):
384397 # Check if there is any goal related error after this tactic
385398 for error in goal_related :
386- if error .position .line == tactic .end_line :
399+ if error .position .line == tactic .end_line or error . position . line - 1 == tactic . end_line :
387400 nested_have_count += 1
388401 return nested_have_count
389402
@@ -461,7 +474,7 @@ def _update_proof_context(self, idx : int, tactics: List[LeanLineInfo], errors:
461474 if have_error_message is None :
462475 self ._nested_have_counts = self ._get_nested_haves_count (tactics , errors )
463476 self ._nested_calc_counts = self ._get_nested_calc_count (tactics , errors )
464- self ._set_proof_context (proof_is_running , proof_goal_messages , last_tactic )
477+ self ._set_proof_context (proof_is_running , proof_goal_messages , last_tactic , errors )
465478 else :
466479 self ._backtrack_tactic_line (idx )
467480 self .lean_error_messages = [have_error_message ]
@@ -504,13 +517,19 @@ def _update_proof_context(self, idx : int, tactics: List[LeanLineInfo], errors:
504517 def _run_stmt_on_lean_server (self , idx : int , stmt : str , theorem_started : bool = False ):
505518 assert self .tactic_parser is not None , "Tactic parser is not initialized"
506519 assert self ._content_till_last_theorem_stmt is not None , "Content till last theorem statement should not be None"
507- if len (stmt ) > SimpleLean4SyncExecutor .max_threshold_for_tactic_length :
520+ if len (stmt ) > self .max_threshold_for_tactic_length :
508521 self .lean_error_messages = [
509522 "The tactic length exceeds the maximum threshold of"
510- f" { SimpleLean4SyncExecutor .max_threshold_for_tactic_length } characters."
523+ f" { self .max_threshold_for_tactic_length } characters."
511524 " Please break down the tactic into smaller steps. And execute them one by one."
512525 ]
513526 return
527+ if '✝' in stmt :
528+ self .lean_error_messages = [
529+ "The tactic tries to use hypothesis ending with '✝', which are hidden."
530+ " Please use the `rename_i` tactic to rename such hypotheses, before using them."
531+ ]
532+ return
514533 if ("sorry" in stmt or "admit" in stmt ) and self ._proof_running :
515534 # We don't need to run the sorry statements. This should be treated as a failed proof step
516535 self .lean_error_messages = ["The tactic 'sorry/admit' was found in the statement, this is not allowed" ]
@@ -535,7 +554,7 @@ def _run_stmt_on_lean_server(self, idx : int, stmt: str, theorem_started: bool =
535554 proof_should_run = False
536555 if theorem_started :
537556 # Load the theorem context at once
538- self .tactic_parser .parse (
557+ full_parse_tacitcs , errors = self .tactic_parser .parse (
539558 self ._content_till_last_theorem_stmt ,
540559 fail_on_error = True ,
541560 parse_type = RequestType .CHKPT_TACTICS
@@ -549,7 +568,6 @@ def _run_stmt_on_lean_server(self, idx : int, stmt: str, theorem_started: bool =
549568 while not code_was_executed :
550569 # Run the statement in tactic mode
551570 code = self ._get_lean_code_with_tactics (idx , stmt )
552- self .logger .info (f"Running tactic on lean server at line { self .line_num } :\n { code } " )
553571 tactics , error_info = self .tactic_parser .parse (
554572 code ,
555573 fail_on_error = False ,
0 commit comments