projects
/
fur
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Prevent assignment to a builtin variable
[fur]
/
parsing.py
diff --git
a/parsing.py
b/parsing.py
index
82c6528
..
91098f9
100644
(file)
--- a/
parsing.py
+++ b/
parsing.py
@@
-327,18
+327,28
@@
def _expression_statement_parser(index, tokens):
return (True, index, FurExpressionStatement(expression=expression))
return (True, index, FurExpressionStatement(expression=expression))
+BUILTINS = {'print', 'pow'}
+
def _assignment_statement_parser(index, tokens):
def _assignment_statement_parser(index, tokens):
- # TODO Use a FurSymbolExpression for the target? Maybe this is actually not a good idea
failure = (False, index, None)
failure = (False, index, None)
- if tokens[index].type != 'symbol':
+ if tokens[index].type == 'symbol':
+ target = tokens[index].match
+ target_assignment_line = tokens[index].line
+
+ index += 1
+ else:
return failure
return failure
- target = tokens[index].match
- index += 1
- if tokens[index].type != 'assignment_operator':
+
+ if tokens[index].type == 'assignment_operator':
+ if target in BUILTINS:
+ raise Exception(
+ 'Trying to assign to builtin "{}" on line {}'.format(target, target_assignment_line),
+ )
+ assignment_operator_index = index
+ else:
return failure
return failure
- assignment_operator_index = index
success, index, expression = _expression_parser(index + 1, tokens)
success, index, expression = _expression_parser(index + 1, tokens)