mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 02:02:41 +01:00
Add option to symbol import script to ignore errors in input
Summary: I was running the generate_ctags_symbols script on a project, and some combination of this script and ctags was generating invalid rows for this script. It's nice if this script can ignore invalid input instead of having to add another step to filter out invalid input. Test Plan: run script with input that has some invalid lines Reviewers: epriestley, vrana Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3532
This commit is contained in:
parent
5a5d0b2b56
commit
d591007d27
2 changed files with 78 additions and 60 deletions
|
@ -73,6 +73,11 @@ foreach (Futures($futures)->limit(8) as $file => $future) {
|
||||||
list($token, $file_path, $line_num) = $tag_info;
|
list($token, $file_path, $line_num) = $tag_info;
|
||||||
list($type, $language, $context) = $extension_fields;
|
list($type, $language, $context) = $extension_fields;
|
||||||
|
|
||||||
|
// skip lines with tokens containing a space
|
||||||
|
if (strpos($token, ' ') !== false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// strip "language:"
|
// strip "language:"
|
||||||
$language = substr($language, 9);
|
$language = substr($language, 9);
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,11 @@ $args->parse(
|
||||||
'help' => 'Do not clear all symbols for this project before '.
|
'help' => 'Do not clear all symbols for this project before '.
|
||||||
'uploading new symbols. Useful for incremental updating.',
|
'uploading new symbols. Useful for incremental updating.',
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'ignore-errors',
|
||||||
|
'help' => 'If a line can\'t be parsed, ignore that line and '.
|
||||||
|
'continue instead of exiting.',
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'name' => 'more',
|
'name' => 'more',
|
||||||
'wildcard' => true,
|
'wildcard' => true,
|
||||||
|
@ -66,72 +71,80 @@ $input = explode("\n", $input);
|
||||||
|
|
||||||
$symbols = array();
|
$symbols = array();
|
||||||
foreach ($input as $key => $line) {
|
foreach ($input as $key => $line) {
|
||||||
$line_no = $key + 1;
|
try {
|
||||||
$matches = null;
|
$line_no = $key + 1;
|
||||||
$ok = preg_match(
|
$matches = null;
|
||||||
'/^((?P<context>[^ ]+)? )?(?P<name>[^ ]+) (?P<type>[^ ]+) '.
|
$ok = preg_match(
|
||||||
'(?P<lang>[^ ]+) (?P<line>\d+) (?P<path>.*)$/',
|
'/^((?P<context>[^ ]+)? )?(?P<name>[^ ]+) (?P<type>[^ ]+) '.
|
||||||
$line,
|
'(?P<lang>[^ ]+) (?P<line>\d+) (?P<path>.*)$/',
|
||||||
$matches);
|
$line,
|
||||||
if (!$ok) {
|
$matches);
|
||||||
throw new Exception(
|
if (!$ok) {
|
||||||
"Line #{$line_no} of input is invalid. Expected five or six ".
|
throw new Exception(
|
||||||
"space-delimited fields: maybe symbol context, symbol name, symbol ".
|
"Line #{$line_no} of input is invalid. Expected five or six ".
|
||||||
"type, symbol language, line number, path. ".
|
"space-delimited fields: maybe symbol context, symbol name, symbol ".
|
||||||
"For example:\n\n".
|
"type, symbol language, line number, path. ".
|
||||||
"idx function php 13 /path/to/some/file.php\n\n".
|
"For example:\n\n".
|
||||||
"Actual line was:\n\n".
|
"idx function php 13 /path/to/some/file.php\n\n".
|
||||||
"{$line}");
|
"Actual line was:\n\n".
|
||||||
}
|
"{$line}");
|
||||||
if (empty($matches['context'])) {
|
}
|
||||||
$matches['context'] = '';
|
if (empty($matches['context'])) {
|
||||||
}
|
$matches['context'] = '';
|
||||||
$context = $matches['context'];
|
}
|
||||||
$name = $matches['name'];
|
$context = $matches['context'];
|
||||||
$type = $matches['type'];
|
$name = $matches['name'];
|
||||||
$lang = $matches['lang'];
|
$type = $matches['type'];
|
||||||
$line_number = $matches['line'];
|
$lang = $matches['lang'];
|
||||||
$path = $matches['path'];
|
$line_number = $matches['line'];
|
||||||
|
$path = $matches['path'];
|
||||||
|
|
||||||
if (strlen($context) > 128) {
|
if (strlen($context) > 128) {
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
"Symbol context '{$context}' defined on line #{$line_no} is too long, ".
|
"Symbol context '{$context}' defined on line #{$line_no} is too long, ".
|
||||||
"maximum symbol context length is 128 characters.");
|
"maximum symbol context length is 128 characters.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($name) > 128) {
|
if (strlen($name) > 128) {
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
"Symbol name '{$name}' defined on line #{$line_no} is too long, maximum ".
|
"Symbol name '{$name}' defined on line #{$line_no} is too long, ".
|
||||||
"symbol name length is 128 characters.");
|
"maximum symbol name length is 128 characters.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($type) > 12) {
|
if (strlen($type) > 12) {
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
"Symbol type '{$type}' defined on line #{$line_no} is too long, maximum ".
|
"Symbol type '{$type}' defined on line #{$line_no} is too long, ".
|
||||||
"symbol type length is 12 characters.");
|
"maximum symbol type length is 12 characters.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($lang) > 32) {
|
if (strlen($lang) > 32) {
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
"Symbol language '{$lang}' defined on line #{$line_no} is too long, ".
|
"Symbol language '{$lang}' defined on line #{$line_no} is too long, ".
|
||||||
"maximum symbol language length is 32 characters.");
|
"maximum symbol language length is 32 characters.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strlen($path) || $path[0] != 0) {
|
if (!strlen($path) || $path[0] != 0) {
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
"Path '{$path}' defined on line #{$line_no} is invalid. Paths should be ".
|
"Path '{$path}' defined on line #{$line_no} is invalid. Paths should ".
|
||||||
"begin with '/' and specify a path from the root of the project, like ".
|
"begin with '/' and specify a path from the root of the project, like ".
|
||||||
"'/src/utils/utils.php'.");
|
"'/src/utils/utils.php'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$symbols[] = array(
|
$symbols[] = array(
|
||||||
'ctxt' => $context,
|
'ctxt' => $context,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'lang' => $lang,
|
'lang' => $lang,
|
||||||
'line' => $line_number,
|
'line' => $line_number,
|
||||||
'path' => $path,
|
'path' => $path,
|
||||||
);
|
);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
if ($args->getArg('ignore-errors')) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Looking up path IDs...\n";
|
echo "Looking up path IDs...\n";
|
||||||
|
|
Loading…
Reference in a new issue