/** * Parse from a string with the Python literal expression */ public Ast parse(String expression) { Ast ast=new Ast(); if(expression==null || expression.length()==0) return ast; SeekableStringReader sr = new SeekableStringReader(expression); if(sr.peek()=='#') sr.readUntil('\n'); // skip comment line try { ast.root = parseExpr(sr); sr.skipWhitespace(); if(sr.hasMore()) throw new ParseException("garbage at end of expression"); return ast; } catch (ParseException x) { String faultLocation = extractFaultLocation(sr); throw new ParseException(x.getMessage() + " (at position "+sr.bookmark()+"; '"+faultLocation+"')", x); } }