@@ -25,7 +25,7 @@ def _split_into_lines(self, tokens):
25
25
26
26
def parse_line (self , line ):
27
27
"""Parses a single line of tokens into a node."""
28
- print (f"Parsing line: { line } " )
28
+ # print(f"Parsing line: {line}")
29
29
if not line :
30
30
return None # handle empty lines
31
31
first_token = line [0 ]
@@ -118,11 +118,14 @@ def parse_if_statement(self, line):
118
118
body = []
119
119
# for every line starts with a tab, parse it as a body
120
120
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 } " )
122
121
# remove the identation token
123
122
line = self .lines [self .current_line ][1 :]
124
123
body .append (self .parse_line (line ))
125
124
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
126
129
return IfNode (condition , body )
127
130
128
131
def parse_assignment (self , line ):
@@ -160,9 +163,9 @@ def parse(self):
160
163
self .lines = self ._split_into_lines (self .tokens )
161
164
ast = []
162
165
while self .current_line < len (self .lines ):
163
- print (f"Current line: { self .current_line } " )
166
+ # print(f"Current line: {self.current_line}")
164
167
ast .append (self .parse_line (self .lines [self .current_line ]))
165
168
self .current_line += 1
166
- print (f"AST: { ast } " )
169
+ # print(f"AST: {ast}")
167
170
return ast
168
171
0 commit comments