1
1
import logging
2
2
from dictionary import Dictionary
3
- from parser_nodes import AssignmentNode , ExpressionNode , NumberNode , IfNode , CellReferenceNode
3
+ from parser_nodes import AssignmentNode , ExpressionNode , NumberNode , StringNode , IfNode , CellReferenceNode
4
4
5
5
logger = logging .getLogger (__name__ )
6
6
@@ -71,6 +71,8 @@ def parse_primary(self, tokens):
71
71
token = tokens [0 ]
72
72
if token .type == Dictionary .INTEGER :
73
73
return NumberNode (token .value ), 1
74
+ elif token .type == Dictionary .STRING :
75
+ return StringNode (token .value ), 1
74
76
elif token .type == Dictionary .CELL :
75
77
return self .parse_cell_reference (token ), 1
76
78
elif token .type == Dictionary .LEFT_PARENTHESES :
@@ -146,11 +148,13 @@ def parse_assignment(self, line):
146
148
raise ValueError ("Invalid assignment statement" )
147
149
variable = tokens [0 ]
148
150
# if the variable is a cell reference, parse it
151
+ print (variable .type )
149
152
if variable .type == Dictionary .CELL :
150
153
variable = self .parse_cell_reference (variable )
151
154
# everything after the assignment token is the expression
152
155
variable_value = tokens [i + 1 :]
153
156
# if we only have 1 token, and it's an identifier, we can return the variable
157
+ print (variable_value [0 ].type )
154
158
if len (variable_value ) == 1 and variable_value [0 ].type == Dictionary .IDENTIFIER :
155
159
return AssignmentNode (variable , variable_value [0 ])
156
160
# otherwise, parse the expression
@@ -169,7 +173,7 @@ def parse_cell_reference(self, token):
169
173
raise ValueError ("Invalid cell reference" )
170
174
if not any (char in token .value for char in Dictionary .ALPHABETIC_CHARACTERS ):
171
175
raise ValueError ("Invalid cell reference" )
172
- if any (char not in Dictionary .NUMERIC_CHARACTERS + Dictionary .ALPHABETIC_CHARACTERS for char in token .value ):
176
+ if any (char not in Dictionary .NUMERIC_CHARACTERS | Dictionary .ALPHABETIC_CHARACTERS for char in token .value ):
173
177
raise ValueError ("Invalid cell reference" )
174
178
# there can be no numeric characters before the alphabetic characters. SO go through the string until we find a numeric character, and then check if the rest of the string is numeric
175
179
i = 0
0 commit comments