Repository navigation
Expand file tree
/
Copy pathstyle_grader_classes.py
More file actions
65 lines (55 loc) · 1.93 KB
/
Copy pathstyle_grader_classes.py
File metadata and controls
65 lines (55 loc) · 1.93 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
class SpacingTracker(object):
"""
Just a set of booleans to track spacing, modular in case this gets expanded.
"""
def __init__(self):
self.asts_left = False
self.asts_right = False
self.amps_left = False
self.amps_right = False
self.amps_both = False
class DataStructureTracker(object):
"""
Counter object to track braces so we know whether or not we're inside a code block.
"""
def __init__(self):
self.in_block = False
self.brace_stack = []
self.brace_index = 1
self.in_if = False
self.switch_brace_index = 0
self.length_so_far = 0
self.in_switch = False
self.switch_brace_stack = []
self.in_class_or_struct = False
self.in_public_or_private = False
self.class_or_struct_brace_stack = []
self.class_or_struct_brace_index = 0
self.in_cout_block = False
self.cout_index = 0
def add_object_brace(self, brace):
self.class_or_struct_brace_stack.append(brace)
self.class_or_struct_brace_index += 1
def add_switch_brace(self, brace):
self.switch_brace_stack.append(brace)
self.switch_brace_index += 1
def add_brace(self, brace):
self.brace_stack.append(brace)
self.brace_index += 1
def pop_brace(self):
self.brace_stack.pop()
self.brace_index -= 1
if self.brace_index == 0:
self.in_block = False
def pop_switch_brace(self):
self.switch_brace_stack.pop()
self.switch_brace_index -= 1
if self.switch_brace_index == 0:
self.in_switch = False
def pop_object_brace(self):
self.class_or_struct_brace_stack.pop()
self.class_or_struct_brace_index -= 1
if self.class_or_struct_brace_index == 0:
self.in_class_or_struct = False
def set_cout_block_status(self, in_block):
self.in_cout_block = in_block