Fixed another crash

This commit is contained in:
Bram Dingelstad 2021-12-07 10:33:03 +01:00
parent 753a504604
commit a57f2193d9
2 changed files with 20 additions and 3 deletions

View file

@ -412,6 +412,9 @@ func generate_assignment(node, assignment):
emit(Constants.ByteCode.Pop, node) emit(Constants.ByteCode.Pop, node)
func generate_expression(node, expression): func generate_expression(node, expression):
if self.assert(expression != null, 'Wrong expression (perhaps unterminated command block ">>"?)'):
return false
match expression.type: match expression.type:
Constants.ExpressionType.Value: Constants.ExpressionType.Value:
generate_value(node, expression.value) generate_value(node, expression.value)

View file

@ -25,7 +25,16 @@ func parse_node():
return WolNode.new('Start', null, self) return WolNode.new('Start', null, self)
func next_symbol_is(valid_types): func next_symbol_is(valid_types):
compiler.assert(tokens.size() != 0, 'Ran out of tokens looking for next symbol!') if tokens.size() == 0:
var error_tokens = []
for token in valid_types:
error_tokens.append(Constants.token_name(token))
if error_tokens == ['TagMarker']:
error_tokens.append('OptionEnd')
compiler.assert(tokens.size() != 0, 'Ran out of tokens looking for next symbol "%s"!' % PoolStringArray(error_tokens).join(', '))
return tokens.front() and tokens.front().type in valid_types return tokens.front() and tokens.front().type in valid_types
# NOTE: 0 look ahead for `<<` and `else` # NOTE: 0 look ahead for `<<` and `else`
@ -734,7 +743,8 @@ class ExpressionNode extends ParseNode:
#next token is parent - left #next token is parent - left
next = parser.expect_symbol([Constants.TokenType.LeftParen]) next = parser.expect_symbol([Constants.TokenType.LeftParen])
op_stack.push_back(next) if next:
op_stack.push_back(next)
elif next.type == Constants.TokenType.Comma: elif next.type == Constants.TokenType.Comma:
#resolve sub expression before moving on #resolve sub expression before moving on
@ -907,6 +917,10 @@ class ExpressionNode extends ParseNode:
if parser.compiler.assert(Operator.is_op(_type), 'Unable to parse expression!'): if parser.compiler.assert(Operator.is_op(_type), 'Unable to parse expression!'):
return false return false
# FIXME: Make sure there can't be a Null value here
if parser.compiler.assert(operator_stack.back() != null, 'Something went wrong getting precedence'):
return false
var second = operator_stack.back().type var second = operator_stack.back().type
if not Operator.is_op(second): if not Operator.is_op(second):