Skip to content

Commit 4bb7424

Browse files
committed
cleaned up print statements
1 parent d465e43 commit 4bb7424

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

custom_parser.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def _split_into_lines(self, tokens):
2525

2626
def parse_line(self, line):
2727
"""Parses a single line of tokens into a node."""
28-
print(f"Parsing line: {line}")
28+
#print(f"Parsing line: {line}")
2929
if not line:
3030
return None # handle empty lines
3131
first_token = line[0]
@@ -118,11 +118,14 @@ def parse_if_statement(self, line):
118118
body = []
119119
# for every line starts with a tab, parse it as a body
120120
while self.current_line < len(self.lines) and self.is_indented(self.lines[self.current_line]):
121-
print(f"Current line in if body at total: {self.current_line}")
122121
# remove the identation token
123122
line = self.lines[self.current_line][1:]
124123
body.append(self.parse_line(line))
125124
self.current_line += 1
125+
# if the body is empty, raise an error
126+
if not body:
127+
raise ValueError(f"Expected body for if statement on line {self.current_line}")
128+
return None
126129
return IfNode(condition, body)
127130

128131
def parse_assignment(self, line):
@@ -160,9 +163,9 @@ def parse(self):
160163
self.lines = self._split_into_lines(self.tokens)
161164
ast = []
162165
while self.current_line < len(self.lines):
163-
print(f"Current line: {self.current_line}")
166+
#print(f"Current line: {self.current_line}")
164167
ast.append(self.parse_line(self.lines[self.current_line]))
165168
self.current_line += 1
166-
print(f"AST: {ast}")
169+
#print(f"AST: {ast}")
167170
return ast
168171

0 commit comments

Comments
 (0)