Skip to content
Snippets Groups Projects
Commit f4c38399 authored by Chris Sangwin's avatar Chris Sangwin
Browse files

Code tidy.

parent 18409e0c
No related branches found
No related tags found
No related merge requests found
......@@ -198,7 +198,8 @@ class stack_ast_container_silent implements cas_evaluatable {
// Get the filter pipeline. Now we only want the core filtters and
// append the strict syntax check to the end.
$pipeline = stack_parsing_rule_factory::get_filter_pipeline(array('996_call_modification', '998_security', '999_strict'), $filteroptions, true);
$pipeline = stack_parsing_rule_factory::get_filter_pipeline(array('996_call_modification', '998_security',
'999_strict'), $filteroptions, true);
if ($ast !== null) {
$ast = $pipeline->filter($ast, $errors, $answernotes, $securitymodel);
......
......@@ -28,7 +28,7 @@ abstract class stack_cas_castext2_block {
public $children;
// We have no clue what this would be in postprocess phase.
public $mathmode = false;
// Position data from the parser
// Position data from the parser.
public $position = null;
public function __construct(
......
......@@ -238,10 +238,10 @@ class stack_cas_castext2_jsxgraph extends stack_cas_castext2_block {
$valid = false;
if ($valids === null) {
$valids = ['width', 'height', 'aspect-ratio'];
if ($input_definitions !== null) {
if ($inputdefinitions !== null) {
$tmp = $root->get_parameter('ioblocks');
$inputs = [];
foreach ($input_definitions->get_names() as $key) {
foreach ($inputdefinitions->get_names() as $key) {
$inputs[] = "input-ref-$key";
}
$valids = array_merge($valids, $inputs);
......
......@@ -134,7 +134,6 @@ class stack_cas_keyval {
}
$this->security->set_context($vallist);
$this->valid = true;
$this->statements = array();
foreach ($ast->items as $item) {
......@@ -303,7 +302,8 @@ class stack_cas_keyval {
$errors = [];
$answernotes = [];
$filteroptions = ['998_security' => ['security' => 't']];
$pipeline = stack_parsing_rule_factory::get_filter_pipeline(['996_call_modification', '998_security', '999_strict'], $filteroptions, true);
$pipeline = stack_parsing_rule_factory::get_filter_pipeline(['996_call_modification', '998_security',
'999_strict'], $filteroptions, true);
$tostringparams = ['nosemicolon' => true, 'pmchar' => 1];
$securitymodel = $this->security;
......
......@@ -28,26 +28,27 @@ class stack_ast_filter_996_call_modification implements stack_cas_astfilter {
$process = function($node) use ($mapfuns) {
if ($node instanceof MP_Functioncall && !isset($node->position['997']) && !$node->is_definition()) {
if ($node->name instanceof MP_Atom && ($node->name->value === 'apply' || isset($mapfuns[$node->name->value]))) {
// apply(foo,...) => (_C(foo),_C(apply),apply(foo,...))
$replacement = new MP_Group([new MP_FunctionCall(new MP_Identifier('_C'),[$node->arguments[0]]), new MP_FunctionCall(new MP_Identifier('_C'),[$node->name]), $node]);
// E.g. apply(foo,...) => (_C(foo),_C(apply),apply(foo,...)).
$replacement = new MP_Group([new MP_FunctionCall(new MP_Identifier('_C'),
[$node->arguments[0]]), new MP_FunctionCall(new MP_Identifier('_C'), [$node->name]), $node]);
$replacement->items[0]->position['997'] = true;
$replacement->items[1]->position['997'] = true;
$replacement->items[2]->position['997'] = true;
$node->parentnode->replace($node, $replacement);
return false;
} else if ($node->name instanceof MP_Atom && ($node->name->value === 'at' || $node->name->value === 'subst')) {
// subst([f=g],g(x)) => (_C(subst),_CE(subst([f=g],g(x))))
$replacement = new MP_Group([new MP_FunctionCall(new MP_Identifier('_C'),[$node->name]), new MP_Functioncall(new MP_Identifier('_CE'),[$node])]);
// E.g. subst([f=g],g(x)) => (_C(subst),_CE(subst([f=g],g(x)))).
$replacement = new MP_Group([new MP_FunctionCall(new MP_Identifier('_C'), [$node->name]),
new MP_Functioncall(new MP_Identifier('_CE'), [$node])]);
$replacement->items[0]->position['997'] = true;
$replacement->items[1]->position['997'] = true;
$replacement->items[1]->arguments[0]->position['997'] = true;
$node->parentnode->replace($node, $replacement);
return false;
} else {
// f(x) => (_C(f),f(x))
// E.g. f(x) => (_C(f),f(x)).
$replacement = new MP_Group([new MP_FunctionCall(new MP_Identifier('_C'), [$node->name]), $node]);
$replacement->items[0]->position['997'] = true;
// 'f(x) => (_C(f),'f(x))
if ($node->parentnode instanceof MP_PrefixOp) {
$replacement->items[1] = $node->parentnode;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment