/** * Recursively filters out start and end markers * * Recursively filter out start and end markers from the regular expression * structure, since they do not have any real meaning, but were required to * create correct automatons. * * @param slRegularExpression $regularExpression * @return slRegularExpression */ protected function filterStartEndMarkers(slRegularExpression $regularExpression) { if ($regularExpression instanceof slRegularExpressionMultiple) { foreach ($regularExpression->getChildren() as $nr => $child) { if ($child instanceof slRegularExpressionElement && ($child->getContent() === 0 || $child->getContent() === 1)) { $regularExpression[$nr] = new slRegularExpressionEmpty(); } else { $this->filterStartEndMarkers($child); } } } if ($regularExpression instanceof slRegularExpressionSingular) { $child = $regularExpression->getChild(); if ($child instanceof slRegularExpressionElement && ($child->getContent() === 0 || $child->getContent() === 1)) { $regularExpression->setChild(new slRegularExpressionEmpty()); } else { $this->filterStartEndMarkers($child); } } return $regularExpression; }