//System.err.println(new PyString(string).__repr__().toString());
char[] bufreader = prepBufreader(PyString.to_bytes(string), cflags);
ReaderCharStream charStream = new ReaderCharStream(bufreader);
PythonGrammar g = new PythonGrammar(charStream, literalMkrForParser);
g.token_source.partial = true;
g.token_source.stdprompt = stdprompt;
try {
node = doparse(kind, cflags, g);
} catch (Throwable t) {
/*
CPython codeop exploits that with CPython parser adding newlines
to a partial valid sentence move the reported error position,
this is not true for our parser, so we need a different approach:
we check whether all sentence tokens have been consumed or
the remaining ones fullfill lookahead expectations. See:
PythonGrammar.partial_valid_sentence (def in python.jjt)
*/
if (g.partial_valid_sentence(t)) {
return null;
}
throw fixParseError(charStream, t, filename);
}
return node;