@@ -146,6 +146,56 @@ public static Parser CreateParser(Stream stream, PythonLanguageVersion version,
146146 //file_input: (Newline | stmt)* ENDMARKER
147147 public PythonAst ParseFile ( Uri module = null ) => ParseFileWorker ( module ) ;
148148
149+ //[stmt_list] Newline | compound_stmt Newline
150+ //stmt_list ::= simple_stmt (";" simple_stmt)* [";"]
151+ //compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef
152+ //Returns a simple or coumpound_stmt or null if input is incomplete
153+ /// <summary>
154+ /// Parse one or more lines of interactive input
155+ /// </summary>
156+ /// <returns>null if input is not yet valid but could be with more lines</returns>
157+ public PythonAst ParseInteractiveCode ( Uri module , out ParseResult properties ) {
158+ bool parsingMultiLineCmpdStmt ;
159+
160+ properties = ParseResult . Complete ;
161+
162+ StartParsing ( ) ;
163+ Statement ret = InternalParseInteractiveInput ( out parsingMultiLineCmpdStmt , out bool isEmptyStmt ) ;
164+
165+ if ( ErrorCode == 0 ) {
166+ if ( isEmptyStmt ) {
167+ properties = ParseResult . Empty ;
168+ } else if ( parsingMultiLineCmpdStmt ) {
169+ properties = ParseResult . IncompleteStatement ;
170+ }
171+
172+ if ( isEmptyStmt ) {
173+ return null ;
174+ }
175+
176+ return CreateAst ( module , ret ) ;
177+ } else {
178+ if ( ( ErrorCode & ErrorCodes . IncompleteMask ) != 0 ) {
179+ if ( ( ErrorCode & ErrorCodes . IncompleteToken ) != 0 ) {
180+ properties = ParseResult . IncompleteToken ;
181+ return null ;
182+ }
183+
184+ if ( ( ErrorCode & ErrorCodes . IncompleteStatement ) != 0 ) {
185+ if ( parsingMultiLineCmpdStmt ) {
186+ properties = ParseResult . IncompleteStatement ;
187+ } else {
188+ properties = ParseResult . IncompleteToken ;
189+ }
190+ return null ;
191+ }
192+ }
193+
194+ properties = ParseResult . Invalid ;
195+ return null ;
196+ }
197+ }
198+
149199 public Expression ParseFStrSubExpr ( ) {
150200 _alwaysAllowContextDependentSyntax = true ;
151201 StartParsing ( ) ;
0 commit comments