CSharpParser ParseString(ParseMode mode, string input, out bool partial_input)
{
partial_input = false;
Reset ();
Tokenizer.LocatedToken.Initialize ();
Stream s = new MemoryStream (Encoding.UTF8.GetBytes (input));
SeekableStreamReader seekable = new SeekableStreamReader (s, Encoding.UTF8);
InputKind kind = ToplevelOrStatement (seekable);
if (kind == InputKind.Error){
if (mode == ParseMode.ReportErrors)
ctx.Report.Error (-25, "Detection Parsing Error");
partial_input = false;
return null;
}
if (kind == InputKind.EOF){
if (mode == ParseMode.ReportErrors)
Console.Error.WriteLine ("Internal error: EOF condition should have been detected in a previous call with silent=true");
partial_input = true;
return null;
}
seekable.Position = 0;
if (ns == null)
ns = new NamespaceEntry (module, null, Location.SourceFiles[0], null);
ns.DeclarationFound = false;
CSharpParser parser = new CSharpParser (seekable, Location.SourceFiles [0], module, ns);
if (kind == InputKind.StatementOrExpression){
parser.Lexer.putback_char = Tokenizer.EvalStatementParserCharacter;
ctx.Settings.StatementMode = true;
} else {
parser.Lexer.putback_char = Tokenizer.EvalCompilationUnitParserCharacter;
ctx.Settings.StatementMode = false;
}
if (mode == ParseMode.GetCompletions)
parser.Lexer.CompleteOnEOF = true;
ReportPrinter old_printer = null;
if ((mode == ParseMode.Silent || mode == ParseMode.GetCompletions) && CSharpParser.yacc_verbose_flag == 0)
old_printer = ctx.Report.SetPrinter (new StreamReportPrinter (TextWriter.Null));
try {
parser.parse ();
} finally {
if (ctx.Report.Errors != 0){
if (mode != ParseMode.ReportErrors && parser.UnexpectedEOF)
partial_input = true;
if (parser.undo != null)
parser.undo.ExecuteUndo ();
parser = null;
}
if (old_printer != null)
ctx.Report.SetPrinter (old_printer);
}
return parser;
}