Skip to content

Commit 0db3c1b

Browse files
authored
fix syntax checker failing on constants (#162)
1 parent 1b6be2d commit 0db3c1b

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

classes/local/answer_parser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ private function is_acceptable_algebraic_formula(bool $fornumericalformula = fal
246246
];
247247
$operatorwhitelist = ['+', '_', '-', '/', '*', '**', '^', '%'];
248248
foreach ($answertokens as $token) {
249-
// Cut short, if it is a NUMBER token.
250-
if ($token->type === token::NUMBER) {
249+
// Cut short, if it is a NUMBER or CONSTANT token.
250+
if (in_array($token->type, [token::NUMBER, token::CONSTANT])) {
251251
continue;
252252
}
253253
if ($token->type === token::VARIABLE) {
@@ -310,7 +310,7 @@ private function is_valid_syntax(): bool {
310310
// should be only one single element on the stack.
311311
$stack = [];
312312
foreach ($tokens as $token) {
313-
if (in_array($token->type, [token::STRING, token::NUMBER, token::VARIABLE])) {
313+
if (in_array($token->type, [token::STRING, token::NUMBER, token::VARIABLE, token::CONSTANT])) {
314314
$stack[] = $token->value;
315315
}
316316
if ($token->type === token::OPERATOR) {

tests/answer_parser_test.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ public static function provide_algebraic_formulas(): array {
9898
[qtype_formulas::ANSWER_TYPE_NUMBER, 'pi'],
9999
[qtype_formulas::ANSWER_TYPE_NUMERIC, '3e8 4.e8 .5e8'],
100100
[qtype_formulas::ANSWER_TYPE_NUMERICAL_FORMULA, '- 3'],
101+
[qtype_formulas::ANSWER_TYPE_NUMERICAL_FORMULA, 'sin(3)'],
102+
[qtype_formulas::ANSWER_TYPE_NUMERICAL_FORMULA, 'sin(pi)'],
103+
[qtype_formulas::ANSWER_TYPE_NUMERICAL_FORMULA, 'sin(π)'],
101104
[qtype_formulas::ANSWER_TYPE_NUMERICAL_FORMULA, 'sin(3)-3+exp(4)'],
102105
[qtype_formulas::ANSWER_TYPE_NUMERICAL_FORMULA, '3+exp(4+5)^sin(6+7)'],
103106
[qtype_formulas::ANSWER_TYPE_NUMERICAL_FORMULA, '3+4^-(9)'],

version.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525
defined('MOODLE_INTERNAL') || die();
2626

2727
$plugin->component = 'qtype_formulas';
28-
$plugin->version = 2024100701;
28+
$plugin->version = 2025021400;
2929

3030
$plugin->cron = 0;
31-
$plugin->requires = 2017111300;
32-
$plugin->dependencies = array(
31+
$plugin->requires = 2022112800;
32+
$plugin->dependencies = [
3333
'qbehaviour_adaptive' => 2015111600,
3434
'qbehaviour_adaptivemultipart' => 2014092500,
3535
'qtype_multichoice' => 2015111600,
36-
);
37-
$plugin->supported = [39, 405];
38-
$plugin->release = '5.3.4.post0 for Moodle 3.9+';
36+
];
37+
$plugin->supported = [401, 405];
38+
$plugin->release = '6.0.0dev';
3939

40-
$plugin->maturity = MATURITY_STABLE;
40+
$plugin->maturity = MATURITY_RC;

0 commit comments

Comments
 (0)