@@ -1466,7 +1466,7 @@ public function add_special_variables(array $studentanswers, float $conversionfa
14661466 // We calculate the sum of squares of all model answers.
14671467 $ ssqmodelanswer = 0 ;
14681468 foreach ($ this ->get_evaluated_answers () as $ answer ) {
1469- if ($ answer === '$EMPTY ' || trim ( $ answer ) === '' ) {
1469+ if ($ answer === '$EMPTY ' ) {
14701470 continue ;
14711471 }
14721472 $ ssqmodelanswer += $ answer ** 2 ;
@@ -1554,13 +1554,12 @@ public function grade(array $response, bool $finalsubmit = false): array {
15541554 // failed evaluation, e.g. caused by an invalid answer.
15551555 $ this ->evaluator ->clear_stack ();
15561556
1557- // Evaluate, if not empty.
1558- if ($ answer === '"" ' || (empty ($ answer ) && !is_numeric ($ answer ))) {
1559- $ evaluated = new token (token::EMPTY , '$EMPTY ' );
1560- } else {
1561- $ evaluated = $ this ->evaluator ->evaluate ($ parser ->get_statements ())[0 ];
1562- }
1563- $ evaluatedresponse [] = token::unpack ($ evaluated ); // $evaluated;
1557+ // Evaluate. If the answer was empty (an empty string or the '$EMPTY'), the parser
1558+ // will create an appropriate evaluable statement or return an empty array. The evaluator,
1559+ // on the other hand, will know how to deal with the "false" return value from reset()
1560+ // and return the $EMPTY token.
1561+ $ statements = $ parser ->get_statements ();
1562+ $ evaluatedresponse [] = token::unpack ($ this ->evaluator ->evaluate (reset ($ statements )));
15641563 } catch (Throwable $ t ) {
15651564 // TODO: convert to non-capturing catch
15661565 // If parsing, validity check or evaluation fails, we consider the answer as wrong.
0 commit comments