@@ -175,15 +175,12 @@ private static Object parsePythonLiteral(String s) {
175175 s = s .trim ();
176176 if (s .isEmpty ()) return null ;
177177
178- // dict: {'key': value, ...}
179178 if (s .startsWith ("{" ) && s .endsWith ("}" )) {
180179 return parseDict (s .substring (1 , s .length () - 1 ));
181180 }
182- // list: [val1, val2, ...]
183181 if (s .startsWith ("[" ) && s .endsWith ("]" )) {
184182 return parseList (s .substring (1 , s .length () - 1 ));
185183 }
186- // single value
187184 return parseValue (s );
188185 }
189186
@@ -193,35 +190,29 @@ private static Map<String, Object> parseDict(String inner) {
193190
194191 int i = 0 ;
195192 while (i < inner .length ()) {
196- // skip whitespace
197193 while (i < inner .length () && Character .isWhitespace (inner .charAt (i ))) i ++;
198194 if (i >= inner .length ()) break ;
199195
200- // parse key (quoted string)
201196 char quote = inner .charAt (i );
202197 if (quote != '\'' && quote != '"' ) break ;
203198 i ++;
204199 int keyStart = i ;
205200 while (i < inner .length () && inner .charAt (i ) != quote ) i ++;
206201 String key = inner .substring (keyStart , i );
207- i ++; // skip closing quote
202+ i ++;
208203
209- // skip to colon
210204 while (i < inner .length () && inner .charAt (i ) != ':' ) i ++;
211- i ++; // skip colon
205+ i ++;
212206
213- // skip whitespace
214207 while (i < inner .length () && Character .isWhitespace (inner .charAt (i ))) i ++;
215208
216- // parse value
217209 int [] endIdx = new int []{i };
218210 Object val = parseValueAt (inner , endIdx );
219211 i = endIdx [0 ];
220212 map .put (key , val );
221213
222- // skip to comma or end
223214 while (i < inner .length () && inner .charAt (i ) != ',' ) i ++;
224- i ++; // skip comma
215+ i ++;
225216 }
226217 return map ;
227218 }
@@ -254,7 +245,6 @@ private static Object parseValueAt(String s, int[] idx) {
254245 }
255246
256247 char c = s .charAt (i );
257- // nested dict
258248 if (c == '{' ) {
259249 int depth = 1 , start = i ;
260250 i ++;
@@ -266,7 +256,6 @@ private static Object parseValueAt(String s, int[] idx) {
266256 idx [0 ] = i ;
267257 return parsePythonLiteral (s .substring (start , i ));
268258 }
269- // nested list
270259 if (c == '[' ) {
271260 int depth = 1 , start = i ;
272261 i ++;
@@ -278,18 +267,16 @@ private static Object parseValueAt(String s, int[] idx) {
278267 idx [0 ] = i ;
279268 return parsePythonLiteral (s .substring (start , i ));
280269 }
281- // quoted string
282270 if (c == '\'' || c == '"' ) {
283271 char quote = c ;
284272 i ++;
285273 int start = i ;
286274 while (i < s .length () && s .charAt (i ) != quote ) i ++;
287275 String val = s .substring (start , i );
288- i ++; // skip closing quote
276+ i ++;
289277 idx [0 ] = i ;
290278 return val ;
291279 }
292- // number or other
293280 int start = i ;
294281 while (i < s .length () && s .charAt (i ) != ',' && s .charAt (i ) != '}' && s .charAt (i ) != ']' && !Character .isWhitespace (s .charAt (i ))) {
295282 i ++;
0 commit comments