|
35 | 35 | 'help' => 'Do not clear all symbols for this project before '.
|
36 | 36 | 'uploading new symbols. Useful for incremental updating.',
|
37 | 37 | ),
|
| 38 | + array( |
| 39 | + 'name' => 'ignore-errors', |
| 40 | + 'help' => 'If a line can\'t be parsed, ignore that line and '. |
| 41 | + 'continue instead of exiting.', |
| 42 | + ), |
38 | 43 | array(
|
39 | 44 | 'name' => 'more',
|
40 | 45 | 'wildcard' => true,
|
|
66 | 71 |
|
67 | 72 | $symbols = array();
|
68 | 73 | foreach ($input as $key => $line) {
|
69 |
| - $line_no = $key + 1; |
70 |
| - $matches = null; |
71 |
| - $ok = preg_match( |
72 |
| - '/^((?P<context>[^ ]+)? )?(?P<name>[^ ]+) (?P<type>[^ ]+) '. |
73 |
| - '(?P<lang>[^ ]+) (?P<line>\d+) (?P<path>.*)$/', |
74 |
| - $line, |
75 |
| - $matches); |
76 |
| - if (!$ok) { |
77 |
| - throw new Exception( |
78 |
| - "Line #{$line_no} of input is invalid. Expected five or six ". |
79 |
| - "space-delimited fields: maybe symbol context, symbol name, symbol ". |
80 |
| - "type, symbol language, line number, path. ". |
81 |
| - "For example:\n\n". |
82 |
| - "idx function php 13 /path/to/some/file.php\n\n". |
83 |
| - "Actual line was:\n\n". |
84 |
| - "{$line}"); |
85 |
| - } |
86 |
| - if (empty($matches['context'])) { |
87 |
| - $matches['context'] = ''; |
88 |
| - } |
89 |
| - $context = $matches['context']; |
90 |
| - $name = $matches['name']; |
91 |
| - $type = $matches['type']; |
92 |
| - $lang = $matches['lang']; |
93 |
| - $line_number = $matches['line']; |
94 |
| - $path = $matches['path']; |
95 |
| - |
96 |
| - if (strlen($context) > 128) { |
97 |
| - throw new Exception( |
98 |
| - "Symbol context '{$context}' defined on line #{$line_no} is too long, ". |
99 |
| - "maximum symbol context length is 128 characters."); |
100 |
| - } |
101 |
| - |
102 |
| - if (strlen($name) > 128) { |
103 |
| - throw new Exception( |
104 |
| - "Symbol name '{$name}' defined on line #{$line_no} is too long, maximum ". |
105 |
| - "symbol name length is 128 characters."); |
106 |
| - } |
107 |
| - |
108 |
| - if (strlen($type) > 12) { |
109 |
| - throw new Exception( |
110 |
| - "Symbol type '{$type}' defined on line #{$line_no} is too long, maximum ". |
111 |
| - "symbol type length is 12 characters."); |
112 |
| - } |
113 |
| - |
114 |
| - if (strlen($lang) > 32) { |
115 |
| - throw new Exception( |
116 |
| - "Symbol language '{$lang}' defined on line #{$line_no} is too long, ". |
117 |
| - "maximum symbol language length is 32 characters."); |
| 74 | + try { |
| 75 | + $line_no = $key + 1; |
| 76 | + $matches = null; |
| 77 | + $ok = preg_match( |
| 78 | + '/^((?P<context>[^ ]+)? )?(?P<name>[^ ]+) (?P<type>[^ ]+) '. |
| 79 | + '(?P<lang>[^ ]+) (?P<line>\d+) (?P<path>.*)$/', |
| 80 | + $line, |
| 81 | + $matches); |
| 82 | + if (!$ok) { |
| 83 | + throw new Exception( |
| 84 | + "Line #{$line_no} of input is invalid. Expected five or six ". |
| 85 | + "space-delimited fields: maybe symbol context, symbol name, symbol ". |
| 86 | + "type, symbol language, line number, path. ". |
| 87 | + "For example:\n\n". |
| 88 | + "idx function php 13 /path/to/some/file.php\n\n". |
| 89 | + "Actual line was:\n\n". |
| 90 | + "{$line}"); |
| 91 | + } |
| 92 | + if (empty($matches['context'])) { |
| 93 | + $matches['context'] = ''; |
| 94 | + } |
| 95 | + $context = $matches['context']; |
| 96 | + $name = $matches['name']; |
| 97 | + $type = $matches['type']; |
| 98 | + $lang = $matches['lang']; |
| 99 | + $line_number = $matches['line']; |
| 100 | + $path = $matches['path']; |
| 101 | + |
| 102 | + if (strlen($context) > 128) { |
| 103 | + throw new Exception( |
| 104 | + "Symbol context '{$context}' defined on line #{$line_no} is too long, ". |
| 105 | + "maximum symbol context length is 128 characters."); |
| 106 | + } |
| 107 | + |
| 108 | + if (strlen($name) > 128) { |
| 109 | + throw new Exception( |
| 110 | + "Symbol name '{$name}' defined on line #{$line_no} is too long, ". |
| 111 | + "maximum symbol name length is 128 characters."); |
| 112 | + } |
| 113 | + |
| 114 | + if (strlen($type) > 12) { |
| 115 | + throw new Exception( |
| 116 | + "Symbol type '{$type}' defined on line #{$line_no} is too long, ". |
| 117 | + "maximum symbol type length is 12 characters."); |
| 118 | + } |
| 119 | + |
| 120 | + if (strlen($lang) > 32) { |
| 121 | + throw new Exception( |
| 122 | + "Symbol language '{$lang}' defined on line #{$line_no} is too long, ". |
| 123 | + "maximum symbol language length is 32 characters."); |
| 124 | + } |
| 125 | + |
| 126 | + if (!strlen($path) || $path[0] != 0) { |
| 127 | + throw new Exception( |
| 128 | + "Path '{$path}' defined on line #{$line_no} is invalid. Paths should ". |
| 129 | + "begin with '/' and specify a path from the root of the project, like ". |
| 130 | + "'/src/utils/utils.php'."); |
| 131 | + } |
| 132 | + |
| 133 | + $symbols[] = array( |
| 134 | + 'ctxt' => $context, |
| 135 | + 'name' => $name, |
| 136 | + 'type' => $type, |
| 137 | + 'lang' => $lang, |
| 138 | + 'line' => $line_number, |
| 139 | + 'path' => $path, |
| 140 | + ); |
| 141 | + } catch (Exception $e) { |
| 142 | + if ($args->getArg('ignore-errors')) { |
| 143 | + continue; |
| 144 | + } else { |
| 145 | + throw $e; |
| 146 | + } |
118 | 147 | }
|
119 |
| - |
120 |
| - if (!strlen($path) || $path[0] != 0) { |
121 |
| - throw new Exception( |
122 |
| - "Path '{$path}' defined on line #{$line_no} is invalid. Paths should be ". |
123 |
| - "begin with '/' and specify a path from the root of the project, like ". |
124 |
| - "'/src/utils/utils.php'."); |
125 |
| - } |
126 |
| - |
127 |
| - $symbols[] = array( |
128 |
| - 'ctxt' => $context, |
129 |
| - 'name' => $name, |
130 |
| - 'type' => $type, |
131 |
| - 'lang' => $lang, |
132 |
| - 'line' => $line_number, |
133 |
| - 'path' => $path, |
134 |
| - ); |
135 | 148 | }
|
136 | 149 |
|
137 | 150 | echo "Looking up path IDs...\n";
|
|
0 commit comments