function resolveNodes($code) { return preg_replace_callback('~(?<name>[A-Z][a-zA-Z_]++)\\s*' . PARAMS . '~', function ($matches) { // recurse $matches['params'] = resolveNodes($matches['params']); $params = magicSplit('(?:' . PARAMS . '|' . ARGS . ')(*SKIP)(*FAIL)|,', $matches['params']); $paramCode = ''; foreach ($params as $param) { $paramCode .= $param . ', '; } return 'new PHPParser_Node_' . $matches['name'] . '(' . $paramCode . '$attributes)'; }, $code); }
function resolveNodes($code) { return preg_replace_callback('~(?<name>[A-Z][a-zA-Z]++)' . PARAMS . '~', function ($matches) { // recurse $matches['params'] = resolveNodes($matches['params']); $params = magicSplit('(?:' . PARAMS . '|' . ARGS . ')(*SKIP)(*FAIL)|,', $matches['params']); $paramCodes = array(); foreach ($params as $param) { list($key, $value) = explode(': ', $param, 2); $paramCodes[] = '\'' . $key . '\' => ' . $value; } return 'new Node_' . $matches['name'] . '(array(' . implode(', ', $paramCodes) . '))'; }, $code); }
function resolveNodes($code) { return preg_replace_callback('~(?<name>[A-Z][a-zA-Z_]++)\\s*' . PARAMS . '~', function ($matches) { // recurse $matches['params'] = resolveNodes($matches['params']); $params = magicSplit('(?:' . PARAMS . '|' . ARGS . ')(*SKIP)(*FAIL)|,', $matches['params']); $paramCode = ''; foreach ($params as $param) { $paramCode .= $param . ', '; } if (substr($matches['name'], 0, 5) === 'Snow_') { $name = 'Snowscript_Node_' . substr($matches['name'], 5); } else { $name = 'PHPParser_Node_' . $matches['name']; } return 'new ' . $name . '(' . $paramCode . '$line, $docComment)'; }, $code); }