MCPcopy Create free account
hub / github.com/ashawkey/camera_viewer / parse

Method parse

js/poseParser.js:166–218  ·  view source on GitHub ↗

* Parse a Python-like list string into a JavaScript array * Supports nested arrays, numbers (including scientific notation), and basic Python syntax * @param {string} input - The Python-like list string * @param {string} format - The input format ('matrix', 'xyz_quat_wxyz', 'xyz_quat_

(input, format = 'matrix')

Source from the content-addressed store, hash-verified

164 * @returns {Object} - { success: boolean, data: array|null, error: string|null, count: number }
165 */
166 static parse(input, format = 'matrix') {
167 try {
168 // Preprocess the input
169 let processed = this.preprocess(input);
170
171 // Try to parse as JSON first (fastest method)
172 try {
173 const data = JSON.parse(processed);
174 const validation = this.validateAndConvert(data, format);
175 if (validation.valid) {
176 return {
177 success: true,
178 data: validation.data,
179 error: null,
180 count: validation.data.length
181 };
182 } else {
183 return {
184 success: false,
185 data: null,
186 error: validation.error,
187 count: 0
188 };
189 }
190 } catch (jsonError) {
191 // If JSON parsing fails, try a more lenient approach
192 const data = this.parsePythonList(processed);
193 const validation = this.validateAndConvert(data, format);
194 if (validation.valid) {
195 return {
196 success: true,
197 data: validation.data,
198 error: null,
199 count: validation.data.length
200 };
201 } else {
202 return {
203 success: false,
204 data: null,
205 error: validation.error,
206 count: 0
207 };
208 }
209 }
210 } catch (error) {
211 return {
212 success: false,
213 data: null,
214 error: `Parse error: ${error.message}`,
215 count: 0
216 };
217 }
218 }
219
220 /**
221 * Preprocess input string to make it more JSON-compatible

Callers 1

parseMultipleMethod · 0.95

Calls 3

preprocessMethod · 0.95
validateAndConvertMethod · 0.95
parsePythonListMethod · 0.95

Tested by

no test coverage detected