@@ -21,14 +21,14 @@ class Location:
21
21
end and input_str.
22
22
"""
23
23
24
- __slots__ = ['context' , 'file_name' ,
25
- '_line' , '_column' ,
26
- '_line_end' , '_column_end' ]
24
+ __slots__ = ['start_position' , 'end_position' , 'input_str' , 'file_name' ,
25
+ '_line' , '_column' , '_line_end' , '_column_end' ]
27
26
28
27
def __init__ (self , context = None , file_name = None ):
29
-
30
- self .context = context
31
- self .file_name = file_name or context .file_name
28
+ self .start_position = context .start_position if context else None
29
+ self .end_position = context .end_position if context else None
30
+ self .input_str = context .input_str if context else None
31
+ self .file_name = file_name or context .file_name if context else None
32
32
33
33
# Evaluate this only when string representation is needed.
34
34
# E.g. during error reporting
@@ -63,40 +63,26 @@ def column_end(self):
63
63
return self ._column_end
64
64
65
65
def evaluate_line_col (self ):
66
- context = self .context
67
66
self ._line , self ._column = pos_to_line_col (
68
- context .input_str , context .start_position )
67
+ self .input_str , self .start_position )
69
68
70
69
def evaluate_line_col_end (self ):
71
- context = self .context
72
- if hasattr (context , 'end_position' ) \
73
- and context .end_position :
70
+ if self .end_position :
74
71
self ._line_end , self ._column_end = \
75
- pos_to_line_col (context .input_str , context .end_position )
76
-
77
- def __getattr__ (self , name ):
78
- if self .context is not None :
79
- return getattr (self .context , name )
80
- else :
81
- raise AttributeError (name )
72
+ pos_to_line_col (self .input_str , self .end_position )
82
73
83
74
def __str__ (self ):
84
- if self .context is None :
85
- line , column = None , None
86
- else :
87
- line , column = self .line , self .column
88
- context = self .context
75
+ line , column = self .line , self .column
89
76
if line is not None :
90
77
return ('{}{}:{}:"{}"'
91
78
.format (f"{ self .file_name } :"
92
79
if self .file_name else "" ,
93
80
line , column ,
94
- position_context (context .input_str ,
95
- context .start_position )))
96
- elif self .file_name :
81
+ position_context (self .input_str ,
82
+ self .start_position )))
83
+ if self .file_name :
97
84
return _a (self .file_name )
98
- else :
99
- return "<Unknown location>"
85
+ return "<Unknown location>"
100
86
101
87
def __repr__ (self ):
102
88
return str (self )
0 commit comments