@@ -47,18 +47,34 @@ def as_marker(self) -> 'Marker':
47
47
@dataclass
48
48
class Marker (MarkerCompatible ):
49
49
"""
50
- See Marker.to_search_range
50
+ A marker can be one of:
51
+ - LINE with string/number value
52
+ - LINE REGEX with regex pattern
53
+ - LINE PREFIX with prefix string
54
+ - LINE SUFFIX with suffix string
55
+ - VARIABLE with name
56
+ - FUNCTION with name
57
+ - CLASS with name
58
+ See also: Marker.to_search_range
51
59
"""
52
60
type : MarkerType
53
61
value : str
54
62
offset : int | None = None
63
+ marker_subtype : str | None = None # 'REGEX', 'PREFIX', 'SUFFIX' for LINE type
55
64
56
65
@property
57
66
def as_marker (self ) -> 'Marker' :
58
67
return self
59
68
60
69
def __str__ (self ):
61
- result = f"{ self .type .value } '{ self .value .strip ()} '"
70
+ result = self .type .value
71
+ match self .marker_subtype :
72
+ case 'string' | None :
73
+ pass
74
+ case _:
75
+ result += self .marker_subtype .value
76
+
77
+ result += f" '{ self .value .strip ()} '"
62
78
if self .offset is not None :
63
79
result += f" at offset { self .offset } "
64
80
return result
@@ -533,13 +549,37 @@ def parse_region(self, node) -> Region:
533
549
return result
534
550
535
551
def parse_marker (self , node ) -> Marker :
536
- # TODO Fix: handle line marker as well
552
+ # Handle marker inside marker_or_segment
537
553
if node .type .casefold () == 'marker' :
538
554
node = node .named_children [0 ]
539
- marker_type = node .children [0 ].type # LINE, VARIABLE, FUNCTION, or CLASS
540
- value = self .parse_string (self .find_first_by_type (node .named_children , 'string' ))
555
+
556
+ marker_type = node .children [0 ].type # LINE, VARIABLE, FUNCTION, METHOD or CLASS
557
+ marker_subtype = None
558
+ value = None
559
+
560
+ if marker_type != 'LINE' : # VARIABLE, FUNCTION, METHOD or CLASS
561
+ value = self .parse_string (self .find_first_by_type (node .named_children , 'string' ))
562
+ # Handle the different marker types
563
+ else :
564
+ # Get the second child which is either a string/number or a subtype specifier
565
+ second_child = node .children [1 ]
566
+ marker_subtype = second_child .type
567
+ if second_child .type in ['string' , 'number' ]:
568
+ match second_child .type :
569
+ case 'string' :
570
+ value = self .parse_string (second_child )
571
+ case _:
572
+ value = second_child .text .decode ('utf8' )
573
+ else : # REGEX, PREFIX, or SUFFIX
574
+ value = self .parse_string (node .children [2 ])
575
+
541
576
offset = self .parse_offset_clause (self .find_first_by_type (node .named_children , 'offset_clause' ))
542
- return Marker (type = MarkerType (marker_type .casefold ()), value = value , offset = offset )
577
+ return Marker (
578
+ type = MarkerType (marker_type .casefold ()),
579
+ marker_subtype = marker_subtype ,
580
+ value = value ,
581
+ offset = offset
582
+ )
543
583
544
584
def parse_segment (self , node ) -> Segment :
545
585
relpos_start = self .find_first_by_type (node .named_children , 'relpos_segment_start' ).children [1 ]
0 commit comments