-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_pointer.py
More file actions
46 lines (36 loc) · 1.75 KB
/
Copy pathstring_pointer.py
File metadata and controls
46 lines (36 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#########################################################################
# SAHIL PROGRAMMING LANGUAGE #
# author : Abdulbasit Rubeiyya #
#########################################################################
def string_pointer(text, pos_start, pos_end):
result = ''
# Calculate indices
idx_start = max(text.rfind('\n', 0, pos_start.idx), 0)
idx_end = text.find('\n', idx_start + 1)
if idx_end < 0: idx_end = len(text)
# Generate each line
line_count = pos_end.ln - pos_start.ln + 1
for i in range(line_count):
# Calculate line columns
line = text[idx_start:idx_end]
col_start = pos_start.col if i == 0 else 0
col_end = pos_end.col if i == line_count - 1 else len(line) - 1
# Append to result
result += line + '\n' #this helps to undeline the point where the erro has occured
result += ' ' * col_start + '^' * (col_end - col_start)
# Re-calculate indices
idx_start = idx_end
idx_end = text.find('\n', idx_start + 1)
if idx_end < 0: idx_end = len(text)
return result.replace('\t', '')
#########################################################################
# COMMENTS #
# #
#########################################################################
#This file point where the error is in the program, it will print the entire line and annotate where the error on that line is . eg
'''
sahil > 4*6/8 886 78
sintaksia batili: Tokeni inayotarajiwa ni '+', '-', '*' au '/' : Faili --, mstari wa 1
4*6/8 886 78
^^^^^^
'''