Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
paths[FUNCTION] = self.subroutine_decl
paths[RETURN] = self.return_statement
# paths[VAR] = self.var_statement
# paths[STATE] = self.state_block
# paths[FOR] = self.for_block
paths[RBRACKET] = self.right_bracket
paths[NEWLINE] = self.new_line
next_token = self.tokens.next()
if next_token.match in paths:
paths[next_token.match]()
return
# otherwise, parse as expression
expr = expression.parseExpression(self.tokens)
if expr:
expr.eval(self.builder)
return
# if we got this far then we don't know what the hell to do
pdb.set_trace()
raise parse_errors.NotAStatement(next_token)
def if_statement(self):
self.tokens.consume(IF)
self.tokens.startSkipping(NEWLINE)
self.tokens.consume(LPAREN)
# parse the condition expression
first_condition_token = self.tokens.next()
condition_expr = expression.parseExpression(self.tokens)
condition_term = condition_expr.eval(self.builder)
if condition_term == None:
raise parse_errors.ExpectedExpression(first_condition_token)
self.tokens.consume(RPAREN)
cond_block = self.builder.startConditionalBlock(condition=condition_term)
self.block_body()