@@ -107,12 +107,13 @@ def __add_terms(self, step: Step, expr: List):
107
107
self .__anonymous_id += 1
108
108
self .__add_term (name , step , term_type )
109
109
elif term_type == TermType .DERIVE :
110
- name = FileContext .get_ident (expr [2 ][0 ])
111
- self .__add_term (name , step , term_type )
112
- if self .__ext_entry (expr [1 ]) == "Derive" :
113
- prop = FileContext .get_ident (expr [2 ][2 ])
114
- self .__add_term (prop , step , term_type )
115
- elif term_type == TermType .OBLIGATION :
110
+ for arg in expr [2 ]:
111
+ name = FileContext .get_ident (arg )
112
+ if name is not None :
113
+ self .__add_term (name , step , term_type )
114
+ elif term_type in [TermType .OBLIGATION , TermType .EQUATION ]:
115
+ # FIXME: For Equations, we are unable of getting terms from the AST
116
+ # but these commands do generate named terms
116
117
self .__last_terms [- 1 ].append (
117
118
("" , Term (step , term_type , self .__path , self .__segments .modules [:]))
118
119
)
@@ -241,12 +242,15 @@ def __term_type(self, expr: List) -> TermType:
241
242
return TermType .FIXPOINT
242
243
if expr [0 ] == "VernacScheme" :
243
244
return TermType .SCHEME
245
+ # FIXME: These are plugins and should probably be handled differently
244
246
if self .__is_extend (expr , "Obligations" ):
245
247
return TermType .OBLIGATION
246
248
if self .__is_extend (expr , "VernacDeclareTacticDefinition" ):
247
249
return TermType .TACTIC
248
250
if self .__is_extend (expr , "Function" ):
249
251
return TermType .FUNCTION
252
+ if self .__is_extend (expr , "Define_equations" , exact = False ):
253
+ return TermType .EQUATION
250
254
if self .__is_extend (expr , "Derive" , exact = False ):
251
255
return TermType .DERIVE
252
256
if self .__is_extend (expr , "AddSetoid" , exact = False ):
@@ -293,6 +297,16 @@ def __get_names(expr: List) -> List[str]:
293
297
stack .append (v )
294
298
return res
295
299
300
+ @staticmethod
301
+ def is_id (el ) -> bool :
302
+ return isinstance (el , list ) and (len (el ) == 3 and el [0 ] == "Ser_Qualid" )
303
+
304
+ @staticmethod
305
+ def is_notation (el ) -> bool :
306
+ return isinstance (el , list ) and (
307
+ len (el ) == 4 and el [0 ] == "CNotation" and el [2 ][1 ] != ""
308
+ )
309
+
296
310
@staticmethod
297
311
def get_id (id : List ) -> Optional [str ]:
298
312
# FIXME: This should be made private once [__step_context] is extracted
@@ -305,18 +319,18 @@ def get_id(id: List) -> Optional[str]:
305
319
306
320
@staticmethod
307
321
def get_ident (el : List ) -> Optional [str ]:
308
- # FIXME: This should be made private once [__get_program_context] is extracted
309
- # from ProofFile to here.
310
- if (
311
- len ( el ) == 3
312
- and el [ 0 ] == "GenArg"
313
- and el [ 1 ][0 ] == "Rawwit"
314
- and el [1 ][ 1 ][ 0 ] == "ExtraArg"
315
- ):
316
- if el [ 1 ][ 1 ][ 1 ] == "identref" :
317
- return el [ 2 ][ 0 ][ 1 ][ 1 ]
318
- elif el [1 ] [1 ][1 ] == "ident " :
319
- return el [2 ][1 ]
322
+ # FIXME: This method should be made private once [__get_program_context]
323
+ # is extracted from ProofFile to here.
324
+ def handle_arg_type ( args , ids ):
325
+ if args [ 0 ] == "ExtraArg" :
326
+ if args [ 1 ] == "identref" :
327
+ return ids [ 0 ][ 1 ][1 ]
328
+ elif args [1 ] == "ident" :
329
+ return ids [ 1 ]
330
+ return None
331
+
332
+ if len ( el ) == 3 and el [0 ] == "GenArg" and el [1 ][0 ] == "Rawwit " :
333
+ return handle_arg_type ( el [1 ][1 ], el [ 2 ])
320
334
return None
321
335
322
336
@staticmethod
@@ -546,6 +560,19 @@ def get_term(self, name: str) -> Optional[Term]:
546
560
return self .__terms [curr_name ][- 1 ]
547
561
return None
548
562
563
+ @staticmethod
564
+ def get_notation_scope (notation : str ) -> str :
565
+ """Get the scope of a notation.
566
+ Args:
567
+ notation (str): Possibly scoped notation pattern. E.g. "_ + _ : nat_scope".
568
+
569
+ Returns:
570
+ str: The scope of the notation. E.g. "nat_scope".
571
+ """
572
+ if notation .split (":" )[- 1 ].endswith ("_scope" ):
573
+ return notation .split (":" )[- 1 ].strip ()
574
+ return ""
575
+
549
576
def get_notation (self , notation : str , scope : str ) -> Term :
550
577
"""Get a notation from the context.
551
578
0 commit comments