-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheckgms_parsers.py
More file actions
executable file
·107 lines (95 loc) · 4.25 KB
/
checkgms_parsers.py
File metadata and controls
executable file
·107 lines (95 loc) · 4.25 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import os
import re
import sys
def parser(regex_string, file_handle, parse_memory_map=None, parse_value_index=0, parse_line_offset=0,
parse_instance=1, parse_integer=False, parse_case_sensitive=True, parse_multiline=False, parse_mode=None):
if parse_mode is None:
print(lr_box("parse_mode is undefined!"))
return
# parse_memory_map filter
if parse_case_sensitive:
regex = re.compile(str.encode(regex_string, 'ascii'), re.MULTILINE)
else:
regex = re.compile(
str.encode(
regex_string,
'ascii'),
re.IGNORECASE | re.MULTILINE)
if parse_memory_map is not None:
match = regex.search(parse_memory_map)
if not match:
return
instanceCount = 0
component = []
component.append(None)
"""
The regex below will allow us to parse out the floats/scientific notation with 1 digit or more to the right of the decimal:
re_value = re.compile(r"([-]{0,1}[0-9]{0,15}\.[0-9]{1,15}[E]{0,1}[-]{0,1}[+]{0,1}[0-9]{0,15})")
│ │ │ │ │ │ │ └── 0 or more (max 15) occurrences of digits between 0-9
│ │ │ │ │ │ └── 0 or 1 occurrence of "+"
│ │ │ │ │ └── 0 or 1 occurrence of "-"
│ │ │ │ └── 0 or 1 occurrence of "E"
│ │ │ └── 0 or more (max 15) occurrences of digits between 0-9
│ │ └── 1 occurence of "."
│ └── 0 or more (max 15) occurrences of digits between 0-9
└── 0 or 1 occurrence of "-"
"""
re_value = re.compile(
r"([-]{0,1}[0-9]{0,15}\.[0-9]{1,15}[E]{0,1}[-]{0,1}[+]{0,1}[0-9]{0,15})")
#
# The regex below will allow us to parse out integers
#
if parse_integer:
re_value = re.compile("([-]{0,1}[0-9]+)")
for line in file_handle:
if parse_case_sensitive:
re_component = re.compile(regex_string)
else:
re_component = re.compile(regex_string, re.IGNORECASE)
result_line = re_component.search(line)
if result_line is not None:
result_line = result_line.group()
if parse_multiline:
value = re_value.findall(result_line)
array = []
while len(value) > 0:
for x in value:
array.append(x)
next_line = next(file_handle)
value = re_value.findall(next_line)
component.append(array)
instanceCount = instanceCount + 1
if instanceCount == parse_instance:
if parse_value_index is not None:
# Return an array element
return component[-1][parse_value_index]
else:
# Return the entire array
return component[-1]
else:
desired_line = line
for i in range(0, parse_line_offset):
desired_line = next(file_handle)
value = re_value.findall(desired_line)
if value is not None:
try:
component.append(value[parse_value_index])
instanceCount = instanceCount + 1
if instanceCount == parse_instance:
return component[-1]
except BaseException:
pass
# Special case
if parse_instance < 0:
try:
if parse_multiline:
if parse_value_index is not None:
# Return an array element
return component[parse_instance][parse_value_index]
else:
# Return an array
return component[parse_instance]
else:
return component[parse_instance]
except BaseException:
return