function addFillNoValue($text) { $excluded = array(); $rule = excludeText($text, $excluded); $rule = str_replace("[", TEXT_BRACKET_LEFT, $rule); $rule = str_replace("]", TEXT_BRACKET_RIGHT, $rule); // hide module dot notations $rule = hideModuleNotations($rule, TEXT_MODULE_DOT); //echo '<BR/>' . $rule; $rule = includeText($rule, $excluded); $parser = new PHPParser_Parser(new PHPParser_Lexer()); $this->factory = new PHPParser_BuilderFactory(); $this->printer = new PHPParser_PrettyPrinter_Default(); $classextension = prepareClassExtension($text); $rootnode = $this->factory->class(CLASS_GETFILL . "_" . $classextension)->extend(CLASS_BASICFILL); $stmt = new PHPParser_Node_Stmt_Return(new PHPParser_Node_Scalar_String("")); try { //echo $rule . "<br/>"; $stmts = $parser->parse("<?php " . $rule . " ?>"); $stmt = $stmts[0]; $stmt = new PHPParser_Node_Arg($stmt); // encapsulate in fake Argument object, since updateVariables looks only at children of entered node $this->updateVariables($stmt); // fake method call for Q1[1,1] reference if ($stmt->value instanceof PHPParser_Node_Expr_MethodCall) { //print_r($stmt->value); $stmt = new PHPParser_Node_Stmt_Return($stmt->value); } else { //print_r($stmt->value->name); //echo 'hghghghghg'; //$stmt = new PHPParser_Node_Stmt_Return($stmt->value->name->args[0]->value); $stmt = new PHPParser_Node_Stmt_Return($stmt->value->name); } } catch (PHPParser_Error $e) { $this->addErrorMessage(Language::errorFillInvalid()); return; } /* add getFillValue function */ $getfillvalue = $this->factory->method(FUNCTION_GET_FILL_VALUE); $getfillvalue->makePublic(); $getfillvalue->addStmt($stmt); $rootnode->addStmt($getfillvalue); /* get statements */ $stmts = array($rootnode->getNode()); /* generate code */ $fillclass = $this->printer->prettyPrint($stmts); /* return result */ //echo $fillclass . "<hr>"; return $fillclass; }
function addAssignment(&$node, $instruction) { $rule = trim($instruction->getRule()); $rgid = trim($instruction->getRgid()); // hide text $excluded = array(); $rule = excludeText($rule, $excluded); // hide module dot notations $rule = hideModuleNotations($rule, TEXT_MODULE_DOT); // split left and right hand $split = splitString("/:=/", $rule); $lefthand = includeText($split[0], $excluded); $righthand = includeText($split[1], $excluded); $this->addToStatements("<div class='uscic-paperversion-for uscic-paperversion-nesting" . $this->nesting . "'><div class='uscic-paperversion-assignment'>" . includeText($rule, $excluded) . "</div></div>", 7); }
function addForLoop($instruction) { $rule = trim($instruction->getRule()); $rgid = trim($instruction->getRgid()); $rgidafter = $rgid; // hide text $excluded = array(); $rule = excludeText($rule, $excluded); // hide module dot notations $rule = hideModuleNotations($rule, TEXT_MODULE_DOT); // strip FOR $reversefor = 1; if (startsWith($rule, ROUTING_IDENTIFY_FORREVERSE)) { $rule = substr($rule, stripos($rule, ROUTING_IDENTIFY_FORREVERSE) + strlen(ROUTING_IDENTIFY_FORREVERSE)); $reversefor = 2; } else { $rule = substr($rule, stripos($rule, ROUTING_IDENTIFY_FOR) + strlen(ROUTING_IDENTIFY_FOR)); } /* multi-line for */ //if ($pos < 0) { if (endsWith(strtoupper($rule), ROUTING_IDENTIFY_DO) == false) { for ($cnt = $this->cnt + 1; $cnt <= sizeof($this->instructions); $cnt++) { if (isset($this->instructions[$cnt])) { $text = trim($this->instructions[$cnt]->getRule()); if (startsWith($text, "/*")) { $this->skipComments($cnt, $cnt); } else { if (startsWith($text, "//")) { } else { //$pos = strripos($text, ROUTING_IDENTIFY_DO); $rule .= " " . $text; //if ($pos > -1) { if (endsWith(strtoupper($rule), ROUTING_IDENTIFY_DO) == true) { $this->cnt = $cnt; $rgidafter = $this->instructions[$cnt]->getRgid(); break; } } } } } } $pos = strripos(strtoupper($rule), ROUTING_IDENTIFY_DO); if ($pos < 1) { $this->addErrorMessage(Language::errorForLoopMissingDo()); return; } // strip do $rule = trim(substr($rule, 0, $pos)); if (!contains(strtoupper($rule), " TO ")) { $this->addErrorMessage(Language::errorForLoopMissingTo()); return; } if (!contains(strtoupper($rule), ":=")) { $this->addErrorMessage(Language::errorForLoopMissingAssignment()); return; } // determine min and max $bounds = preg_split("/ to /i", $rule); $counterplusstart = splitString("/:=/", $bounds[0]); //print_r($excluded); $counterfield = includeText($counterplusstart[0], $excluded); $minimum = includeText($counterplusstart[1], $excluded); $maximum = includeText($bounds[1], $excluded); // check for array if (!is_numeric($minimum)) { $var = $this->survey->getVariableDescriptiveByName(getBasicName($minimum)); // new VariableDescriptive(); if ($var->isArray()) { if (!contains($minimum, "[")) { $this->addErrorMessage(Language::errorVariableNoArrayIndex(strtolower(getBasicName($minimum)))); } } } if (!is_numeric($maximum)) { $var = $this->survey->getVariableDescriptiveByName(getBasicName($maximum)); // new VariableDescriptive(); if ($var->isArray()) { if (!contains($maximum, "[")) { $this->addErrorMessage(Language::errorVariableNoArrayIndex(strtolower(getBasicName($maximum)))); } } } // replace [ and ] with ( and ), so the parser doesn't break // (we deal with these cases in the updateVariables function) $counterfield = str_replace("[", TEXT_BRACKET_LEFT, $counterfield); $counterfield = str_replace("]", TEXT_BRACKET_RIGHT, $counterfield); $minimum = str_replace("[", TEXT_BRACKET_LEFT, $minimum); $minimum = str_replace("]", TEXT_BRACKET_RIGHT, $minimum); $maximum = str_replace("[", TEXT_BRACKET_LEFT, $maximum); $maximum = str_replace("]", TEXT_BRACKET_RIGHT, $maximum); $parser = new PHPParser_Parser(new PHPParser_Lexer()); try { $stmts = $parser->parse("<?php " . $minimum . "?>"); // only one statement (no ; allowed in loop minimum) $stmt = $stmts[0]; $stmt = new PHPParser_Node_Arg($stmt); // encapsulate in fake Argument object, since updateVariables looks only at children of entered node $this->updateVariables($stmt); $min = $stmt; //echo 'min: ' . $minimum; $stmts = $parser->parse("<?php " . $maximum . "?>"); // only one statement (no ; allowed in loop maximum) $stmt = $stmts[0]; $stmt = new PHPParser_Node_Arg($stmt); // encapsulate in fake Argument object, since updateVariables looks only at children of entered node $this->updateVariables($stmt); $max = $stmt; //echo 'max: ' . $maximum; $stmts = $parser->parse("<?php " . $counterfield . "?>"); // only one statement (no ; allowed in loop maximum) $stmt = $stmts[0]; $stmt = new PHPParser_Node_Arg($stmt); // encapsulate in fake Argument object, since updateVariables looks only at children of entered node $this->updateVariables($stmt); //print_r($stmt); if ($stmt->value instanceof PHPParser_Node_Expr_MethodCall) { $counter = $stmt->value->var; } else { /* not a constant, which happens if the counter field does not exist */ if ($stmt->value->name instanceof PHPParser_Node_Expr_MethodCall) { $counter = $stmt->value->name->var; } else { $counter = new PHPParser_Node_Expr_Variable($counterfield); } } } catch (PHPParser_Error $e) { $this->addErrorMessage(Language::errorForLoopInvalid()); return; } // create for loop $temp = new PHPParser_Node_Expr_MethodCall($counter, FUNCTION_XI_GET_ANSWER, array($min)); $temp1 = new PHPParser_Node_Expr_MethodCall($counter, FUNCTION_XI_GET_ANSWER, array()); $temp2 = new PHPParser_Node_Expr_SmallerOrEqual($temp1, $max->value); $temp4 = new PHPParser_Node_Expr_Plus($temp1, new PHPParser_Node_Scalar_LNumber(1)); $temp3 = new PHPParser_Node_Expr_MethodCall($counter, FUNCTION_XI_GET_ANSWER, array($temp4)); $fillcall = "for (" . $this->printer->prettyPrint(array($temp)) . " " . $this->printer->prettyPrint(array($temp2)) . " " . $this->printer->prettyPrint(array($temp3)); // clean up $fillcall = str_replace(" . (", "", $fillcall); $fillcall = str_replace(" . ])", "]", $fillcall); $fillcall = str_replace("\n", "", trim(substr($fillcall, 0, strlen($fillcall) - 1))) . ") {\r\n"; // remove closing "}" $this->routing_output[$this->seid][] = $fillcall; }