From f198985c8d63033cccb106a1f0af2159b39d50ff Mon Sep 17 00:00:00 2001 From: "K. Andrew Parker" Date: Sun, 17 Mar 2024 13:33:55 -0400 Subject: [PATCH] MathObject version of the new Boolean context --- macros/contexts/contextReaction.pl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/macros/contexts/contextReaction.pl b/macros/contexts/contextReaction.pl index d561287dbf..7651805d65 100644 --- a/macros/contexts/contextReaction.pl +++ b/macros/contexts/contextReaction.pl @@ -276,6 +276,23 @@ sub cmp_postprocess { if $ans->{showTypeWarnings} && $ans->{student_value}{tree}->type ne 'Reaction'; } +# permit ions to be written at 2+ or simply + or - +# automatically added with cmp_call_filter (hence the additional argument) +sub cmp_prefilter { + my $self = shift; # technically, this is correct_value + my $ans = shift; + # parens are added by MQ when the ion digit leads - swap the order + $ans->{student_ans} =~ s/\^\((\d)([+-])\)/"^(".$2.$1.")"/ge; + # no parens when the ion digit is preceeded by +/-, + # modification is necessary to protect against next regex + $ans->{student_ans} =~ s/\^([+-])(\d)/"^(".$1.$2.")"/ge; + # only ions with no digits remain + $ans->{student_ans} =~ s/\^\(([+-])\)/"^(".$1."1)"/ge; + $ans->{student_ans} =~ s/\^([+-])/"^(".$1."1)"/ge; + warn "modified reaction: $ans->{student_ans}"; + return $ans; +} + # # Since the context only allows things that are comparable, we # don't really have to check anything. (But if somone added